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")
def test_remove_integration_role(aws_credentials):
    mock_session = MagicMock()

    assert (remove_integration_role(
        integration_uninstall(nr_account_id=123456789, session=mock_session))
            is None)

    mock_client = mock_session.client.return_value
    mock_client.describe_stacks.return_value = {
        "Stacks": [{
            "StackStatus": "peachy"
        }]
    }

    assert (remove_integration_role(
        integration_uninstall(nr_account_id=123456789, session=mock_session))
            is None)

    mock_client.assert_has_calls([
        call.describe_stacks(
            StackName="NewRelicLambdaIntegrationRole-123456789")
    ])
    mock_client.assert_has_calls([
        call.delete_stack(StackName="NewRelicLambdaIntegrationRole-123456789")
    ])
Example #3
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")