conjur-asset-host-factory 1.0.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 +7 -0
- data/.gitignore +23 -0
- data/.project +18 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +10 -0
- data/conjur-asset-host-factory.gemspec +25 -0
- data/lib/conjur-asset-host-factory-version.rb +27 -0
- data/lib/conjur-asset-host-factory.rb +22 -0
- data/lib/conjur/api/host_factories.rb +73 -0
- data/lib/conjur/command/host_factories.rb +152 -0
- data/lib/conjur/host-factory-api.rb +38 -0
- data/lib/conjur/host_factory.rb +75 -0
- data/lib/conjur/host_factory_token.rb +65 -0
- data/spec/.keepme +1 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e3c2d66c6541a8eca47e87920a0a70a0d457c570
|
4
|
+
data.tar.gz: 750acd291ddef8c6b792368a6c5531f0f9616ad2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35f6c10d408630bcc2e81210091c5926e84db14cf45f5317327a944948da28714b9cdf4405ab6f1b47e70a67ca1145ad1d0ecb0003c33c3a6d88bb5ba79be807
|
7
|
+
data.tar.gz: bdd0d00d9b258c4c91ffbebd60697e1445e1ae791cdf2803117f43f575d714d5c347315fc070a3116809881d803a0b39e512d2b04ce886a310603f0282e48ea1
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
.conjurrc
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
.yardoc
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
coverage
|
11
|
+
doc/
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
*.bundle
|
20
|
+
*.so
|
21
|
+
*.o
|
22
|
+
*.a
|
23
|
+
mkmf.log
|
data/.project
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>conjur-asset-host-factory</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>com.aptana.ide.core.unifiedBuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>com.aptana.ruby.core.rubynature</nature>
|
16
|
+
<nature>com.aptana.projects.webnature</nature>
|
17
|
+
</natures>
|
18
|
+
</projectDescription>
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kevin Gilpin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Conjur::Asset::HostFactory
|
2
|
+
|
3
|
+
API and CLI interface to the Conjur host factory.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'conjur-asset-host-factory'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install conjur-asset-host-factory
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/conjur-asset-host-factory/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'ci/reporter/rake/rspec'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new :spec
|
7
|
+
|
8
|
+
task :jenkins => ['ci:setup:rspec', :spec] do
|
9
|
+
File.write('build_number', ENV['BUILD_NUMBER']) if ENV['BUILD_NUMBER']
|
10
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'conjur-asset-host-factory-version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "conjur-asset-host-factory"
|
8
|
+
spec.version = Conjur::Asset::HostFactory::VERSION
|
9
|
+
spec.authors = ["Kevin Gilpin"]
|
10
|
+
spec.email = ["kgilpin@gmail.com"]
|
11
|
+
spec.summary = %q{Conjur asset plugin for the host factory}
|
12
|
+
spec.homepage = "https://github.com/conjurinc/conjur-asset-host-factory"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "conjur-api", '>= 4.9.2'
|
21
|
+
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "= 2.14.1"
|
24
|
+
spec.add_development_dependency 'ci_reporter', '~> 1.8'
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Conjur Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
module Conjur
|
22
|
+
module Asset
|
23
|
+
module HostFactory
|
24
|
+
VERSION = "1.0.0"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Conjur Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'conjur-asset-host-factory-version'
|
22
|
+
require 'conjur/host-factory-api'
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Conjur Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'conjur/host_factory'
|
22
|
+
|
23
|
+
module Conjur
|
24
|
+
class API
|
25
|
+
# Options:
|
26
|
+
# +layers+ list of host factory layers
|
27
|
+
# +roleid+ host factory role
|
28
|
+
def create_host_factory(id, options = {})
|
29
|
+
if options[:layers]
|
30
|
+
options[:layers] = options[:layers].map do |layer|
|
31
|
+
if layer.is_a?(Conjur::Layer)
|
32
|
+
layer.resourceid
|
33
|
+
elsif layer.is_a?(String)
|
34
|
+
layer
|
35
|
+
else
|
36
|
+
raise "Can't interpret layer #{layer}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
log do |logger|
|
41
|
+
logger << "Creating host_factory #{id}"
|
42
|
+
unless options.blank?
|
43
|
+
logger << " with options #{options.inspect}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
options ||= {}
|
47
|
+
options[:id] = id
|
48
|
+
resp = RestClient::Resource.new(Conjur::API.host_factory_asset_host, credentials).post(options)
|
49
|
+
Conjur::HostFactory.build_from_response(resp, credentials)
|
50
|
+
end
|
51
|
+
|
52
|
+
def host_factory id
|
53
|
+
Conjur::HostFactory.new(Conjur::API.host_factory_asset_host, credentials)[fully_escape(id)]
|
54
|
+
end
|
55
|
+
|
56
|
+
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)
|
63
|
+
Conjur::Host.new(Conjur::API.core_asset_host, credentials)["hosts"][fully_escape attributes['id']].tap do |host|
|
64
|
+
host.attributes = attributes
|
65
|
+
end
|
66
|
+
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
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Conjur Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
|
22
|
+
class Conjur::Command::HostFactories < Conjur::Command
|
23
|
+
desc "Manage host factories"
|
24
|
+
|
25
|
+
command :hostfactory do |hf|
|
26
|
+
hf.desc "Create a new host factory"
|
27
|
+
hf.arg_name "id"
|
28
|
+
hf.command :create do |c|
|
29
|
+
acting_as_option(c)
|
30
|
+
|
31
|
+
c.arg_name "layer"
|
32
|
+
c.desc "A space-delimited list of layers to which new hosts will belong"
|
33
|
+
c.flag [:l, :layer]
|
34
|
+
|
35
|
+
c.action do |global_options,options,args|
|
36
|
+
id = require_arg(args, 'hostfactory')
|
37
|
+
|
38
|
+
unless options[:ownerid]
|
39
|
+
exit_now! "Use --as-group or --as-role to indicate the host factory role"
|
40
|
+
end
|
41
|
+
|
42
|
+
layers = (options[:layer] || "").split(/\s/)
|
43
|
+
layers.each do |layer|
|
44
|
+
exit_now! "Layer '#{layer}' does not exist" unless api.layer(layer).exists?
|
45
|
+
end
|
46
|
+
|
47
|
+
command_options = options.dup
|
48
|
+
command_options[:layers] = layers
|
49
|
+
command_options[:roleid] = options[:ownerid]
|
50
|
+
|
51
|
+
host_factory = api.create_host_factory id, command_options
|
52
|
+
display host_factory
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
hf.desc "Show a host factory"
|
57
|
+
hf.arg_name "id"
|
58
|
+
hf.command :show do |c|
|
59
|
+
c.action do |global_options,options,args|
|
60
|
+
id = require_arg(args, 'id')
|
61
|
+
display(api.host_factory(id), options)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
hf.desc "List host factories"
|
66
|
+
hf.command :list do |c|
|
67
|
+
command_options_for_list c
|
68
|
+
c.action do |global_options, options, args|
|
69
|
+
command_impl_for_list global_options, options.merge(kind: "host_factory"), args
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
hf.desc "Operations on tokens"
|
74
|
+
hf.long_desc <<-DESC
|
75
|
+
This command creates one or more identical tokens. A token is always created with an
|
76
|
+
expiration time, which by default is 1 hour from now. The expiration time can be customized
|
77
|
+
with command arguments specifying the number of minutes, hours, days for which the token
|
78
|
+
will be valid.
|
79
|
+
|
80
|
+
By default, this command creates one token. Optionally, it can be used to create multiple identical tokens.
|
81
|
+
DESC
|
82
|
+
hf.command :tokens do |tokens|
|
83
|
+
|
84
|
+
tokens.desc "Create one or more tokens"
|
85
|
+
tokens.arg_name "hostfactory"
|
86
|
+
tokens.command :create do |c|
|
87
|
+
c.arg_name "duration in minutes"
|
88
|
+
c.desc "Number of minutes from now in which the token will expire"
|
89
|
+
c.flag [:"duration-minutes"]
|
90
|
+
|
91
|
+
c.arg_name "duration in hours"
|
92
|
+
c.desc "Number of hours from now in which the token will expire"
|
93
|
+
c.flag [:"duration-hours"]
|
94
|
+
|
95
|
+
c.arg_name "duration in days"
|
96
|
+
c.desc "Number of days from now in which the token will expire"
|
97
|
+
c.flag [:"duration-days"]
|
98
|
+
|
99
|
+
c.arg_name "count"
|
100
|
+
c.desc "Number of identical tokens to create"
|
101
|
+
c.flag [:c, :count]
|
102
|
+
|
103
|
+
c.action do |global_options,options,args|
|
104
|
+
id = require_arg(args, 'hostfactory')
|
105
|
+
|
106
|
+
duration = 0
|
107
|
+
%w(duration-minutes duration-hours duration-days).each do |d|
|
108
|
+
if t = options[d.to_sym]
|
109
|
+
duration += t.to_i.send(d.split('-')[-1])
|
110
|
+
end
|
111
|
+
end
|
112
|
+
if duration == 0
|
113
|
+
duration = 1.hour
|
114
|
+
end
|
115
|
+
expiration = Time.now + duration
|
116
|
+
count = (options[:count] || 1).to_i
|
117
|
+
command_options = {}
|
118
|
+
command_options[:max_uses] = options[:"max-uses"].to_i if options[:"max-uses"]
|
119
|
+
|
120
|
+
tokens = api.host_factory(id).create_tokens expiration, count, command_options
|
121
|
+
display tokens.map(&:to_json)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
tokens.desc "Revoke (delete) a token"
|
126
|
+
tokens.arg_name "token"
|
127
|
+
tokens.command :revoke do |c|
|
128
|
+
c.action do |global_options,options,args|
|
129
|
+
token = require_arg(args, 'token')
|
130
|
+
|
131
|
+
api.revoke_host_factory_token token
|
132
|
+
puts "Token revoked"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
hf.desc "Operations on hosts"
|
138
|
+
hf.command :hosts do |hosts|
|
139
|
+
hosts.desc "Use a token to create a host"
|
140
|
+
hosts.arg_name "token host-id"
|
141
|
+
hosts.command :create do |c|
|
142
|
+
c.action do |global_options,options,args|
|
143
|
+
token = require_arg(args, 'token')
|
144
|
+
id = require_arg(args, 'host-id')
|
145
|
+
|
146
|
+
host = api.host_factory_create_host token, id, options
|
147
|
+
display host
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Conjur Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'conjur/api'
|
22
|
+
require 'conjur/configuration'
|
23
|
+
|
24
|
+
class Conjur::Configuration
|
25
|
+
add_option :host_factory_url do
|
26
|
+
account_service_url 'host_factories', 500
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Conjur::API
|
31
|
+
class << self
|
32
|
+
def host_factory_asset_host
|
33
|
+
Conjur.configuration.host_factory_url
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
require 'conjur/api/host_factories'
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Conjur Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'conjur/host_factory_token'
|
22
|
+
|
23
|
+
module Conjur
|
24
|
+
class HostFactory < RestClient::Resource
|
25
|
+
include ActsAsAsset
|
26
|
+
|
27
|
+
def roleid
|
28
|
+
attributes['roleid']
|
29
|
+
end
|
30
|
+
|
31
|
+
def role
|
32
|
+
Role.new(Conjur::Authz::API.host, self.options)[Conjur::API.parse_role_id(roleid).join('/')]
|
33
|
+
end
|
34
|
+
|
35
|
+
def deputy
|
36
|
+
Conjur::Deputy.new(Conjur::API.core_asset_host, options)["deputies/#{fully_escape id}"]
|
37
|
+
end
|
38
|
+
|
39
|
+
def deputy_api_key
|
40
|
+
attributes['deputy_api_key']
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_token(expiration, options = {})
|
44
|
+
create_tokens(expiration, 1, options)[0]
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_tokens(expiration, count, options = {})
|
48
|
+
parameters = options.merge({
|
49
|
+
expiration: expiration.iso8601,
|
50
|
+
count: count
|
51
|
+
})
|
52
|
+
response = RestClient::Resource.new(Conjur::API.host_factory_asset_host, self.options)[fully_escape id]["tokens"].post(parameters).body
|
53
|
+
JSON.parse(response).map do |attrs|
|
54
|
+
build_host_factory_token attrs
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def tokens
|
59
|
+
# Tokens list is not returned by +show+ if the caller doesn't have permission
|
60
|
+
return nil unless self.attributes['tokens']
|
61
|
+
|
62
|
+
self.attributes['tokens'].collect do |attrs|
|
63
|
+
build_host_factory_token attrs
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
def build_host_factory_token attrs
|
70
|
+
Conjur::HostFactoryToken.new(Conjur::API.host_factory_asset_host, self.options)["tokens"][attrs['token']].tap do |token|
|
71
|
+
token.attributes = attrs
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Conjur Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
module Conjur
|
22
|
+
class HostFactoryToken < RestClient::Resource
|
23
|
+
include HasAttributes
|
24
|
+
|
25
|
+
def to_json(options = {})
|
26
|
+
{ token: token, expiration: expiration }.tap do |h|
|
27
|
+
h[:max_uses] = max_uses if max_uses
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def token
|
32
|
+
self.url.split('/')[-1]
|
33
|
+
end
|
34
|
+
|
35
|
+
alias id token
|
36
|
+
|
37
|
+
def expiration
|
38
|
+
DateTime.iso8601(attributes['expiration'])
|
39
|
+
end
|
40
|
+
|
41
|
+
def max_uses
|
42
|
+
attributes['max_uses']
|
43
|
+
end
|
44
|
+
|
45
|
+
def host_factory
|
46
|
+
Conjur::HostFactory.new(Conjur::API.host_factory_asset_host, options)[fully_escape attributes['host_factory_id']]
|
47
|
+
end
|
48
|
+
|
49
|
+
def revoke!
|
50
|
+
invalidate do
|
51
|
+
RestClient::Resource.new(self['revoke'].url, options).post
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def save
|
56
|
+
raise "HostFactoryToken attributes are not updatable"
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
|
61
|
+
def fetch
|
62
|
+
raise "HostFactoryToken attributes are not fetchable"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/.keepme
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# keep me
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: conjur-asset-host-factory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Gilpin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: conjur-api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.9.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.9.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.14.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ci_reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.8'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- kgilpin@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .project
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- conjur-asset-host-factory.gemspec
|
83
|
+
- lib/conjur-asset-host-factory-version.rb
|
84
|
+
- lib/conjur-asset-host-factory.rb
|
85
|
+
- lib/conjur/api/host_factories.rb
|
86
|
+
- lib/conjur/command/host_factories.rb
|
87
|
+
- lib/conjur/host-factory-api.rb
|
88
|
+
- lib/conjur/host_factory.rb
|
89
|
+
- lib/conjur/host_factory_token.rb
|
90
|
+
- spec/.keepme
|
91
|
+
homepage: https://github.com/conjurinc/conjur-asset-host-factory
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Conjur asset plugin for the host factory
|
115
|
+
test_files:
|
116
|
+
- spec/.keepme
|
117
|
+
has_rdoc:
|