def get_alt_creds(self): if self.isolated_creds.get('alt'): return self.isolated_creds.get('alt') creds = self._get_creds() alt_credential = cred_provider.get_credentials(**creds) self.isolated_creds['alt'] = alt_credential return alt_credential
def get_primary_creds(self): if self.isolated_creds.get('primary'): return self.isolated_creds.get('primary') creds = self._get_creds() primary_credential = cred_provider.get_credentials(**creds) self.isolated_creds['primary'] = primary_credential return primary_credential
def get_alt_creds(self): if self.isolated_creds.get('alt'): return self.isolated_creds.get('alt') if not self.use_default_creds: creds = self.get_creds(1) alt_credential = cred_provider.get_credentials(**creds) else: alt_credential = cred_provider.get_configured_credentials( 'alt_user') self.isolated_creds['alt'] = alt_credential return alt_credential
def get_primary_creds(self): if self.isolated_creds.get('primary'): return self.isolated_creds.get('primary') if not self.use_default_creds: creds = self.get_creds(0) primary_credential = cred_provider.get_credentials(**creds) else: primary_credential = cred_provider.get_configured_credentials( 'user') self.isolated_creds['primary'] = primary_credential return primary_credential
def get_creds_by_roles(self, roles, force_new=False): roles = list(set(roles)) exist_creds = self.isolated_creds.get(str(roles), None) # The force kwarg is used to allocate an additional set of creds with # the same role list. The index used for the previously allocation # in the isolated_creds dict will be moved. if exist_creds and not force_new: return exist_creds elif exist_creds and force_new: new_index = str(roles) + '-' + str(len(self.isolated_creds)) self.isolated_creds[new_index] = exist_creds creds = self._get_creds(roles=roles) role_credential = cred_provider.get_credentials(**creds) self.isolated_creds[str(roles)] = role_credential return role_credential
def get_creds_by_roles(self, roles, force_new=False): roles = list(set(roles)) exist_creds = self.isolated_creds.get(str(roles), None) index = 0 if exist_creds and not force_new: return exist_creds elif exist_creds and force_new: new_index = str(roles) + '-' + str(len(self.isolated_creds)) self.isolated_creds[new_index] = exist_creds # Figure out how many existing creds for this roles set are present # use this as the index the returning hash list to ensure separate # creds are returned with force_new being True for creds_names in self.isolated_creds: if str(roles) in creds_names: index = index + 1 if not self.use_default_creds: creds = self.get_creds(index, roles=roles) role_credential = cred_provider.get_credentials(**creds) self.isolated_creds[str(roles)] = role_credential else: msg = "Default credentials can not be used with specifying "\ "credentials by roles" raise exceptions.InvalidConfiguration(msg) return role_credential
def _get_credentials(self, user, tenant): return cred_provider.get_credentials( username=user['name'], user_id=user['id'], tenant_name=tenant['name'], tenant_id=tenant['id'], password=self.password)