conjur-cli 4.3.0 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 873f90a23b9e22be41441f80c9086f5c005137fe
4
+ data.tar.gz: 7c6d8a46e66a871415dc3085bc28ef6551c30289
5
+ SHA512:
6
+ metadata.gz: efe1fdb784cd353cbf45d0b60ab4744bc5bdd83c9ee333257e4ca0515b4e486426edd03645a125b349443729c241a18e42966adb773fd11b9ab533a9eab56a01
7
+ data.tar.gz: 5bec66f78fdccf45d679b2f58a8f4c7cec8e2a65d2bafe116b8e266832b9590fc6c50200278b806b22847664a41a53a03bdd601107bb9fc6a47f74630ac87664
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .conjurrc
1
2
  *.cert
2
3
  *.credential
3
4
  *.json
data/Gemfile CHANGED
@@ -4,3 +4,7 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'conjur-api', git: 'https://github.com/inscitiv/api-ruby.git', branch: 'master'
7
+
8
+ group :test, :development do
9
+ gem 'pry'
10
+ end
@@ -62,8 +62,6 @@ class MockAPI
62
62
  protected
63
63
 
64
64
  def create_thing(kind, id, options, kind_options = {})
65
- p kind, id, options, kind_options
66
-
67
65
  thing = OpenStruct.new(kind: kind, id: id, exists?: true)
68
66
 
69
67
  class << thing
@@ -83,7 +83,7 @@ module Conjur
83
83
  end
84
84
 
85
85
  if Conjur.log
86
- Conjur.log << "error: #{exception}\n#{exception.backtrace rescue 'NO BACKTRACE?'}"
86
+ Conjur.log << "error: #{exception}\n#{exception.backtrace.join("\n") rescue 'NO BACKTRACE?'}"
87
87
  end
88
88
  true
89
89
  end
@@ -0,0 +1,11 @@
1
+ module RSpec::Core::DSL
2
+ def describe_command *argv, &block
3
+ describe *argv do
4
+ let(:invoke) do
5
+ Conjur::CLI.error_device = $stderr
6
+ Conjur::CLI.run argv.first.split(' ')
7
+ end
8
+ instance_eval &block
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ require 'conjur/command/rspec/describe_command'
2
+ require 'conjur/command/rspec/output_matchers'
3
+ require 'conjur/command/rspec/mock_services'
@@ -0,0 +1,40 @@
1
+ shared_context "with fake endpoints and test config" do
2
+ let(:authn_host) { 'https://authn.example.com' }
3
+ let(:authz_host) { 'https://authz.example.com' }
4
+ let(:core_host) { 'https://core.example.com' }
5
+ before do
6
+ Conjur::Authn::API.stub host: authn_host
7
+ Conjur::Authz::API.stub host: authz_host
8
+ Conjur::Core::API.stub host: core_host
9
+
10
+ ENV['GLI_DEBUG'] = 'true'
11
+ end
12
+ end
13
+
14
+ shared_context "with mock authn" do
15
+ include_context "with fake endpoints and test config"
16
+ let(:netrcfile) { Tempfile.new 'authtest' }
17
+ let(:netrc) { Netrc.read(netrcfile.path) }
18
+ let(:account) { 'the-account' }
19
+ before do
20
+ Conjur::Core::API.stub conjur_account: account
21
+ Conjur::Authn.stub netrc: netrc, host: authn_host
22
+ Conjur::Config.merge 'account' => account
23
+ end
24
+ end
25
+
26
+ shared_context "when logged in", logged_in: true do
27
+ include_context "with mock authn"
28
+ let(:username) { 'dknuth' }
29
+ let(:api_key) { 'sekrit' }
30
+ let(:api) { Conjur::API.new_from_key(username, api_key) }
31
+ before do
32
+ api.stub credentials: {}
33
+ netrc[authn_host] = [username, api_key]
34
+ Conjur::Command.stub api: api
35
+ end
36
+ end
37
+
38
+ shared_context "when not logged in", logged_in: false do
39
+ include_context "with mock authn"
40
+ end
@@ -29,7 +29,7 @@ class Conjur::Command::Authn < Conjur::Command
29
29
  command :execute do |c|
30
30
  acting_as_option(c)
31
31
 
32
- c.desc "Load context from this config file; save it when finished"
32
+ c.desc "Load context from this config file, and save it when finished. The file permissions will be 0600 by default."
33
33
  c.arg_name "context"
34
34
  c.flag [:c, :context]
35
35
 
@@ -55,6 +55,7 @@ class Conjur::Command::Authn < Conjur::Command
55
55
 
56
56
  if options[:context]
57
57
  File.write(options[:context], JSON.pretty_generate(runner.context))
58
+ File.chmod(0600, options[:context])
58
59
  end
59
60
 
60
61
  puts JSON.pretty_generate(result)
@@ -28,10 +28,10 @@ class Conjur::Command::Variables < Conjur::Command
28
28
  arg_name "id?"
29
29
  command :create do |c|
30
30
  c.arg_name "mime_type"
31
- c.flag [:m, :"mime-type"]
31
+ c.flag [:m, :"mime-type"], default_value: "text/plain"
32
32
 
33
33
  c.arg_name "kind"
34
- c.flag [:k, :"kind"]
34
+ c.flag [:k, :"kind"], default_value: "secret"
35
35
 
36
36
  acting_as_option(c)
37
37
 
@@ -44,7 +44,7 @@ class Conjur::Command::Variables < Conjur::Command
44
44
 
45
45
  options.delete(:"mime-type")
46
46
  options.delete(:"kind")
47
-
47
+
48
48
  var = api.create_variable(mime_type, kind, options)
49
49
  display(var, options)
50
50
  end
@@ -82,4 +82,4 @@ class Conjur::Command::Variables < Conjur::Command
82
82
  $stdout.write api.variable(id).value(options[:version])
83
83
  end
84
84
  end
85
- end
85
+ end
@@ -18,6 +18,8 @@
18
18
  # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
+ require 'active_support/core_ext/hash/deep_merge'
22
+ require 'active_support/core_ext/hash/indifferent_access'
21
23
  module Conjur
22
24
  class Config
23
25
  @@attributes = {}
@@ -25,7 +27,7 @@ module Conjur
25
27
  class << self
26
28
  def load
27
29
  require 'yaml'
28
- [ File.join("/etc", "conjur.conf"), ( ENV['CONJURRC'] || File.join(ENV['HOME'], ".conjurrc") ) ].each do |f|
30
+ [ File.join("/etc", "conjur.conf"), ( ENV['CONJURRC'] || File.join(ENV['HOME'], ".conjurrc") ), '.conjurrc' ].each do |f|
29
31
  if File.exists?(f)
30
32
  if Conjur.log
31
33
  Conjur.log << "Loading #{f}\n"
@@ -36,13 +38,15 @@ module Conjur
36
38
  end
37
39
 
38
40
  def apply
39
- ENV['CONJUR_ENV'] = Config[:env] || "production"
40
- ENV['CONJUR_STACK'] = Config[:stack] if Config[:stack]
41
- ENV['CONJUR_STACK'] ||= 'v4' if ENV['CONJUR_ENV'] == 'production'
42
- ENV['CONJUR_ACCOUNT'] = Config[:account] or raise "Missing configuration setting: account. Please set it in ~/.conjurrc"
41
+ keys = Config.keys.dup
42
+ keys.delete(:plugins)
43
+ keys.each do |k|
44
+ value = Config[k]
45
+ Conjur.configuration.set k, value if value
46
+ end
43
47
 
44
48
  if Conjur.log
45
- Conjur.log << "Using host #{Conjur::Authn::API.host}\n"
49
+ Conjur.log << "Using authn host #{Conjur::Authn::API.host}\n"
46
50
  end
47
51
  end
48
52
 
@@ -61,7 +65,11 @@ module Conjur
61
65
 
62
66
  def merge(a)
63
67
  a = {} unless a
64
- @@attributes.merge!(a)
68
+ @@attributes.deep_merge!(a.stringify_keys)
69
+ end
70
+
71
+ def keys
72
+ @@attributes.keys.map(&:to_sym)
65
73
  end
66
74
 
67
75
  def [](key)
@@ -25,6 +25,12 @@ module Conjur
25
25
  @objects = Array.new
26
26
  end
27
27
 
28
+ # Provides a hash to export various application specific
29
+ # asset ids (or anything else you want)
30
+ def assets
31
+ @context['assets'] ||= {}
32
+ end
33
+
28
34
  def api
29
35
  @api ||= connect
30
36
  end
@@ -150,7 +156,7 @@ module Conjur
150
156
 
151
157
  def do_object obj, &block
152
158
  begin
153
- api_keys[obj.resourceid] = obj.api_key
159
+ api_keys[obj.resourceid] = obj.api_key if obj.api_key
154
160
  rescue
155
161
  end
156
162
 
@@ -19,5 +19,5 @@
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
21
  module Conjur
22
- VERSION = "4.3.0"
22
+ VERSION = "4.4.0"
23
23
  end
@@ -3,9 +3,9 @@ require 'spec_helper'
3
3
  describe Conjur::Command::Variables, logged_in: true do
4
4
  let(:collection_url) { "https://core.example.com/variables" }
5
5
 
6
- let(:base_payload) { { mime_type: 'text/plain', kind: 'password' } }
6
+ let(:base_payload) { { mime_type: 'text/json', kind: 'password' } }
7
7
 
8
- describe_command "variable:create -m text/plain -k password" do
8
+ describe_command "variable:create -m text/json -k password" do
9
9
  it "lets the server assign the id" do
10
10
  RestClient::Request.should_receive(:execute).with(
11
11
  method: :post,
@@ -17,7 +17,7 @@ describe Conjur::Command::Variables, logged_in: true do
17
17
  expect { invoke }.to write({ id: 'assigned-id' }).to(:stdout)
18
18
  end
19
19
  end
20
- describe_command "variable:create -m text/plain -k password the-id" do
20
+ describe_command "variable:create -m text/json -k password the-id" do
21
21
  it "propagates the user-assigned id" do
22
22
  RestClient::Request.should_receive(:execute).with(
23
23
  method: :post,
@@ -29,4 +29,20 @@ describe Conjur::Command::Variables, logged_in: true do
29
29
  expect { invoke }.to write({ id: 'the-id' }).to(:stdout)
30
30
  end
31
31
  end
32
- end
32
+
33
+
34
+ describe_command "variable:create" do
35
+ it "provides default values for optional parameters mime_type and kind" do
36
+ RestClient::Request.should_receive(:execute).with(
37
+ method: :post,
38
+ url: collection_url,
39
+ headers: {},
40
+ payload: { mime_type: 'text/plain', kind: 'secret'}
41
+ ).and_return(post_response('the-id'))
42
+ expect { invoke }.to write # invoke_silently
43
+ end
44
+ end
45
+
46
+
47
+
48
+ end
@@ -5,61 +5,6 @@ require 'ostruct'
5
5
 
6
6
  require "simplecov"
7
7
  SimpleCov.start
8
-
9
- module RSpec::Core::DSL
10
- def describe_command *argv, &block
11
- describe *argv do
12
- let(:invoke) do
13
- Conjur::CLI.error_device = $stderr
14
- Conjur::CLI.run argv.first.split(' ')
15
- end
16
- instance_eval &block
17
- end
18
- end
19
- end
20
-
21
- shared_context "with fake endpoints and test config" do
22
- let(:authn_host) { 'https://authn.example.com' }
23
- let(:authz_host) { 'https://authz.example.com' }
24
- let(:core_host) { 'https://core.example.com' }
25
- before do
26
- Conjur::Authn::API.stub host: authn_host
27
- Conjur::Authz::API.stub host: authz_host
28
- Conjur::Core::API.stub host: core_host
29
-
30
- ENV['GLI_DEBUG'] = 'true'
31
- end
32
- end
33
-
34
- shared_context "with mock authn" do
35
- include_context "with fake endpoints and test config"
36
- let(:netrcfile) { Tempfile.new 'authtest' }
37
- let(:netrc) { Netrc.read(netrcfile.path) }
38
- let(:account) { 'the-account' }
39
- before do
40
- Conjur::Core::API.stub conjur_account: account
41
- Conjur::Authn.stub netrc: netrc, host: authn_host
42
- Conjur::Config.merge 'account' => account
43
- end
44
-
45
- end
46
-
47
- shared_context "when logged in", logged_in: true do
48
- include_context "with mock authn"
49
- let(:username) { 'dknuth' }
50
- let(:api_key) { 'sekrit' }
51
- let(:api) { Conjur::API.new_from_key(username, api_key) }
52
- before do
53
- api.stub credentials: {}
54
- netrc[authn_host] = [username, api_key]
55
- Conjur::Command.stub api: api
56
- end
57
- end
58
-
59
- shared_context "when not logged in", logged_in: false do
60
- include_context "with mock authn"
61
- end
62
-
63
8
 
64
9
  def post_response(id, attributes = {})
65
10
  attributes[:id] = id
@@ -79,7 +24,7 @@ PRIVILEGE='<privilege>'
79
24
  OWNER='<owner/userid>'
80
25
  ACCOUNT='<core_account>'
81
26
 
82
- require 'write_expectation'
27
+ require 'conjur/command/rspec/helpers'
83
28
 
84
29
  ENV['CONJURRC'] = '/dev/null'
85
30
 
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conjur-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
5
- prerelease:
4
+ version: 4.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rafał Rzepecki
@@ -10,172 +9,151 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-11-19 00:00:00.000000000 Z
12
+ date: 2013-12-24 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: conjur-api
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: '4.0'
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: '4.0'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: gli
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: highline
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - '>='
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  type: :runtime
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - '>='
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: netrc
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - '>='
69
61
  - !ruby/object:Gem::Version
70
62
  version: '0'
71
63
  type: :runtime
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - '>='
77
68
  - !ruby/object:Gem::Version
78
69
  version: '0'
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: methadone
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ! '>='
74
+ - - '>='
85
75
  - !ruby/object:Gem::Version
86
76
  version: '0'
87
77
  type: :runtime
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ! '>='
81
+ - - '>='
93
82
  - !ruby/object:Gem::Version
94
83
  version: '0'
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: deep_merge
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
- - - ! '>='
88
+ - - '>='
101
89
  - !ruby/object:Gem::Version
102
90
  version: '0'
103
91
  type: :runtime
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
- - - ! '>='
95
+ - - '>='
109
96
  - !ruby/object:Gem::Version
110
97
  version: '0'
111
98
  - !ruby/object:Gem::Dependency
112
99
  name: cas_rest_client
113
100
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
101
  requirements:
116
- - - ! '>='
102
+ - - '>='
117
103
  - !ruby/object:Gem::Version
118
104
  version: '0'
119
105
  type: :runtime
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
108
  requirements:
124
- - - ! '>='
109
+ - - '>='
125
110
  - !ruby/object:Gem::Version
126
111
  version: '0'
127
112
  - !ruby/object:Gem::Dependency
128
113
  name: rspec
129
114
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
115
  requirements:
132
- - - ! '>='
116
+ - - '>='
133
117
  - !ruby/object:Gem::Version
134
118
  version: '0'
135
119
  type: :development
136
120
  prerelease: false
137
121
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
122
  requirements:
140
- - - ! '>='
123
+ - - '>='
141
124
  - !ruby/object:Gem::Version
142
125
  version: '0'
143
126
  - !ruby/object:Gem::Dependency
144
127
  name: simplecov
145
128
  requirement: !ruby/object:Gem::Requirement
146
- none: false
147
129
  requirements:
148
- - - ! '>='
130
+ - - '>='
149
131
  - !ruby/object:Gem::Version
150
132
  version: '0'
151
133
  type: :development
152
134
  prerelease: false
153
135
  version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
136
  requirements:
156
- - - ! '>='
137
+ - - '>='
157
138
  - !ruby/object:Gem::Version
158
139
  version: '0'
159
140
  - !ruby/object:Gem::Dependency
160
141
  name: aruba
161
142
  requirement: !ruby/object:Gem::Requirement
162
- none: false
163
143
  requirements:
164
- - - ! '>='
144
+ - - '>='
165
145
  - !ruby/object:Gem::Version
166
146
  version: '0'
167
147
  type: :development
168
148
  prerelease: false
169
149
  version_requirements: !ruby/object:Gem::Requirement
170
- none: false
171
150
  requirements:
172
- - - ! '>='
151
+ - - '>='
173
152
  - !ruby/object:Gem::Version
174
153
  version: '0'
175
154
  - !ruby/object:Gem::Dependency
176
155
  name: ci_reporter
177
156
  requirement: !ruby/object:Gem::Requirement
178
- none: false
179
157
  requirements:
180
158
  - - ~>
181
159
  - !ruby/object:Gem::Version
@@ -183,7 +161,6 @@ dependencies:
183
161
  type: :development
184
162
  prerelease: false
185
163
  version_requirements: !ruby/object:Gem::Requirement
186
- none: false
187
164
  requirements:
188
165
  - - ~>
189
166
  - !ruby/object:Gem::Version
@@ -191,7 +168,6 @@ dependencies:
191
168
  - !ruby/object:Gem::Dependency
192
169
  name: rake
193
170
  requirement: !ruby/object:Gem::Requirement
194
- none: false
195
171
  requirements:
196
172
  - - ~>
197
173
  - !ruby/object:Gem::Version
@@ -199,7 +175,6 @@ dependencies:
199
175
  type: :development
200
176
  prerelease: false
201
177
  version_requirements: !ruby/object:Gem::Requirement
202
- none: false
203
178
  requirements:
204
179
  - - ~>
205
180
  - !ruby/object:Gem::Version
@@ -249,6 +224,10 @@ files:
249
224
  - lib/conjur/command/ids.rb
250
225
  - lib/conjur/command/resources.rb
251
226
  - lib/conjur/command/roles.rb
227
+ - lib/conjur/command/rspec/describe_command.rb
228
+ - lib/conjur/command/rspec/helpers.rb
229
+ - lib/conjur/command/rspec/mock_services.rb
230
+ - lib/conjur/command/rspec/output_matchers.rb
252
231
  - lib/conjur/command/script.rb
253
232
  - lib/conjur/command/secrets.rb
254
233
  - lib/conjur/command/users.rb
@@ -268,38 +247,30 @@ files:
268
247
  - spec/command/variables_spec.rb
269
248
  - spec/command_spec.rb
270
249
  - spec/spec_helper.rb
271
- - spec/write_expectation.rb
272
250
  - update_ci.sh
273
251
  homepage: https://github.com/inscitiv/cli-ruby
274
252
  licenses:
275
253
  - MIT
254
+ metadata: {}
276
255
  post_install_message:
277
256
  rdoc_options: []
278
257
  require_paths:
279
258
  - lib
280
259
  required_ruby_version: !ruby/object:Gem::Requirement
281
- none: false
282
260
  requirements:
283
- - - ! '>='
261
+ - - '>='
284
262
  - !ruby/object:Gem::Version
285
263
  version: '0'
286
- segments:
287
- - 0
288
- hash: -1644875280166095669
289
264
  required_rubygems_version: !ruby/object:Gem::Requirement
290
- none: false
291
265
  requirements:
292
- - - ! '>='
266
+ - - '>='
293
267
  - !ruby/object:Gem::Version
294
268
  version: '0'
295
- segments:
296
- - 0
297
- hash: -1644875280166095669
298
269
  requirements: []
299
270
  rubyforge_project:
300
- rubygems_version: 1.8.25
271
+ rubygems_version: 2.0.3
301
272
  signing_key:
302
- specification_version: 3
273
+ specification_version: 4
303
274
  summary: Conjur command line interface
304
275
  test_files:
305
276
  - features/dsl_context.feature
@@ -324,4 +295,3 @@ test_files:
324
295
  - spec/command/variables_spec.rb
325
296
  - spec/command_spec.rb
326
297
  - spec/spec_helper.rb
327
- - spec/write_expectation.rb