Class: Conjur::HostFactory
- Inherits:
-
BaseObject
- Object
- BaseObject
- Conjur::HostFactory
- Includes:
- ActsAsRolsource
- Defined in:
- lib/conjur/host_factory.rb
Overview
A Host Factory is a way to allow clients to create Conjur hosts without giving them any other access to Conjur.
Each Host Factory can have 0 or more tokens, each of which is a random string that has an associated expiration and optional CIDR restriction. A user or machine who has a host factory token can use it to create new hosts, or to rotate the API keys of existing hosts.
Instance Attribute Summary
Attributes inherited from BaseObject
Instance Method Summary collapse
-
#create_token(expiration, cidr: nil) ⇒ Object
Create a new token.
-
#create_tokens(expiration, count: 1, cidr: nil) ⇒ Array<HostFactoryToken>
Create one or more host factory tokens.
-
#tokens ⇒ Array<HostFactoryToken>
Enumerate the tokens on the host factory.
Methods inherited from BaseObject
#account, #as_json, #identifier, #initialize, #inspect, #kind, #username
Methods included from Routing
Methods included from BuildObject
Methods included from LogSource
Constructor Details
This class inherits a constructor from Conjur::BaseObject
Instance Method Details
#create_token(expiration, cidr: nil) ⇒ Object
Create a new token.
59 60 61 |
# File 'lib/conjur/host_factory.rb', line 59 def create_token expiration, cidr: nil create_tokens(expiration, cidr: cidr).first end |
#create_tokens(expiration, count: 1, cidr: nil) ⇒ Array<HostFactoryToken>
Create one or more host factory tokens. Each token can be used to create hosts, using API.host_factory_create_host.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/conjur/host_factory.rb', line 44 def create_tokens expiration, count: 1, cidr: nil = {} [:expiration] = expiration.iso8601 [:host_factory] = id [:count] = count [:cidr] = cidr if cidr response = JSON.parse url_for(:host_factory_create_tokens, credentials, id).post() response.map do |data| HostFactoryToken.new data, credentials end end |
#tokens ⇒ Array<HostFactoryToken>
Enumerate the tokens on the host factory.
66 67 68 69 70 71 72 73 |
# File 'lib/conjur/host_factory.rb', line 66 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 |data| HostFactoryToken.new data, credentials end end |