def GetVaultStatistics(self, vault): """Retrieve the statistics on a Vault :param vault: vault to get the statistics for :store: The Statistics for the Vault in the statistics property for the specific Vault :returns: True on success :raises: TypeError if vault is not a Vault object :raises: RunTimeError on failure """ path = api_v1.get_vault_path(vault.vault_id) self.ReInit(self.sslenabled, path) self.__update_headers() self.__log_request_data(fn='Get Vault Statistics') res = requests.get(self.Uri, headers=self.Headers) self.__log_response_data(res, jsondata=True, fn='Get Vault Statistics') if res.status_code == 200: vault.statistics = res.json() return True else: raise RuntimeError( 'Failed to get Vault statistics. ' 'Error ({0:}): {1:}'.format(res.status_code, res.text))
def VaultExists(self, vault): """Return the statistics on a Vault :param vault: Vault object for the vault or name of vault to be verified :returns: True if the Vault exists; otherwise False :raises: RunTimeError on error """ # Note: We cannot use GetVault() here b/c it would # end up being self-referential vault_id = vault if isinstance(vault, api_vault.Vault): vault_id = vault.vault_id path = api_v1.get_vault_path(vault_id) self.ReInit(self.sslenabled, path) self.__update_headers() self.__log_request_data(fn='Vault Exists') res = requests.head(self.Uri, headers=self.Headers) self.__log_response_data(res, jsondata=False, fn='Vault Exists') if res.status_code == 204: if isinstance(vault, api_vault.Vault): vault.status = 'valid' return True elif res.status_code == 404: if isinstance(vault, api_vault.Vault): vault.status = 'invalid' return False else: raise RuntimeError( 'Failed to determine if Vault exists. ' 'Error ({0:}): {1:}'.format(res.status_code, res.text))
def CreateVault(self, vault_name): """Create a vault :param vault_name: name of the vault :returns: deuceclient.api.Vault instance of the new Vault :raises: TypeError if vault_name is not a string object :raises: RunTimeError on failure """ path = api_v1.get_vault_path(vault_name) self.ReInit(self.sslenabled, path) self.__update_headers() self.__log_request_data(fn='Create Vault') res = requests.put(self.Uri, headers=self.Headers) self.__log_response_data(res, jsondata=False, fn='Create Vault') if res.status_code == 201: vault = api_vault.Vault(project_id=self.project_id, vault_id=vault_name) vault.status = 'created' return vault else: raise RuntimeError( 'Failed to create Vault. ' 'Error ({0:}): {1:}'.format(res.status_code, res.text))
def DeleteVault(self, vault): """Delete a Vault :param vault: the vault to be deleted :returns: True on success :raises: TypeError if vault is not a Vault object :raises: RunTimeError on failure """ path = api_v1.get_vault_path(vault.vault_id) self.ReInit(self.sslenabled, path) self.__update_headers() self.__log_request_data(fn='Delete Vault') res = requests.delete(self.Uri, headers=self.Headers) self.__log_response_data(res, jsondata=False, fn='Delete Vault') if res.status_code == 204: vault.status = 'deleted' return True else: raise RuntimeError( 'Failed to delete Vault. ' 'Error ({0:}): {1:}'.format(res.status_code, res.text))