def uninstall(aws_profile, aws_region, aws_permissions_check, nr_account_id,
              force):
    """Uninstall New Relic AWS Lambda Integration"""
    session = boto3.Session(profile_name=aws_profile, region_name=aws_region)

    if aws_permissions_check:
        permissions.ensure_integration_uninstall_permissions(session)

    uninstall_integration = True

    if not force and nr_account_id:
        uninstall_integration = click.confirm(
            "This will uninstall the New Relic AWS Lambda integration role. "
            "Are you sure you want to proceed?")

    if uninstall_integration and nr_account_id:
        integrations.remove_integration_role(session, nr_account_id)

    if not force:
        click.confirm(
            "This will uninstall the New Relic AWS Lambda log ingestion function and "
            "role. Are you sure you want to proceed?",
            abort=True,
            default=False,
        )

    integrations.remove_log_ingestion_function(session)

    done("Uninstall Complete")
Exemple #2
0
def test_check_for_ingest_stack(aws_credentials):
    """
    Asserts that check_for_ingestion_stack returns the ingestion stack if present;
    None if not.
    """
    session = boto3.Session(region_name="us-east-1")
    assert check_for_ingest_stack(session) is None

    create_log_ingestion_function(session, "mock-nr-license-key")
    assert check_for_ingest_stack(session) == "CREATE_COMPLETE"

    remove_log_ingestion_function(session)
    assert check_for_ingest_stack(session) is None
def test_remove_log_ingestion_function(success_mock):
    session = MagicMock()

    remove_log_ingestion_function(session)

    session.assert_has_calls(
        [
            call.client("cloudformation"),
            call.client().describe_stacks(StackName="NewRelicLogIngestion"),
            call.client().delete_stack(StackName="NewRelicLogIngestion"),
        ],
        any_order=True,
    )
    success_mock.assert_called_once()
Exemple #4
0
def uninstall(**kwargs):
    """Uninstall New Relic AWS Lambda Integration"""
    input = IntegrationUninstall(session=None, **kwargs)

    input = input._replace(
        session=boto3.Session(
            profile_name=input.aws_profile, region_name=input.aws_region
        )
    )

    if input.aws_permissions_check:
        permissions.ensure_integration_uninstall_permissions(input)

    uninstall_integration = True

    if not input.force and input.nr_account_id:
        uninstall_integration = click.confirm(
            "This will uninstall the New Relic AWS Lambda integration role. "
            "Are you sure you want to proceed?"
        )

    if uninstall_integration and input.nr_account_id:
        integrations.remove_integration_role(input)

    if not input.force:
        click.confirm(
            "This will uninstall the New Relic AWS Lambda log ingestion function and "
            "role. Are you sure you want to proceed?",
            abort=True,
            default=False,
        )

    integrations.remove_log_ingestion_function(input)

    if not input.force:
        click.confirm(
            "This will uninstall the New Relic License Key managed secret, and IAM "
            "Policy. "
            "Are you sure you want to proceed?",
            abort=True,
            default=False,
        )
    integrations.remove_license_key(input)

    done("Uninstall Complete")
Exemple #5
0
def test_remove_log_ingestion_function_not_present(success_mock):
    describe_stack_mock = {
        "client.return_value.describe_stacks.side_effect": botocore.exceptions.ClientError(
            {"ResponseMetadata": {"HTTPStatusCode": 404}}, "test"
        )
    }
    session = MagicMock(**describe_stack_mock)

    remove_log_ingestion_function(integration_uninstall(session=session))

    session.assert_has_calls(
        [
            call.client("cloudformation"),
            call.client().describe_stacks(StackName="NewRelicLogIngestion"),
        ],
        any_order=True,
    )
    success_mock.assert_not_called()