コード例 #1
0
ファイル: iam.py プロジェクト: rofrnnds/scar
 def get_user_name_or_id(self):
     try:
         user = self.client.get_user_info()
         return user.get('UserName', user['User']['UserId'])
     except ClientError as ce:
         # If the user doesn't have access rights to IAMClient
         # we can find the user name in the error response
         return utils.find_expression('(?<=user\/)(\S+)', str(ce))     
コード例 #2
0
def parse_error_invocation_response(response, function_name):
    if "Task timed out" in response['Payload']:
        # Find the timeout time
        message = utils.find_expression(str(response['Payload']),
                                        '(Task timed out .* seconds)')
        # Modify the error message to ease the error readability
        error_msg = message.replace("Task", "Function '%s'" % function_name)
        error_log = "Error in function response: %s" % error_msg
    else:
        error_msg = "Error in function response."
        error_log = "Error in function response: %s" % response['Payload']
    logger.error(error_msg, error_log)
コード例 #3
0
 def get_user_info(self):
     '''
     Retrieves information about the specified IAM user, including the user's creation date, path, unique ID, and ARN.
     https://boto3.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.get_user
     '''
     try:
         return self.client.get_user()
     except ClientError as ce:
         if ce.response['Error']['Code'] == 'AccessDenied':
             # If the user doesn't have access rights to IAMClient
             # we can find the user name in the error response
             user_name = utils.find_expression(str(ce), '(?<=user\/)(\S+)')
             return {
                 'UserName': user_name,
                 'User': {
                     'UserName': user_name,
                     'UserId': ''
                 }
             }
コード例 #4
0
ファイル: controller.py プロジェクト: adolfo24/scar
 def add_account_id(self):
     self.properties['account_id'] = utils.find_expression(
         self.properties['iam']['role'], '\d{12}')
コード例 #5
0
ファイル: apigateway.py プロジェクト: rofrnnds/scar
 def get_api_lambda_uri(self):
     self.aws_acc_id = utils.find_expression('\d{12}', self.lambda_role)
     api_gateway_uri = 'arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/'
     lambda_uri = 'arn:aws:lambda:us-east-1:{0}:function:{1}/invocations'.format(
         self.aws_acc_id, self.function_name)
     return api_gateway_uri + lambda_uri
コード例 #6
0
 def validate_function_name(function_name):
     if not utils.find_expression(function_name, valid_lambda_name_regex):
         error_msg = 'Find name restrictions in: https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html#SSS-CreateFunction-request-FunctionName'
         raise ValidatorError(parameter='function_name',
                              parameter_value=function_name,
                              error_msg=error_msg)
コード例 #7
0
ファイル: validators.py プロジェクト: iMerica/scar
def validate_function_name(function_name, name_regex):
    if not utils.find_expression(function_name, name_regex):
        raise Exception(
            "'{0}' is an invalid lambda function name.".format(function_name))