示例#1
0
 def _check_group_exists(self, group, method):
     try:
         self.groups[group]
     except KeyError:
         raise client_error(
             method, 'NoSuchEntity',
             'The group with name %s cannot be found.' % group)
示例#2
0
 def _check_user_has_policy(policy, user, method):
     if policy not in user.attached_policies:
         raise client_error(method,
                            'NoSuchEntity',
                            'The policy with name %s '
                            'is not attached to the user with name '
                            '%s.' % (policy, user.username))
示例#3
0
 def _check_signing_certificate_exists(self, user, cert_id, method):
     try:
         self.users[user].signing_certs[cert_id]
     except KeyError:
         raise client_error(
             method, 'NoSuchEntity',
             'The signing certificate with certificate id '
             '%s cannot be found.' % cert_id)
示例#4
0
 def _check_group_exists(self, group, method):
     try:
         self.groups[group]
     except KeyError:
         raise client_error(method,
                            'NoSuchEntity',
                            'The group with name %s cannot be found.'
                            % group)
示例#5
0
 def _check_signing_certificate_exists(self, user, cert_id, method):
     try:
         self.users[user].signing_certs[cert_id]
     except KeyError:
         raise client_error(method,
                            'NoSuchEntity',
                            'The signing certificate with certificate id '
                            '%s cannot be found.' % cert_id)
示例#6
0
 def _check_user_exists(self, user, method):
     try:
         self.users[user]
     except KeyError:
         raise client_error(method,
                            'NoSuchEntity',
                            'The user with name %s cannot be found.'
                            % user)
示例#7
0
    def _check_policy_exists(self, policy_name, method):
        try:
            policy = self.policies[policy_name]
        except KeyError:
            raise client_error(
                method, 'NoSuchEntity', 'The policy with name %s '
                'cannot be found.' % policy_name)

        return policy
示例#8
0
    def create_user(self, kwargs):
        """Create user if user does not exist."""
        if kwargs['UserName'] in self.users:
            raise client_error(
                'CreateUser', 'EntityAlreadyExists',
                'User with name %s already exists.' % kwargs['UserName'])

        self.users[kwargs['UserName']] = User(kwargs['UserName'])
        return responses.user_response(kwargs['UserName'])
示例#9
0
    def create_group(self, kwargs):
        """Create group if it does not exist."""
        if kwargs['GroupName'] in self.groups:
            raise client_error(
                'CreateGroup', 'EntityAlreadyExists',
                'Group with name %s already exists.' % kwargs['GroupName'])

        group = Group(kwargs['GroupName'])
        self.groups[group.name] = group
        return responses.group_response(group)
示例#10
0
    def create_user(self, kwargs):
        """Create user if user does not exist."""
        if kwargs['UserName'] in self.users:
            raise client_error('CreateUser',
                               'EntityAlreadyExists',
                               'User with name %s already exists.'
                               % kwargs['UserName'])

        self.users[kwargs['UserName']] = User(kwargs['UserName'])
        return responses.user_response(kwargs['UserName'])
示例#11
0
    def _check_policy_exists(self, policy_name, method):
        try:
            policy = self.policies[policy_name]
        except KeyError:
            raise client_error(method,
                               'NoSuchEntity',
                               'The policy with name %s '
                               'cannot be found.' % policy_name)

        return policy
示例#12
0
    def create_group(self, kwargs):
        """Create group if it does not exist."""
        if kwargs['GroupName'] in self.groups:
            raise client_error('CreateGroup',
                               'EntityAlreadyExists',
                               'Group with name %s already exists.'
                               % kwargs['GroupName'])

        group = Group(kwargs['GroupName'])
        self.groups[group.name] = group
        return responses.group_response(group)
示例#13
0
    def mock_make_api_call(self, operation_name, kwargs):
        """Entry point for mocking AWS endpoints.

        Calls the mocked AWS operation and returns a parsed
        response.

        If the AWS endpoint is not mocked raise a client error.
        """
        try:
            return getattr(self, inflection(operation_name))(kwargs)
        except AttributeError:
            raise client_error(operation_name, 'NoSuchMethod',
                               'Operation not mocked.')
示例#14
0
    def enable_mfa_device(self, kwargs):
        """Enable MFA Device for user."""
        self._check_user_exists(kwargs['UserName'], 'EnableMFADevice')

        user = self.users[kwargs['UserName']]
        if kwargs['SerialNumber'] in user.mfa_devices:
            raise client_error('EnableMFADevice',
                               'EntityAlreadyExists',
                               'Device with serial number %s already '
                               'exists.' % kwargs['SerialNumber'])

        user.enable_mfa_device(kwargs['SerialNumber'])
        return responses.generic_response()
示例#15
0
    def upload_signing_certificate(self, kwargs):
        self._check_user_exists(kwargs['UserName'], 'UploadSigningCertificate')

        user = self.users[kwargs['UserName']]
        for key, cert in user.signing_certs.items():
            if kwargs['CertificateBody'] == cert.body:
                raise client_error('UploadSigningCertificate',
                                   'DuplicateCertificate',
                                   'A duplicate certificate already exists.')

        cert = user.upload_signing_certificate(kwargs['CertificateBody'])
        return responses.upload_signing_certificate_response(
            kwargs['UserName'], cert)
示例#16
0
    def enable_mfa_device(self, kwargs):
        """Enable MFA Device for user."""
        self._check_user_exists(kwargs['UserName'], 'EnableMFADevice')

        user = self.users[kwargs['UserName']]
        if kwargs['SerialNumber'] in user.mfa_devices:
            raise client_error(
                'EnableMFADevice', 'EntityAlreadyExists',
                'Device with serial number %s already '
                'exists.' % kwargs['SerialNumber'])

        user.enable_mfa_device(kwargs['SerialNumber'])
        return responses.generic_response()
示例#17
0
    def create_policy(self, kwargs):
        """Create policy given policy document."""
        if kwargs['PolicyName'] in self.policies:
            raise client_error(
                'CreatePolicy', 'EntityAlreadyExists',
                'Policy with name %s already'
                'exists.' % kwargs['PolicyName'])

        policy = Policy(kwargs.get('PolicyName'), kwargs.get('PolicyDocument'),
                        kwargs.get('Description', None),
                        kwargs.get('Path', None))
        self.policies[policy.name] = policy
        return responses.create_policy_response(policy)
示例#18
0
    def deactivate_mfa_device(self, kwargs):
        """Deactivate and detach MFA Device from user if device exists."""
        self._check_user_exists(kwargs['UserName'], 'DeactivateMFADevice')

        user = self.users[kwargs['UserName']]
        if kwargs['SerialNumber'] not in user.mfa_devices:
            raise client_error('DeactivateMFADevice',
                               'NoSuchEntity',
                               'Device with serial number %s cannot '
                               'be found.' % kwargs['SerialNumber'])

        user.deactivate_mfa_device(kwargs['SerialNumber'])
        return responses.generic_response()
示例#19
0
    def deactivate_mfa_device(self, kwargs):
        """Deactivate and detach MFA Device from user if device exists."""
        self._check_user_exists(kwargs['UserName'], 'DeactivateMFADevice')

        user = self.users[kwargs['UserName']]
        if kwargs['SerialNumber'] not in user.mfa_devices:
            raise client_error(
                'DeactivateMFADevice', 'NoSuchEntity',
                'Device with serial number %s cannot '
                'be found.' % kwargs['SerialNumber'])

        user.deactivate_mfa_device(kwargs['SerialNumber'])
        return responses.generic_response()
示例#20
0
    def mock_make_api_call(self, operation_name, kwargs):
        """Entry point for mocking AWS endpoints.

        Calls the mocked AWS operation and returns a parsed
        response.

        If the AWS endpoint is not mocked raise a client error.
        """
        try:
            return getattr(self, inflection(operation_name))(kwargs)
        except AttributeError:
            raise client_error(operation_name,
                               'NoSuchMethod',
                               'Operation not mocked.')
示例#21
0
    def create_policy(self, kwargs):
        """Create policy given policy document."""
        if kwargs['PolicyName'] in self.policies:
            raise client_error('CreatePolicy',
                               'EntityAlreadyExists',
                               'Policy with name %s already'
                               'exists.' % kwargs['PolicyName'])

        policy = Policy(kwargs.get('PolicyName'),
                        kwargs.get('PolicyDocument'),
                        kwargs.get('Description', None),
                        kwargs.get('Path', None))
        self.policies[policy.name] = policy
        return responses.create_policy_response(policy)
示例#22
0
    def upload_signing_certificate(self, kwargs):
        self._check_user_exists(kwargs['UserName'], 'UploadSigningCertificate')

        user = self.users[kwargs['UserName']]
        for key, cert in user.signing_certs.items():
            if kwargs['CertificateBody'] == cert.body:
                raise client_error('UploadSigningCertificate',
                                   'DuplicateCertificate',
                                   'A duplicate certificate already exists.')

        cert = user.upload_signing_certificate(kwargs['CertificateBody'])
        return responses.upload_signing_certificate_response(
            kwargs['UserName'],
            cert
        )
示例#23
0
    def create_login_profile(self, kwargs):
        """Create login profile for user if user has no password."""
        self._check_user_exists(kwargs['UserName'], 'CreateLoginProfile')

        user = self.users[kwargs['UserName']]
        if user.login_profile:
            raise client_error('CreateLoginProfile',
                               'EntityAlreadyExists',
                               'LoginProfile for user with name %s '
                               'already exists.' % user.username)

        reset_required = kwargs.get('PasswordResetRequired', None)
        user.create_login_profile(kwargs['Password'],
                                  reset_required=reset_required)
        return responses.login_profile_response(user, create=True)
示例#24
0
    def create_login_profile(self, kwargs):
        """Create login profile for user if user has no password."""
        self._check_user_exists(kwargs['UserName'], 'CreateLoginProfile')

        user = self.users[kwargs['UserName']]
        if user.login_profile:
            raise client_error(
                'CreateLoginProfile', 'EntityAlreadyExists',
                'LoginProfile for user with name %s '
                'already exists.' % user.username)

        reset_required = kwargs.get('PasswordResetRequired', None)
        user.create_login_profile(kwargs['Password'],
                                  reset_required=reset_required)
        return responses.login_profile_response(user, create=True)
示例#25
0
 def _access_key_not_found(access_key_id, method):
     raise client_error(
         method, 'NoSuchEntity',
         'The Access Key with id %s cannot be found.' % access_key_id)
示例#26
0
 def _check_login_profile_exists(user, method):
     if not user.login_profile:
         raise client_error(method,
                            'NoSuchEntity',
                            'LoginProfile for user with name %s'
                            ' cannot be found.' % user.username)
示例#27
0
 def _access_key_not_found(access_key_id, method):
     raise client_error(method,
                        'NoSuchEntity',
                        'The Access Key with id %s cannot be found.'
                        % access_key_id)
示例#28
0
 def _check_login_profile_exists(user, method):
     if not user.login_profile:
         raise client_error(
             method, 'NoSuchEntity', 'LoginProfile for user with name %s'
             ' cannot be found.' % user.username)
示例#29
0
 def _check_user_exists(self, user, method):
     try:
         self.users[user]
     except KeyError:
         raise client_error(method, 'NoSuchEntity',
                            'The user with name %s cannot be found.' % user)
示例#30
0
 def _check_user_has_policy(policy, user, method):
     if policy not in user.attached_policies:
         raise client_error(
             method, 'NoSuchEntity', 'The policy with name %s '
             'is not attached to the user with name '
             '%s.' % (policy, user.username))