def test_creates_clients_with_overrides(self): overrides = {"region_name": "custom", "verify": True, "other_thing": "more custom"} client = utils.create_client_from_parsed_globals(self.session, "ec2", self.parsed_globals, overrides) self.assertEqual(self.fake_client, client) self.session.create_client.assert_called_once_with( "ec2", region_name="custom", verify=True, other_thing="more custom", endpoint_url="https://foo.bar.com" )
def _run_main(self, parsed_args, parsed_globals): tool = parsed_args.tool.lower() package_format = self.TOOL_MAP[tool]['package_format'] codeartifact_client = cli_utils.create_client_from_parsed_globals( self._session, 'codeartifact', parsed_globals ) auth_token_res = self._get_authorization_token( codeartifact_client, parsed_args ) repository_endpoint = self._get_repository_endpoint( codeartifact_client, parsed_args, package_format ) domain = parsed_args.domain repository = parsed_args.repository namespace = self._get_namespace(tool, parsed_args) auth_token = auth_token_res['authorizationToken'] expiration = parse_timestamp(auth_token_res['expiration']) login = self.TOOL_MAP[tool]['login_cls']( auth_token, expiration, repository_endpoint, domain, repository, subprocess, namespace ) login.login(parsed_args.dry_run) return 0
def _run_main(self, parsed_args, parsed_globals): s3 = create_client_from_parsed_globals(self._session, 's3', parsed_globals) self._lambda = create_client_from_parsed_globals( self._session, 'lambda', parsed_globals) self._sns = create_client_from_parsed_globals(self._session, 'sns', parsed_globals) self._sqs = create_client_from_parsed_globals(self._session, 'sqs', parsed_globals) sts = create_client_from_parsed_globals(self._session, 'sts', parsed_globals) self._notification_configuration = s3.get_bucket_notification_configuration( Bucket=parsed_args.bucket, ) self._region = s3.get_bucket_location( Bucket=parsed_args.bucket)['LocationConstraint'] self._caller = sts.get_caller_identity() paginator = s3.get_paginator('list_objects_v2') params = {'Bucket': parsed_args.bucket, 'PaginationConfig': {}} if parsed_args.delimiter is not None: params['Delimiter'] = parsed_args.delimiter if parsed_args.start_after is not None: params['StartAfter'] = parsed_args.start_after if parsed_args.prefix is not None: params['Prefix'] = parsed_args.prefix if parsed_args.page_size is not None: params['PaginationConfig']['PageSize'] = parsed_args.page_size if parsed_args.max_items is not None: params['PaginationConfig']['MaxItems'] = parsed_args.max_items if parsed_args.starting_token is not None: params['PaginationConfig'][ 'StartingToken'] = parsed_args.starting_token iterator = paginator.paginate(**params) for response in iterator: if (response['KeyCount'] == 0): print('We are done here') else: [ self.process_file(parsed_args.bucket, file) for file in response['Contents'] ] return 0
def test_creates_clients_with_no_overrides(self): client = utils.create_client_from_parsed_globals( self.session, 'ec2', self.parsed_globals) self.assertEqual(self.fake_client, client) self.session.create_client.assert_called_once_with( 'ec2', region_name='us-west-2', verify=False, endpoint_url='https://foo.bar.com')
def test_creates_clients_with_no_overrides(self): client = utils.create_client_from_parsed_globals( self.session, 'ec2', self.parsed_globals) self.assertEqual(self.fake_client, client) self.session.create_client.assert_called_once_with( 'ec2', region_name='us-west-2', verify=False, endpoint_url='https://foo.bar.com' )
def _run_main(self, parsed_args, parsed_globals): ecr_public_client = create_client_from_parsed_globals( self._session, 'ecr-public', parsed_globals) result = ecr_public_client.get_authorization_token() auth = result['authorizationData'] auth_token = b64decode(auth['authorizationToken']).decode() _, password = auth_token.split(':') sys.stdout.write(password) sys.stdout.write('\n') return 0
def _run_main(self, parsed_args, parsed_globals): ecr_client = create_client_from_parsed_globals( self._session, 'ecr', parsed_globals) if not parsed_args.registry_ids: result = ecr_client.get_authorization_token() else: result = ecr_client.get_authorization_token( registryIds=parsed_args.registry_ids) for auth in result['authorizationData']: auth_token = b64decode(auth['authorizationToken']).decode() username, password = auth_token.split(':') sys.stdout.write('docker login -u %s -p %s -e none %s\n' % (username, password, auth['proxyEndpoint'])) return 0
def test_creates_clients_with_overrides(self): overrides = { 'region_name': 'custom', 'verify': True, 'other_thing': 'more custom' } client = utils.create_client_from_parsed_globals( self.session, 'ec2', self.parsed_globals, overrides) self.assertEqual(self.fake_client, client) self.session.create_client.assert_called_once_with( 'ec2', region_name='custom', verify=True, other_thing='more custom', endpoint_url='https://foo.bar.com')
def test_creates_clients_with_overrides(self): overrides = { 'region_name': 'custom', 'verify': True, 'other_thing': 'more custom' } client = utils.create_client_from_parsed_globals( self.session, 'ec2', self.parsed_globals, overrides) self.assertEqual(self.fake_client, client) self.session.create_client.assert_called_once_with( 'ec2', region_name='custom', verify=True, other_thing='more custom', endpoint_url='https://foo.bar.com' )
def _run_main(self, parsed_args, parsed_globals): ecr_client = create_client_from_parsed_globals( self._session, 'ecr', parsed_globals) if not parsed_args.registry_ids: result = ecr_client.get_authorization_token() else: result = ecr_client.get_authorization_token( registryIds=parsed_args.registry_ids) for auth in result['authorizationData']: auth_token = b64decode(auth['authorizationToken']).decode() username, password = auth_token.split(':') command = ['docker', 'login', '-u', username, '-p', password] if parsed_args.include_email: command.extend(['-e', 'none']) command.append(auth['proxyEndpoint']) sys.stdout.write(' '.join(command)) sys.stdout.write('\n') return 0
def _run_main(self, parsed_args, parsed_globals): tool = parsed_args.tool.lower() package_format = self.TOOL_MAP[tool]['package_format'] codeartifact_client = cli_utils.create_client_from_parsed_globals( self._session, 'codeartifact', parsed_globals) auth_token = self._get_authorization_token(codeartifact_client, parsed_args) repository_endpoint = self._get_repository_endpoint( codeartifact_client, parsed_args, package_format) login = self.TOOL_MAP[tool]['login_cls'](auth_token, repository_endpoint, subprocess) login.login(parsed_args.dry_run) return 0
def test_creates_clients_with_no_parsed_globals(self): client = utils.create_client_from_parsed_globals( self.session, 'ec2', argparse.Namespace()) self.assertEqual(self.fake_client, client) self.session.create_client.assert_called_once_with('ec2')
def _create_clients(self, args, parsed_globals): self.iam = self._session.create_client('iam') self.opsworks = create_client_from_parsed_globals( self._session, 'opsworks', parsed_globals)