def test_ensure_subscription_uninstall_permissions(): mock_session = MagicMock() mock_session.client.return_value.simulate_principal_policy.return_value = { "EvaluationResults": [ {"EvalActionName": "foo:bar", "EvalDecision": "allowed"}, {"EvalActionName": "bar:baz", "EvalDecision": "denied"}, ] } with raises(UsageError): ensure_subscription_uninstall_permissions( subscription_uninstall(session=mock_session) ) mock_session.assert_has_calls([call.client("iam"), call.client("sts")]) mock_session.assert_has_calls( [ call.client().simulate_principal_policy( PolicySourceArn=ANY, ActionNames=ANY, ResourceArns=["*"], ContextEntries=[{}], ), ], )
def uninstall(**kwargs): """Uninstall New Relic AWS Lambda Log Subscriptions""" input = SubscriptionUninstall(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_subscription_uninstall_permissions(input) functions = get_aliased_functions(input) with ThreadPoolExecutor() as executor: futures = [ executor.submit(subscriptions.remove_log_subscription, input, function) for function in functions ] uninstall_success = all(future.result() for future in as_completed(futures)) if uninstall_success: done("Uninstall Complete") else: failure("Uninstall Incomplete. See messages above for details.", exit=True)
def uninstall(aws_profile, aws_region, aws_permissions_check, function): """Uninstall New Relic AWS Lambda Log Subscription""" session = boto3.Session(profile_name=aws_profile, region_name=aws_region) if aws_permissions_check: permissions.ensure_subscription_uninstall_permissions(session) subscriptions.remove_log_subscription(session, function) done("Uninstall Complete")
def uninstall(aws_profile, aws_region, aws_permissions_check, functions, excludes): """Uninstall New Relic AWS Lambda Log Subscriptions""" session = boto3.Session(profile_name=aws_profile, region_name=aws_region) if aws_permissions_check: permissions.ensure_subscription_uninstall_permissions(session) functions = get_aliased_functions(session, functions, excludes) uninstall_success = True for function in functions: result = subscriptions.remove_log_subscription(session, function) uninstall_success = result and uninstall_success if result: success("Successfully uninstalled log subscription on %s" % function) if uninstall_success: done("Uninstall Complete") else: failure("Uninstall Incomplete. See messages above for details.", exit=True)
def uninstall(aws_profile, aws_region, aws_permissions_check, functions, excludes): """Uninstall New Relic AWS Lambda Log Subscriptions""" session = boto3.Session(profile_name=aws_profile, region_name=aws_region) if aws_permissions_check: permissions.ensure_subscription_uninstall_permissions(session) functions = get_aliased_functions(session, functions, excludes) with ThreadPoolExecutor() as executor: futures = [ executor.submit(subscriptions.remove_log_subscription, session, function) for function in functions ] uninstall_success = all(future.result() for future in as_completed(futures)) if uninstall_success: done("Uninstall Complete") else: failure("Uninstall Incomplete. See messages above for details.", exit=True)