Class: Conjur::HostFactory

Inherits:
RestClient::Resource
  • Object
show all
Includes:
ActsAsAsset
Defined in:
lib/conjur/host_factory.rb

Instance Method Summary collapse

Methods included from ActsAsAsset

#add_member, #remove_member

Methods included from HasAttributes

#attributes, #invalidate, #refresh, #save, #to_json

Methods included from ActsAsResource

#deny, #permit, #resource, #resource_kind, #resourceid

Methods included from HasOwner

#ownerid, #userid

Methods included from Exists

#exists?

Methods included from HasId

#id

Instance Method Details

#create_token(expiration, options = {}) ⇒ Object



43
44
45
# File 'lib/conjur/host_factory.rb', line 43

def create_token(expiration, options = {})
  create_tokens(expiration, 1, options)[0]
end

#create_tokens(expiration, count, options = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/conjur/host_factory.rb', line 47

def create_tokens(expiration, count, options = {})
  parameters = options.merge({
    expiration: expiration.iso8601,
    count: count
  })
  response = RestClient::Resource.new(Conjur::API.host_factory_asset_host, self.options)[fully_escape id]["tokens"].post(parameters).body
  JSON.parse(response).map do |attrs|
    build_host_factory_token attrs
  end
end

#deputyObject



35
36
37
# File 'lib/conjur/host_factory.rb', line 35

def deputy
  Conjur::Deputy.new(Conjur::API.core_asset_host, options)["deputies/#{fully_escape id}"]
end

#deputy_api_keyObject



39
40
41
# File 'lib/conjur/host_factory.rb', line 39

def deputy_api_key
  attributes['deputy_api_key']
end

#roleObject



31
32
33
# File 'lib/conjur/host_factory.rb', line 31

def role
  Role.new(Conjur::Authz::API.host, self.options)[Conjur::API.parse_role_id(roleid).join('/')]
end

#roleidObject



27
28
29
# File 'lib/conjur/host_factory.rb', line 27

def roleid
  attributes['roleid']
end

#tokensObject



58
59
60
61
62
63
64
65
# File 'lib/conjur/host_factory.rb', line 58

def tokens
  # Tokens list is not returned by +show+ if the caller doesn't have permission
  return nil unless self.attributes['tokens']

  self.attributes['tokens'].collect do |attrs|
    build_host_factory_token attrs
  end
end