def setUp(self): self.domain = 'domain' self.domain_owner = 'domain-owner' self.package_format = 'npm' self.repository = 'repository' self.auth_token = 'auth-token' self.namespace = 'namespace' self.expiration = (datetime.now(tzlocal()) + relativedelta(hours=10) + relativedelta(minutes=9)).replace(microsecond=0) self.endpoint = 'https://{domain}-{domainOwner}.codeartifact.aws.' \ 'a2z.com/{format}/{repository}/'.format( domain=self.domain, domainOwner=self.domain_owner, format=self.package_format, repository=self.repository ) repo_uri = urlparse.urlsplit(self.endpoint) always_auth_config = '//{}{}:always-auth'.format( repo_uri.netloc, repo_uri.path) auth_token_config = '//{}{}:_authToken'.format(repo_uri.netloc, repo_uri.path) self.commands = [] self.commands.append( [self.NPM_CMD, 'config', 'set', 'registry', self.endpoint]) self.commands.append( [self.NPM_CMD, 'config', 'set', always_auth_config, 'true']) self.commands.append([ self.NPM_CMD, 'config', 'set', auth_token_config, self.auth_token ]) self.subprocess_utils = mock.Mock() self.test_subject = NpmLogin(self.auth_token, self.expiration, self.endpoint, self.subprocess_utils)
def _get_npm_commands(self, **kwargs): npm_cmd = 'npm.cmd' \ if platform.system().lower() == 'windows' else 'npm' repo_uri = urlparse.urlsplit(self.endpoint) always_auth_config = '//{}{}:always-auth'.format( repo_uri.netloc, repo_uri.path ) auth_token_config = '//{}{}:_authToken'.format( repo_uri.netloc, repo_uri.path ) scope = kwargs.get('scope') registry = '{}:registry'.format(scope) if scope else 'registry' commands = [] commands.append( [npm_cmd, 'config', 'set', registry, self.endpoint] ) commands.append( [npm_cmd, 'config', 'set', always_auth_config, 'true'] ) commands.append( [npm_cmd, 'config', 'set', auth_token_config, self.auth_token] ) return commands
def setUp(self): self.domain = 'domain' self.domain_owner = 'domain-owner' self.package_format = 'pip' self.repository = 'repository' self.auth_token = 'auth-token' self.expiration = (datetime.now(tzlocal()) + relativedelta(years=1) + relativedelta(months=9)).replace(microsecond=0) self.endpoint = 'https://{domain}-{domainOwner}.codeartifact.aws.' \ 'a2z.com/{format}/{repository}/'.format( domain=self.domain, domainOwner=self.domain_owner, format=self.package_format, repository=self.repository ) repo_uri = urlparse.urlsplit(self.endpoint) self.pip_index_url = self.PIP_INDEX_URL_FMT.format( scheme=repo_uri.scheme, auth_token=self.auth_token, netloc=repo_uri.netloc, path=repo_uri.path) self.subprocess_utils = mock.Mock() self.test_subject = PipLogin(self.auth_token, self.expiration, self.endpoint, self.subprocess_utils)
def get_commands(cls, endpoint, auth_token, **kwargs): commands = [] scope = kwargs.get('scope') # prepend scope if it exists registry = '{}:registry'.format(scope) if scope else 'registry' # set up the codeartifact repository as the npm registry. commands.append( [cls.NPM_CMD, 'config', 'set', registry, endpoint] ) repo_uri = urlparse.urlsplit(endpoint) # configure npm to always require auth for the repository. always_auth_config = '//{}{}:always-auth'.format( repo_uri.netloc, repo_uri.path ) commands.append( [cls.NPM_CMD, 'config', 'set', always_auth_config, 'true'] ) # set auth info for the repository. auth_token_config = '//{}{}:_authToken'.format( repo_uri.netloc, repo_uri.path ) commands.append( [cls.NPM_CMD, 'config', 'set', auth_token_config, auth_token] ) return commands
def setUp(self): self.domain = 'domain' self.domain_owner = 'domain-owner' self.package_format = 'npm' self.repository = 'repository' self.auth_token = 'auth-token' self.endpoint = 'https://{domain}-{domainOwner}.codeartifact.aws.' \ 'a2z.com/{format}/{repository}/'.format( domain=self.domain, domainOwner=self.domain_owner, format=self.package_format, repository=self.repository ) repo_uri = urlparse.urlsplit(self.endpoint) always_auth_config = '//{}{}:always-auth'.format( repo_uri.netloc, repo_uri.path) auth_token_config = '//{}{}:_authToken'.format(repo_uri.netloc, repo_uri.path) self.commands = [] self.commands.append( [self.NPM_CMD, 'config', 'set', 'registry', self.endpoint]) self.commands.append( [self.NPM_CMD, 'config', 'set', always_auth_config, 'true']) self.commands.append([ self.NPM_CMD, 'config', 'set', auth_token_config, self.auth_token ]) self.subprocess_utils = mock.Mock() self.test_subject = NpmLogin(self.auth_token, self.endpoint, self.subprocess_utils)
def setUp(self): self.domain = 'domain' self.domain_owner = 'domain-owner' self.package_format = 'pip' self.repository = 'repository' self.auth_token = 'auth-token' self.endpoint = 'https://{domain}-{domainOwner}.codeartifact.aws.' \ 'a2z.com/{format}/{repository}/'.format( domain=self.domain, domainOwner=self.domain_owner, format=self.package_format, repository=self.repository ) repo_uri = urlparse.urlsplit(self.endpoint) self.pip_index_url = self.PIP_INDEX_URL_FMT.format( scheme=repo_uri.scheme, auth_token=self.auth_token, netloc=repo_uri.netloc, path=repo_uri.path) self.subprocess_utils = mock.Mock() self.test_subject = PipLogin(self.auth_token, self.endpoint, self.subprocess_utils)
def get_commands(cls, endpoint, auth_token, **kwargs): repo_uri = urlparse.urlsplit(endpoint) pip_index_url = cls.PIP_INDEX_URL_FMT.format(scheme=repo_uri.scheme, auth_token=auth_token, netloc=repo_uri.netloc, path=repo_uri.path) return [['pip', 'config', 'set', 'global.index-url', pip_index_url]]
def _get_pip_commands(self): pip_index_url_fmt = '{scheme}://aws:{auth_token}@{netloc}{path}simple/' repo_uri = urlparse.urlsplit(self.endpoint) pip_index_url = pip_index_url_fmt.format(scheme=repo_uri.scheme, auth_token=self.auth_token, netloc=repo_uri.netloc, path=repo_uri.path) return [['pip', 'config', 'set', 'global.index-url', pip_index_url]]