class ContextHubVault::Client

Public Class Methods

new(host: ContextHubVault.host, auth_token: ContextHubVault.auth_token, version: ContextHubVault.version, app_id: ContextHubVault.app_id) click to toggle source
# File lib/context_hub_vault/client.rb, line 8
def initialize(host: ContextHubVault.host, auth_token: ContextHubVault.auth_token, version: ContextHubVault.version, app_id: ContextHubVault.app_id)
  if http_prefix(host)
    self.class.base_uri "#{host}/api"
  else
    self.class.base_uri "https://#{host}/api"
  end
  self.class.headers('Authorization' => %Q[Token token="#{auth_token}"]) if auth_token
  self.class.headers('Accept' => "application/vnd.carbon.vault.v#{version}") if version
  self.class.headers('HTTP_CARBON_APP_ID' => app_id) if app_id
end

Public Instance Methods

create(container, data = {}) click to toggle source

Create new vault data

@param container [String] The name of the vault container @param data [Hash] A hash of key/value pairs to store in the vault @return [Hash] The newly created vault

# File lib/context_hub_vault/client.rb, line 41
def create(container, data = {})
  fail 'Must include the container' unless container

  data.merge! container: container
  post '/vaults', body: data
end
destroy(id, data = {}) click to toggle source

Delete a vault by vault_id

@param id [String] vault_id

# File lib/context_hub_vault/client.rb, line 60
def destroy(id, data = {})
  delete "/vaults/#{id}"
end
find_by_id(id) click to toggle source

Find a vault by it's vault_id

@param id [String] vault_id @return [Hash] The full vault data structure that matches the vault_id

# File lib/context_hub_vault/client.rb, line 23
def find_by_id(id)
  search('vault_info.vault_id' => id).first
end
update(id, data = {}) click to toggle source

Update vault data

@param id [String] vault_id @param data [Hash] Data to update the vault with @return [Hash] The updated vault data structure

# File lib/context_hub_vault/client.rb, line 53
def update(id, data = {})
  patch "/vaults/#{id}", body: data
end

Private Instance Methods

delete(path, options = {}) click to toggle source
# File lib/context_hub_vault/client.rb, line 82
def delete(path, options = {})
  self.class.delete path, options
end
get(path, options = {}) click to toggle source
# File lib/context_hub_vault/client.rb, line 74
def get(path, options = {})
  self.class.get path, options
end
http_prefix(host) click to toggle source
# File lib/context_hub_vault/client.rb, line 66
def http_prefix(host)
  host.downcase.start_with?('http://', 'https://')
end
patch(path, options = {}) click to toggle source
# File lib/context_hub_vault/client.rb, line 78
def patch(path, options = {})
  self.class.patch path, options
end
post(path, options = {}) click to toggle source
# File lib/context_hub_vault/client.rb, line 70
def post(path, options = {})
  self.class.post path, options
end