def get_secret(self, token, owner_type, resource_type, source, name): """ Get secret from secret service :param token: :param owner_type: :param resource_type: :param source: :param name: :return: """ try: token = "Bearer " + token metadata = (('authorization', token), ) owner_type = ResourceOwnerType.Value(owner_type) resource_type = ResourceType.Value(resource_type) source = ResourceSource.Value(source) met = SecretMetadata(owner_type=owner_type, resource_type=resource_type, source=source, name=name) request = GetSecretRequest(metadata=met) msg = self.resource_sec_client.getSecret(request=request, metadata=metadata) return MessageToJson(msg) except Exception: logger.exception("Error occurred while fetching secrets") raise
def add_ssh_credential(self, token, client_id, owner_id, description): try: token = "Bearer " + token metadata = (('authorization', token), ) secret_metadata = SecretMetadata(client_id=client_id, owner_id=owner_id, description=description) ssh_cred = SSHCredential(metadata=secret_metadata) return self.resource_sec_client.addSSHCredential(request=ssh_cred, metadata=metadata) except Exception: logger.exception("Error occurred while creating ssh key") raise
def get_KV_credential(self, token, user_token, client_id, key): try: token = "Bearer " + token metadata = ( ('authorization', token), ('user_token', user_token), ) secret_metadata = SecretMetadata(client_id=client_id) request = KVCredential(key=key, metadata=secret_metadata) msg = self.resource_sec_client.getKVCredential(request=request, metadata=metadata) return MessageToJson(msg) except Exception: logger.exception("Error occurred while get KV credential") raise
def add_password_credential(self, token, client_id, owner_id, description, password): try: token = "Bearer " + token metadata = (('authorization', token), ) secret_metadata = SecretMetadata(client_id=client_id, owner_id=owner_id, description=description) password_cred = PasswordCredential(metadata=secret_metadata, password=password) return self.resource_sec_client.addPasswordCredential( request=password_cred, metadata=metadata) except Exception: logger.exception("Error occurred while creating password key") raise