Esempio n. 1
0
    def security_group_create(self,
                              security_group_name,
                              description,
                              vpc_id=None,
                              tags=None):
        if self.security_group_exists(security_group_name=security_group_name):
            security_group_id = self.security_group(
                security_group_name=security_group_name
            ).get(
                'GroupId'
            )  # todo see what is a better way to implement this workflow, since at the moment there are two full calls to the self.security_groups() method
            return status_warning(
                message=
                f'Security group already existed: {security_group_name}',
                data={'security_group_id': security_group_id})
        kwargs = {
            'Description':
            description,
            'GroupName':
            security_group_name,
            'TagSpecifications':
            self.tag_specifications_create(tags=tags,
                                           resource_type='security-group')
        }
        if vpc_id:
            kwargs['VpcId'] = vpc_id

        security_group_id = self.client().create_security_group(
            **kwargs).get('GroupId')
        return status_ok(
            message=f'Security group created ok: {security_group_name}',
            data={'security_group_id': security_group_id})
Esempio n. 2
0
 def log_stream_delete(self, log_group_name, log_stream_name):
     if self.log_stream_exists(log_group_name, log_stream_name) is False:
         return status_warning(
             f'log stream did not exist: {log_group_name}')
     self.client().delete_log_stream(logGroupName=log_group_name,
                                     logStreamName=log_stream_name)
     return status_ok(message=f"log stream deleted ok: {log_stream_name}")
Esempio n. 3
0
 def log_group_create(self, log_group_name, tags=None):
     if self.log_group_exists(log_group_name):
         return status_warning(
             f'log group already existed: {log_group_name}')
     kwargs = {'logGroupName': log_group_name}
     if tags:
         kwargs['tags'] = tags
     self.client().create_log_group(**kwargs)
     return status_ok(message=f"log group created ok: {log_group_name}")
Esempio n. 4
0
 def check_current_session_credentials(
     self,
     raise_exception=True
 ):  # todo: see if there is a faster way to do this, at the moment it takes about 500ms which is quite a lot
     if AWS_Config().dev_skip_aws_key_check() == "True":
         return status_warning(message="check was skipped")
     result = self.check_aws_session()
     if result.get('status') == 'error':
         self.print_bad_credentials_exception(result.get('message'))
         #if exit_on_error:                                                  # todo: see better way to do this
         #    self.end_process_bad_credentials_exception()
         if raise_exception:
             self.raise_bad_credentials_exception(result.get('message'))
     return result
Esempio n. 5
0
 def log_stream_create(self, log_group_name, log_stream_name):
     if self.log_group_not_exists(
             log_group_name=log_group_name
     ):  # if the log group doesn't exist, create it
         self.log_group_create(log_group_name).get('status')
     try:
         self.client().create_log_stream(logGroupName=log_group_name,
                                         logStreamName=log_stream_name)
         return status_ok(
             message=f"log stream created ok: {log_stream_name}")
     except ClientError as exception:
         if exception.response['Error'][
                 'Code'] == 'ResourceAlreadyExistsException':
             return status_warning(
                 message=f"log stream already existed: {log_stream_name}")
         return status_error(message=f'exception', error=exception)
Esempio n. 6
0
    def validate_create_kwargs(self, kwargs):
        name = kwargs.get('FunctionName')
        code = kwargs.get('Code', {})
        image_uri = code.get('ImageUri')
        s3_bucket = code.get('S3Bucket')
        s3_key = code.get('S3Key')

        if len(name) > 64:
            return status_error(
                message="lambda functions name cannot be bigger than 64 chars",
                data=self.name)
        if Lambda(name=name).exists():
            return status_warning(
                message=f'lambda function already exists: {name}')

        if image_uri is None:
            if self.s3().file_not_exists(s3_bucket, s3_key):
                return status_error(
                    message=
                    f'for function {name}, could not find provided s3 bucket and s3 key: {s3_bucket} {s3_key}'
                )
        return status_ok()
Esempio n. 7
0
 def delete(self):
     if self.exists():
         result = self.cluster.api_core().delete_namespace(name=self.name)
         return status_ok(message="namespace deleted", data=result)
     return status_warning(message="namespace already existed")