sera/providers/aws.py
def create_provider_keys(
            cls,
            username=USERNAME,
            group=GROUP,
            policy_name=POLICY_NAME,
            policy=WATCHER_POLICY):
        """Create a provider user with permissions for the watcher to connect"""

        iam = boto3.client(
            'iam',
            region_name=os.getenv('SERA_REGION'),
            aws_access_key_id=os.getenv('SERA_ACCESS_KEY'),
            aws_secret_access_key=os.getenv('SERA_SECRET_KEY'))
        try:
            iam.create_user(UserName=username)
            keys = iam.create_access_key(UserName=username)
            access_key = keys.get('AccessKey', {}).get('AccessKeyId')
            secret_key = keys.get('AccessKey', {}).get('SecretAccessKey')
        except ClientError as e:
            access_key = secret_key = None
            code = e.response.get('Error', {}).get('Code', '')
            if code != 'EntityAlreadyExists':
                raise
        try:
            iam.create_group(GroupName=group)
        except ClientError as e:
            code = e.response.get('Error', {}).get('Code', '')
            if code != 'EntityAlreadyExists':
                raise
        try:
            iam.add_user_to_group(GroupName=group, UserName=username)
        except ClientError as e:
            code = e.response.get('Error', {}).get('Code', '')
            if code != 'EntityAlreadyExists':
                raise

        iam.put_group_policy(
            GroupName=group,
            PolicyName=policy_name,
            PolicyDocument=WATCHER_POLICY)
        return access_key, secret_key
Create a provider user with permissions for the watcher to connect
Create a provider user with permissions for the watcher to connect
Create a provider user with permissions for the watcher to connect
def create_provider_keys(
            cls,
            username=USERNAME,
            group=GROUP,
            policy_name=POLICY_NAME,
            policy=WATCHER_POLICY):
        iam = boto3.client(
            'iam',
            region_name=os.getenv('SERA_REGION'),
            aws_access_key_id=os.getenv('SERA_ACCESS_KEY'),
            aws_secret_access_key=os.getenv('SERA_SECRET_KEY'))
        try:
            iam.create_user(UserName=username)
            keys = iam.create_access_key(UserName=username)
            access_key = keys.get('AccessKey', {}).get('AccessKeyId')
            secret_key = keys.get('AccessKey', {}).get('SecretAccessKey')
        except ClientError as e:
            access_key = secret_key = None
            code = e.response.get('Error', {}).get('Code', '')
            if code != 'EntityAlreadyExists':
                raise
        try:
            iam.create_group(GroupName=group)
        except ClientError as e:
            code = e.response.get('Error', {}).get('Code', '')
            if code != 'EntityAlreadyExists':
                raise
        try:
            iam.add_user_to_group(GroupName=group, UserName=username)
        except ClientError as e:
            code = e.response.get('Error', {}).get('Code', '')
            if code != 'EntityAlreadyExists':
                raise
        iam.put_group_policy(
            GroupName=group,
            PolicyName=policy_name,
            PolicyDocument=WATCHER_POLICY)
        return access_key, secret_key
def create_provider_keys ( cls , username = USERNAME , group = GROUP , policy_name = POLICY_NAME , policy = WATCHER_POLICY ) : iam = boto3 . client ( 'iam' , region_name = os . getenv ( 'SERA_REGION' ) , aws_access_key_id = os . getenv ( 'SERA_ACCESS_KEY' ) , aws_secret_access_key = os . getenv ( 'SERA_SECRET_KEY' ) ) try : iam . create_user ( UserName = username ) keys = iam . create_access_key ( UserName = username ) access_key = keys . get ( 'AccessKey' , { } ) . get ( 'AccessKeyId' ) secret_key = keys . get ( 'AccessKey' , { } ) . get ( 'SecretAccessKey' ) except ClientError as e : access_key = secret_key = None code = e . response . get ( 'Error' , { } ) . get ( 'Code' , '' ) if code != 'EntityAlreadyExists' : raise try : iam . create_group ( GroupName = group ) except ClientError as e : code = e . response . get ( 'Error' , { } ) . get ( 'Code' , '' ) if code != 'EntityAlreadyExists' : raise try : iam . add_user_to_group ( GroupName = group , UserName = username ) except ClientError as e : code = e . response . get ( 'Error' , { } ) . get ( 'Code' , '' ) if code != 'EntityAlreadyExists' : raise iam . put_group_policy ( GroupName = group , PolicyName = policy_name , PolicyDocument = WATCHER_POLICY ) return access_key , secret_key
Create a provider user with permissions for the watcher to connect
Create a provider user with permissions for the watcher to connect
"""Create a provider user with permissions for the watcher to connect"""
cls
username
group
policy_name
policy