conjur-cli 2.4.1 → 2.6.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.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Rafał Rzepecki
1
+ Copyright (c) 2012 Conjur Inc
2
2
 
3
3
  MIT License
4
4
 
data/conjur.gemspec CHANGED
@@ -3,9 +3,10 @@ require File.expand_path('../lib/conjur/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Rafa\305\202 Rzepecki", "Kevin Gilpin"]
6
- gem.email = ["divided.mind@gmail.com", "kevin.gilpin@inscitiv.com",]
6
+ gem.email = ["divided.mind@gmail.com", "kgilpin@conjur.net",]
7
7
  gem.summary = %q{Conjur command line interface}
8
8
  gem.homepage = "https://github.com/inscitiv/cli-ruby"
9
+ gem.license = 'MIT'
9
10
 
10
11
  gem.files = `git ls-files`.split($\) + Dir['build_number']
11
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -5,7 +5,7 @@ class Conjur::Command::Hosts < Conjur::Command
5
5
  self.prefix = :host
6
6
 
7
7
  desc "Create a new host"
8
- arg_name "host"
8
+ arg_name "id?"
9
9
  command :create do |c|
10
10
  c.arg_name "password"
11
11
  c.flag [:p,:password]
@@ -70,17 +70,29 @@ class Conjur::Command::Resources < Conjur::Command
70
70
  puts "Permission revoked"
71
71
  end
72
72
  end
73
-
74
- desc "Check whether a role has a privilege on a resource"
75
- arg_name "kind resource-id role privilege"
73
+
74
+ desc "Check for a privilege on a resource"
75
+ long_desc """
76
+ By default, the privilege is checked for the logged-in user.
77
+ Permission checks may be performed for other roles using the optional role argument.
78
+ When the role argument is used, either the logged-in user must either own the specified
79
+ resource or be an admin of the specified role (i.e. be granted the specified role with grant option).
80
+ """
81
+ arg_name "kind resource-id privilege"
76
82
  command :check do |c|
83
+ c.desc "Role to check. By default, the current logged-in role is used"
84
+ c.flag [:r,:role]
85
+
77
86
  c.action do |global_options,options,args|
78
87
  kind = args.shift or raise "Missing parameter: resource-kind"
79
88
  resource_id = args.shift or raise "Missing parameter: resource-id"
80
- role = args.shift or raise "Missing parameter: role"
81
89
  privilege = args.shift or raise "Missing parameter: privilege"
82
- role = api.role(role)
83
- puts role.permitted? kind, resource_id, privilege
90
+ if role = options[:role]
91
+ role = api.role(role)
92
+ puts role.permitted? kind, resource_id, privilege
93
+ else
94
+ puts api.resource([ conjur_account, kind, resource_id ].join(':')).permitted? privilege
95
+ end
84
96
  end
85
97
  end
86
98
 
@@ -92,11 +104,11 @@ class Conjur::Command::Resources < Conjur::Command
92
104
  id = require_arg(args, "resource-id")
93
105
  owner = require_arg(args, "owner")
94
106
  api.resource([ conjur_account, kind, id ].join(':')).give_to owner
95
- puts "Role granted"
107
+ puts "Ownership granted"
96
108
  end
97
109
  end
98
110
 
99
- desc "List roles with a specified permission on the resource"
111
+ desc "List roles with a specified permission on a resource"
100
112
  arg_name "kind resource-id permission"
101
113
  command :permitted_roles do |c|
102
114
  c.action do |global_options,options,args|
@@ -5,6 +5,7 @@ class Conjur::Command::Variables < Conjur::Command
5
5
  self.prefix = :variable
6
6
 
7
7
  desc "Create and store a variable"
8
+ arg_name "id?"
8
9
  command :create do |c|
9
10
  c.arg_name "mime_type"
10
11
  c.flag [:m, :"mime-type"]
@@ -15,7 +16,16 @@ class Conjur::Command::Variables < Conjur::Command
15
16
  acting_as_option(c)
16
17
 
17
18
  c.action do |global_options,options,args|
18
- var = api.create_variable(options[:m], options[:k], options)
19
+ id = args.shift
20
+ options[:id] = id if id
21
+
22
+ mime_type = options.delete(:m)
23
+ kind = options.delete(:k)
24
+
25
+ options.delete(:"mime-type")
26
+ options.delete(:"kind")
27
+
28
+ var = api.create_variable(mime_type, kind, options)
19
29
  display(var, options)
20
30
  end
21
31
  end
@@ -37,6 +47,7 @@ class Conjur::Command::Variables < Conjur::Command
37
47
  value = args.shift || STDIN.read
38
48
 
39
49
  api.variable(id).add_value(value)
50
+ puts "Value added"
40
51
  end
41
52
  end
42
53
 
@@ -1,3 +1,3 @@
1
1
  module Conjur
2
- VERSION = "2.4.1"
2
+ VERSION = "2.6.0"
3
3
  end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conjur::Command::Hosts, logged_in: true do
4
+ let(:collection_url) { "https://core.example.com/hosts" }
5
+
6
+ describe_command "host:create" do
7
+ it "lets the server assign the id" do
8
+ RestClient::Request.should_receive(:execute).with(
9
+ method: :post,
10
+ url: collection_url,
11
+ headers: {},
12
+ payload: {}
13
+ ).and_return(post_response('assigned-id'))
14
+
15
+ expect { invoke }.to write({ id: 'assigned-id' }).to(:stdout)
16
+ end
17
+ end
18
+ describe_command "host:create the-id" do
19
+ it "propagates the user-assigned id" do
20
+ RestClient::Request.should_receive(:execute).with(
21
+ method: :post,
22
+ url: collection_url,
23
+ headers: {},
24
+ payload: { id: 'the-id' }
25
+ ).and_return(post_response('the-id'))
26
+
27
+ expect { invoke }.to write({ id: 'the-id' }).to(:stdout)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conjur::Command::Resources, logged_in: true do
4
+
5
+ describe_command "resource:check food bacon fry" do
6
+ it "performs a permission check for the logged-in user" do
7
+ api.should_receive(:resource).with("the-account:food:bacon").and_return bacon = double("the-account:food:bacon")
8
+ bacon.should_receive(:permitted?).with("fry")
9
+
10
+ invoke
11
+ end
12
+ end
13
+
14
+ describe_command "resource:check -r test:the-role food bacon fry" do
15
+ it "performs a permission check for a specified role" do
16
+ api.should_receive(:role).with("test:the-role").and_return role = double("the-account:test:the-role")
17
+
18
+ role.should_receive(:permitted?).with("food", "bacon", "fry")
19
+
20
+ invoke
21
+ end
22
+ end
23
+ end
@@ -30,7 +30,7 @@ describe Conjur::Command::Roles, logged_in: true do
30
30
  end
31
31
  end
32
32
  end
33
-
33
+
34
34
  describe "role:memberships" do
35
35
  let(:all_roles) { %w(foo:user:joerandom foo:something:cool foo:something:else foo:group:admins) }
36
36
  let(:role) do
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conjur::Command::Variables, logged_in: true do
4
+ let(:collection_url) { "https://core.example.com/variables" }
5
+
6
+ let(:base_payload) { { mime_type: 'text/plain', kind: 'password' } }
7
+
8
+ describe_command "variable:create -m text/plain -k password" do
9
+ it "lets the server assign the id" do
10
+ RestClient::Request.should_receive(:execute).with(
11
+ method: :post,
12
+ url: collection_url,
13
+ headers: {},
14
+ payload: base_payload
15
+ ).and_return(post_response('assigned-id'))
16
+
17
+ expect { invoke }.to write({ id: 'assigned-id' }).to(:stdout)
18
+ end
19
+ end
20
+ describe_command "variable:create -m text/plain -k password the-id" do
21
+ it "propagates the user-assigned id" do
22
+ RestClient::Request.should_receive(:execute).with(
23
+ method: :post,
24
+ url: collection_url,
25
+ headers: {},
26
+ payload: base_payload.merge({ id: 'the-id' })
27
+ ).and_return(post_response('the-id'))
28
+
29
+ expect { invoke }.to write({ id: 'the-id' }).to(:stdout)
30
+ end
31
+ end
32
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "rubygems"
2
2
  require "bundler/setup"
3
3
  require 'tempfile'
4
+ require 'ostruct'
4
5
 
5
6
  require "simplecov"
6
7
  SimpleCov.start
@@ -59,6 +60,16 @@ shared_context "when not logged in", logged_in: false do
59
60
  include_context "with mock authn"
60
61
  end
61
62
 
63
+
64
+ def post_response(id, attributes = {})
65
+ attributes[:id] = id
66
+
67
+ OpenStruct.new({
68
+ headers: { location: [ collection_url, id ].join('/') },
69
+ body: attributes.to_json
70
+ })
71
+ end
72
+
62
73
  require 'write_expectation'
63
74
 
64
75
  require 'conjur/cli'
@@ -25,6 +25,7 @@ RSpec::Matchers.define :write do |message|
25
25
  end
26
26
 
27
27
  case message
28
+ when Hash then output.include?(JSON.pretty_generate message)
28
29
  when String then output.include? message
29
30
  when Regexp then output.match message
30
31
  when nil then output
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conjur-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-07-16 00:00:00.000000000 Z
13
+ date: 2013-08-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: conjur-api
@@ -191,7 +191,7 @@ dependencies:
191
191
  description:
192
192
  email:
193
193
  - divided.mind@gmail.com
194
- - kevin.gilpin@inscitiv.com
194
+ - kgilpin@conjur.net
195
195
  executables:
196
196
  - conjur
197
197
  - jsonfield
@@ -229,11 +229,15 @@ files:
229
229
  - lib/conjur/version.rb
230
230
  - spec/command/authn_spec.rb
231
231
  - spec/command/groups_spec.rb
232
+ - spec/command/hosts_spec.rb
233
+ - spec/command/resources_spec.rb
232
234
  - spec/command/roles_spec.rb
235
+ - spec/command/variables_spec.rb
233
236
  - spec/spec_helper.rb
234
237
  - spec/write_expectation.rb
235
238
  homepage: https://github.com/inscitiv/cli-ruby
236
- licenses: []
239
+ licenses:
240
+ - MIT
237
241
  post_install_message:
238
242
  rdoc_options: []
239
243
  require_paths:
@@ -246,7 +250,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
246
250
  version: '0'
247
251
  segments:
248
252
  - 0
249
- hash: -619613034249408123
253
+ hash: -4082547880357174583
250
254
  required_rubygems_version: !ruby/object:Gem::Requirement
251
255
  none: false
252
256
  requirements:
@@ -255,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
259
  version: '0'
256
260
  segments:
257
261
  - 0
258
- hash: -619613034249408123
262
+ hash: -4082547880357174583
259
263
  requirements: []
260
264
  rubyforge_project:
261
265
  rubygems_version: 1.8.25
@@ -267,6 +271,9 @@ test_files:
267
271
  - features/support/env.rb
268
272
  - spec/command/authn_spec.rb
269
273
  - spec/command/groups_spec.rb
274
+ - spec/command/hosts_spec.rb
275
+ - spec/command/resources_spec.rb
270
276
  - spec/command/roles_spec.rb
277
+ - spec/command/variables_spec.rb
271
278
  - spec/spec_helper.rb
272
279
  - spec/write_expectation.rb