conjur-asset-host-factory 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3c2d66c6541a8eca47e87920a0a70a0d457c570
4
- data.tar.gz: 750acd291ddef8c6b792368a6c5531f0f9616ad2
3
+ metadata.gz: cd29397edddda0f79be357cdbe3b49c6868e9e5c
4
+ data.tar.gz: 592e45e7862422b2bc162ec797c5d45f756aeacd
5
5
  SHA512:
6
- metadata.gz: 35f6c10d408630bcc2e81210091c5926e84db14cf45f5317327a944948da28714b9cdf4405ab6f1b47e70a67ca1145ad1d0ecb0003c33c3a6d88bb5ba79be807
7
- data.tar.gz: bdd0d00d9b258c4c91ffbebd60697e1445e1ae791cdf2803117f43f575d714d5c347315fc070a3116809881d803a0b39e512d2b04ce886a310603f0282e48ea1
6
+ metadata.gz: 4a282dd21436c06d180575e127643e8a05735ab6667dbdc3151d90fa8ecf8f32319b9da0c4800e5a890ce0f1628ab43f4ad6602bd8b9afdc0c3b9ba4cda27a11
7
+ data.tar.gz: 386db30d18c70b7b81c82c7b8055e0ea7d20812ad320362f94323c0207560868e60be01dcfdb72842c9df67af839ef2a3ae7c0a5a07e616783751104201c05d9
@@ -21,7 +21,7 @@
21
21
  module Conjur
22
22
  module Asset
23
23
  module HostFactory
24
- VERSION = "1.0.0"
24
+ VERSION = "1.1.0"
25
25
  end
26
26
  end
27
27
  end
@@ -22,14 +22,27 @@ require 'conjur/host_factory'
22
22
 
23
23
  module Conjur
24
24
  class API
25
+ class << self
26
+ # Creates a host and returns the response Hash.
27
+ def host_factory_create_host token, id, options = {}
28
+ token = token.token if token.is_a?(HostFactoryToken)
29
+ http_options = {
30
+ headers: { authorization: %Q(Token token="#{token}") }
31
+ }
32
+ response = RestClient::Resource.new(Conjur::API.host_factory_asset_host, http_options)["hosts"].post(options.merge(id: id)).body
33
+ JSON.parse(response)
34
+ end
35
+ end
36
+
25
37
  # Options:
26
38
  # +layers+ list of host factory layers
27
- # +roleid+ host factory role
39
+ # +roleid+ host factory role id
40
+ # +role+ host factory role. If this is provided, it is converted to roleid.
28
41
  def create_host_factory(id, options = {})
29
42
  if options[:layers]
30
43
  options[:layers] = options[:layers].map do |layer|
31
44
  if layer.is_a?(Conjur::Layer)
32
- layer.resourceid
45
+ layer.id
33
46
  elsif layer.is_a?(String)
34
47
  layer
35
48
  else
@@ -37,6 +50,9 @@ module Conjur
37
50
  end
38
51
  end
39
52
  end
53
+ if role = options.delete(:role)
54
+ options[:roleid] = role.roleid
55
+ end
40
56
  log do |logger|
41
57
  logger << "Creating host_factory #{id}"
42
58
  unless options.blank?
@@ -53,21 +69,25 @@ module Conjur
53
69
  Conjur::HostFactory.new(Conjur::API.host_factory_asset_host, credentials)[fully_escape(id)]
54
70
  end
55
71
 
72
+ def revoke_host_factory_token token
73
+ token = token.token if token.is_a?(Conjur::HostFactoryToken)
74
+ RestClient::Resource.new(Conjur::API.host_factory_asset_host, credentials)["tokens/#{token}"].delete
75
+ end
76
+
77
+ def show_host_factory_token token
78
+ token = token.token if token.is_a?(Conjur::HostFactoryToken)
79
+ attrs = JSON.parse(RestClient::Resource.new(Conjur::API.host_factory_asset_host, credentials)["tokens/#{token}"].get.body)
80
+ Conjur::HostFactoryToken.new(Conjur::API.host_factory_asset_host, credentials)["tokens"][attrs['token']].tap do |token|
81
+ token.attributes = attrs
82
+ end
83
+ end
84
+
85
+ # Creates a Host and returns a Host object.
56
86
  def host_factory_create_host token, id, options = {}
57
- token = token.token if token.is_a?(HostFactoryToken)
58
- http_options = {
59
- headers: { authorization: %Q(Token token="#{token}") }
60
- }
61
- response = RestClient::Resource.new(Conjur::API.host_factory_asset_host, http_options)["hosts"].post(options.merge(id: id)).body
62
- attributes = JSON.parse(response)
87
+ attributes = self.class.host_factory_create_host token, id, options
63
88
  Conjur::Host.new(Conjur::API.core_asset_host, credentials)["hosts"][fully_escape attributes['id']].tap do |host|
64
89
  host.attributes = attributes
65
90
  end
66
91
  end
67
-
68
- def revoke_host_factory_token token
69
- token = token.token if token.is_a?(Conjur::HostFactoryToken)
70
- RestClient::Resource.new(Conjur::API.host_factory_asset_host, credentials)["tokens/#{token}"].delete
71
- end
72
92
  end
73
93
  end
@@ -132,6 +132,16 @@ By default, this command creates one token. Optionally, it can be used to create
132
132
  puts "Token revoked"
133
133
  end
134
134
  end
135
+
136
+ tokens.desc "Show a token"
137
+ tokens.arg_name "token"
138
+ tokens.command :show do |c|
139
+ c.action do |global_options,options,args|
140
+ token = require_arg(args, 'token')
141
+
142
+ display api.show_host_factory_token(token), options
143
+ end
144
+ end
135
145
  end
136
146
 
137
147
  hf.desc "Operations on hosts"
@@ -143,7 +153,7 @@ By default, this command creates one token. Optionally, it can be used to create
143
153
  token = require_arg(args, 'token')
144
154
  id = require_arg(args, 'host-id')
145
155
 
146
- host = api.host_factory_create_host token, id, options
156
+ host = Conjur::API.host_factory_create_host token, id, options
147
157
  display host
148
158
  end
149
159
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conjur-asset-host-factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Gilpin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-26 00:00:00.000000000 Z
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: conjur-api