def test_add_image_pull_secret(self): name = "mnubo.com-sa-{0}".format(str(uuid.uuid4().hex[:5])) acct = _utils.create_service_account(name=name) data = {"auths": {"repo:port": {"auth": "authstring", "email": "*****@*****.**"}}} if _utils.is_reachable(acct.config): acct.create() secret = K8sSecret.create_image_pull_secret(config=acct.config, name=acct.name, data=data) acct.add_image_pull_secret(secret) secrets = K8sSecret.list_image_pull_secrets() self.assertEqual(1, len(secrets))
def image_pull_secrets(self): refs = self.model.image_pull_secrets secrets = [] for ref in refs: s = K8sSecret(config=self.config, name=ref.name).get() secrets.append(s) return secrets
def create_secret(config=None, name=None): if config is None: config = create_config() obj = K8sSecret( config=config, name=name ) return obj
def test_add_api_token(self): name = "mnubo.com-sa-{0}".format(str(uuid.uuid4().hex[:5])) acct = _utils.create_service_account(name=name) if _utils.is_reachable(acct.config): acct.create() acct.add_api_token() secrets = K8sSecret.api_tokens_for_service_account(config=acct.config, name=acct.name) self.assertEqual(2, len(secrets))
def test_add_api_token(self): name = "mnubo.com-sa-{0}".format(str(uuid.uuid4().hex[:5])) acct = _utils.create_service_account(name=name) if _utils.is_reachable(acct.config): acct.create() acct.add_api_token() secrets = K8sSecret.api_tokens_for_service_account( config=acct.config, name=acct.name) self.assertEqual(2, len(secrets))
def test_add_image_pull_secret(self): name = "mnubo.com-sa-{0}".format(str(uuid.uuid4().hex[:5])) acct = _utils.create_service_account(name=name) data = { "auths": { "repo:port": { "auth": "authstring", "email": "*****@*****.**" } } } if _utils.is_reachable(acct.config): acct.create() secret = K8sSecret.create_image_pull_secret(config=acct.config, name=acct.name, data=data) acct.add_image_pull_secret(secret) secrets = K8sSecret.list_image_pull_secrets() self.assertEqual(1, len(secrets))
def cleanup_secrets(): ref = create_secret(name="throwaway") if is_reachable(ref.config.api_host): try: _list = ref.list() while len(_list) > 0: for secret in _list: try: name = secret['metadata']['name'] obj = K8sSecret(config=ref.config, name=name).get() if obj.type != 'kubernetes.io/service-account-token': obj.delete() if obj.type == 'kubernetes.io/service-account-token' and not re.search(r'default', name): obj.delete() if len(_list) == 1 and re.search(r'default', name): raise StopIteration except NotFoundException: continue _list = ref.list() except StopIteration: pass
def secrets(self): secrets = K8sSecret.api_tokens_for_service_account(config=self.config, name=self.name) return secrets
def add_api_token(self): return K8sSecret.create_service_account_api_token(config=self.config, name=self.name)
def add_api_token(self): return K8sSecret.create_service_account_api_token( config=self.config, name=self.name )