Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion newrelic_lambda_cli/cli/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
envvar="NEW_RELIC_API_KEY",
help="New Relic User API Key",
metavar="<key>",
required=True,
required=False,
),
click.option(
"--nr-region",
Expand Down
65 changes: 55 additions & 10 deletions newrelic_lambda_cli/cli/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def register(group):
required=False,
)
@add_options(NR_OPTIONS)
@click.option(
"--nr-ingest-key",
help="New Relic Ingest Key",
metavar="<key>",
required=False,
)
@click.option(
"--timeout",
"-t",
Expand Down Expand Up @@ -113,6 +119,12 @@ def install(ctx, **kwargs):
"""Install New Relic AWS Lambda Integration"""
input = IntegrationInstall(session=None, verbose=ctx.obj["VERBOSE"], **kwargs)

if input.nr_api_key and input.nr_ingest_key:
raise click.UsageError(
"Please provide either the --nr-api-key or the --nr-ingest-key flag, but not both."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sashwatdas123 It's not clear to me why this is invalid. I need to pass API key to set up account linking, but then it will choose an arbitrary license key. So passing both is perfectly valid.

To that end, maybe instead of this, it should allow specifying the ingest key name, and then the api key is used to find it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rittneje , Thank you for sharing this. We are looking into this and will update the PR.
Thank you.

)
if not input.nr_api_key and not input.nr_ingest_key:
raise click.UsageError("Please provide either --nr-api-key or --nr-ingest-key.")
input = input._replace(
session=boto3.Session(
profile_name=input.aws_profile, region_name=input.aws_region
Expand All @@ -130,30 +142,47 @@ def install(ctx, **kwargs):
if input.aws_permissions_check:
permissions.ensure_integration_install_permissions(input)

click.echo("Validating New Relic credentials")
gql_client = api.validate_gql_credentials(input)
nr_license_key = None
gql_client = None

click.echo("Retrieving integration license key")
nr_license_key = api.retrieve_license_key(gql_client)
if input.nr_ingest_key:
click.echo("Using provided New Relic ingest key")
nr_license_key = input.nr_ingest_key
if input.nr_api_key:
click.echo("Validating New Relic credentials for account linking")
gql_client = api.validate_gql_credentials(input)
else:
click.echo(
"Note: Skipping cloud integration account linking "
"(requires --nr-api-key). Only AWS resources will be created."
)
else:
click.echo("Validating New Relic credentials")
gql_client = api.validate_gql_credentials(input)

click.echo("Retrieving integration license key")
nr_license_key = api.retrieve_license_key(gql_client)

install_success = True

click.echo("Creating the AWS role for the New Relic AWS Lambda Integration")
role = integrations.create_integration_role(input)
install_success = install_success and role

if role:
if role and gql_client:
click.echo("Linking New Relic account to AWS account")
res = api.create_integration_account(gql_client, input, role)
install_success = res and install_success

linked_account_id = res.get("id")
linked_account_id = res.get("id") if res else None
if linked_account_id:
click.echo(
"Enabling Lambda integration on the link between New Relic and AWS"
)
res = api.enable_lambda_integration(gql_client, input, linked_account_id)
install_success = res and install_success
elif role and not gql_client:
click.echo("Skipping cloud integration (no API key provided)")

if input.enable_license_key_secret:
click.echo("Creating the managed secret for the New Relic License Key")
Expand Down Expand Up @@ -282,6 +311,12 @@ def uninstall(**kwargs):
type=click.INT,
)
@add_options(NR_OPTIONS)
@click.option(
"--nr-ingest-key",
help="New Relic Ingest Key",
metavar="<key>",
required=False,
)
@click.option(
"--timeout",
"-t",
Expand Down Expand Up @@ -323,6 +358,12 @@ def update(**kwargs):
"""UpdateNew Relic AWS Lambda Integration"""
input = IntegrationUpdate(session=None, **kwargs)

if input.nr_api_key and input.nr_ingest_key:
raise click.UsageError(
"Please provide either the --nr-api-key or the --nr-ingest-key flag, but not both."
)
if not input.nr_api_key and not input.nr_ingest_key:
raise click.UsageError("Please provide either --nr-api-key or --nr-ingest-key.")
input = input._replace(
session=boto3.Session(
profile_name=input.aws_profile, region_name=input.aws_region
Expand All @@ -332,11 +373,15 @@ def update(**kwargs):
if input.aws_permissions_check:
permissions.ensure_integration_install_permissions(input)

click.echo("Validating New Relic credentials")
gql_client = api.validate_gql_credentials(input)
if input.nr_ingest_key:
click.echo("Using provided New Relic ingest key")
nr_license_key = input.nr_ingest_key
else:
click.echo("Validating New Relic credentials")
gql_client = api.validate_gql_credentials(input)

click.echo("Retrieving integration license key")
nr_license_key = api.retrieve_license_key(gql_client)
click.echo("Retrieving integration license key")
nr_license_key = api.retrieve_license_key(gql_client)

update_success = True

Expand Down
2 changes: 2 additions & 0 deletions newrelic_lambda_cli/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"linked_account_name",
"nr_account_id",
"nr_api_key",
"nr_ingest_key",
"nr_region",
"timeout",
"role_name",
Expand Down Expand Up @@ -42,6 +43,7 @@
"memory_size",
"nr_account_id",
"nr_api_key",
"nr_ingest_key",
"nr_region",
"timeout",
"role_name",
Expand Down
Loading