conjur-cli 4.14.0 → 4.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YzdkNTU4NDk0N2QyMmNiOWJkMDA3MzZkZmNhMTg2NjZiNTQzZTMwYw==
5
- data.tar.gz: !binary |-
6
- ODE1ODg4ZGMyZGYzYTBiYTNmNzMzMWZlNjUwYjdjZjc4NDZjYWJkOA==
2
+ SHA1:
3
+ metadata.gz: 9a7286b596f4e9bfdcac76be7e5d79b813aa2a52
4
+ data.tar.gz: 6e4d13583b0c704139bcfcea5cc4e6fa1a8a3335
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NzE2OGU2MWI2NTI4ZjQyZjBmMDQyOTQ2ZDM5OTY1YTBjNWY2MmJjMDQ0ZTNj
10
- MmM2ZjkzMjRmMTZkN2UxZjc3MmM5NTAxNjg4ZjE4YjE5Y2NiMTA4ZDI2OGQy
11
- YTgxZWJiZjZjZjBlMDVhZjM2OWZiOTMyYTYzMzY4MTA2YjhmYWM=
12
- data.tar.gz: !binary |-
13
- NjlhMjllYzZjNDMwOTdmYjg0Nzc4MGU1ZWY0ZTg3Y2JiN2EyMmJkNWMzYmIx
14
- YWY5Y2U0NmE3NmJmNGYyYTRhMzdlODk1ODZkN2YzYjJiZTBmMWU5Zjg2MWFh
15
- NGI3NGQ2NjU3NDBmY2NiYWY0NTAzMWU0ZDM3MjZiZDY5NGI3YTk=
6
+ metadata.gz: 88490f66539ca80f3456abd2331763ff23b01ba62c35b389a446ab0d92d0a2a193478342d1dd27a7ea95af36a1777bb70d39c299d9bb30212ca4b56d180c8194
7
+ data.tar.gz: 9aa6c11cda54ecb915470c0c9a8915f84ad8bcc9c8664e25364dfa90da8dd2cf7a44b10862b222a986f8b8584c4526a49bf38f5162aa581ed3198104ca55963b
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # 4.15.0
2
+
3
+ * Migration to rspec 3
4
+ * Commands to retire(decommission) variable, host, user, group
5
+ * Bugfix (in some situations `conjur init` logged config file location incorrectly)
@@ -87,6 +87,8 @@
87
87
  :show: true
88
88
  :list: true
89
89
  :update_password: true
90
+ :update: true
91
+ :uidsearch: true
90
92
  :variable:
91
93
  :create: true
92
94
  :show: true
data/conjur.gemspec CHANGED
@@ -26,9 +26,11 @@ Gem::Specification.new do |gem|
26
26
 
27
27
  gem.add_runtime_dependency 'cas_rest_client'
28
28
 
29
- gem.add_development_dependency 'rspec', '>= 2.14', '< 3.0'
29
+ gem.add_development_dependency 'rspec', '~> 3.0'
30
30
  gem.add_development_dependency 'simplecov'
31
31
  gem.add_development_dependency 'aruba'
32
- gem.add_development_dependency 'ci_reporter', '~> 1.8'
32
+ gem.add_development_dependency 'ci_reporter_rspec', '~> 1.0'
33
+ gem.add_development_dependency 'ci_reporter_cucumber'
33
34
  gem.add_development_dependency 'rake', '~> 10.0'
35
+ gem.add_development_dependency 'io-grab', '~> 0.0.1'
34
36
  end
@@ -41,6 +41,6 @@ end
41
41
 
42
42
  Then(/^the context "(.*?)" should contain "(.*?)" item$/) do |key, key_count|
43
43
  step "the context should contain \"#{key}\""
44
- @runner.context[key].should have(key_count.to_i).items
44
+ expect(@runner.context[key].length).to eq key_count.to_i
45
45
  end
46
46
 
@@ -99,7 +99,24 @@ module Conjur
99
99
  puts JSON.pretty_generate resources
100
100
  end
101
101
  end
102
+
103
+ def retire_resource obj
104
+ obj.resource.attributes['permissions'].each do |p|
105
+ role = api.role(p['role'])
106
+ privilege = p['privilege']
107
+ next if role.roleid == obj.roleid && privilege == 'read'
108
+ puts "Denying #{privilege} privilege to #{role.roleid}"
109
+ obj.resource.deny(privilege, role)
110
+ end
111
+ end
102
112
 
113
+ def retire_role obj
114
+ obj.role.members.each do |r|
115
+ member = api.role(r.member)
116
+ puts "Revoking from role #{member.roleid}"
117
+ obj.role.revoke_from member
118
+ end
119
+ end
103
120
 
104
121
  def display_members(members, options)
105
122
  result = if options[:V]
@@ -59,6 +59,24 @@ class Conjur::Command::Groups < Conjur::Command
59
59
  display(api.group(id), options)
60
60
  end
61
61
  end
62
+
63
+ group.desc "Decommission a group"
64
+ group.arg_name "id"
65
+ group.command :retire do |c|
66
+ c.action do |global_options,options,args|
67
+ id = require_arg(args, 'id')
68
+
69
+ group = api.group(id)
70
+
71
+ retire_resource group
72
+ retire_role group
73
+
74
+ puts "Giving ownership to 'attic'"
75
+ group.resource.give_to api.user('attic')
76
+
77
+ puts "Group retired"
78
+ end
79
+ end
62
80
 
63
81
  group.desc "Show and manage group members"
64
82
  group.command :members do |members|
@@ -20,6 +20,10 @@
20
20
  #
21
21
 
22
22
  class Conjur::Command::Hosts < Conjur::Command
23
+ def self.host_layer_roles host
24
+ host.role.all.select{|r| r.kind == "layer"}
25
+ end
26
+
23
27
  desc "Manage hosts"
24
28
  command :host do |hosts|
25
29
  hosts.desc "Create a new host"
@@ -51,7 +55,28 @@ class Conjur::Command::Hosts < Conjur::Command
51
55
  end
52
56
  end
53
57
 
58
+ hosts.desc "Decommission a host"
59
+ hosts.arg_name "id"
60
+ hosts.command :retire do |c|
61
+ c.action do |global_options,options,args|
62
+ id = require_arg(args, 'id')
63
+
64
+ host = api.host(id)
65
+
66
+ host_layer_roles(host).each do |layer|
67
+ puts "Removing from layer #{layer.id}"
68
+ api.layer(layer.id).remove_host host
69
+ end
54
70
 
71
+ retire_resource host
72
+ retire_role host
73
+
74
+ puts "Giving ownership to 'attic'"
75
+ host.resource.give_to api.user('attic')
76
+
77
+ puts "Host retired"
78
+ end
79
+ end
55
80
 
56
81
  hosts.desc "List hosts"
57
82
  hosts.command :list do |c|
@@ -78,7 +103,8 @@ class Conjur::Command::Hosts < Conjur::Command
78
103
  hosts.command :layers do |c|
79
104
  c.action do |global_options, options, args|
80
105
  id = require_arg(args, 'id')
81
- display api.host(id).role.all.select{|r| r.kind == "layer"}.map(&:identifier), options
106
+ host = api.host(id)
107
+ display host_layer_roles(host).map(&:identifier), options
82
108
  end
83
109
  end
84
110
  end
@@ -121,7 +121,7 @@ class Conjur::Command::Init < Conjur::Command
121
121
  f.puts YAML.dump(config.stringify_keys)
122
122
  end
123
123
 
124
- puts "Wrote configuration to #{options[:file]}"
124
+ puts "Wrote configuration to #{config_file}"
125
125
  end
126
126
  end
127
127
 
@@ -1,4 +1,4 @@
1
- module RSpec::Core::DSL
1
+ RSpec::Core::DSL.change_global_dsl do
2
2
  def describe_command *argv, &block
3
3
  describe *argv do
4
4
  let(:invoke) do
@@ -3,9 +3,9 @@ shared_context "with fake endpoints and test config" do
3
3
  let(:authz_host) { 'https://authz.example.com' }
4
4
  let(:core_host) { 'https://core.example.com' }
5
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
6
+ allow(Conjur::Authn::API).to receive(:host) { authn_host }
7
+ allow(Conjur::Authz::API).to receive(:host) { authz_host }
8
+ allow(Conjur::Core::API).to receive(:host) { core_host }
9
9
 
10
10
  ENV['GLI_DEBUG'] = 'true'
11
11
  end
@@ -17,8 +17,8 @@ shared_context "with mock authn" do
17
17
  let(:netrc) { Netrc.read(netrcfile.path) }
18
18
  let(:account) { 'the-account' }
19
19
  before do
20
- Conjur::Core::API.stub conjur_account: account
21
- Conjur::Authn.stub netrc: netrc, host: authn_host
20
+ allow(Conjur::Core::API).to receive(:conjur_account) { account }
21
+ allow(Conjur::Authn).to receive_messages(netrc: netrc, host: authn_host)
22
22
  Conjur::Config.merge 'account' => account
23
23
  end
24
24
  end
@@ -29,9 +29,9 @@ shared_context "when logged in", logged_in: true do
29
29
  let(:api_key) { 'sekrit' }
30
30
  let(:api) { Conjur::API.new_from_key(username, api_key) }
31
31
  before do
32
- api.stub credentials: {}
32
+ allow(api).to receive(:credentials) { {} }
33
33
  netrc[authn_host] = [username, api_key]
34
- Conjur::Command.stub api: api
34
+ allow(Conjur::Command).to receive_messages api: api
35
35
  end
36
36
  end
37
37
 
@@ -1,6 +1,4 @@
1
- # from https://gist.github.com/elgalu/5073871
2
- require 'rspec'
3
- require 'stringio'
1
+ require 'io/grab'
4
2
 
5
3
  # Custom matcher to test text written to standard output and standard error
6
4
  #
@@ -12,17 +10,23 @@ require 'stringio'
12
10
  #
13
11
  # @note http://greyblake.com/blog/2012/12/14/custom-expectations-with-rspec/
14
12
  RSpec::Matchers.define :write do |message|
13
+ supports_block_expectations
14
+
15
15
  chain(:to) do |io|
16
16
  @io = io
17
17
  end
18
18
 
19
19
  match do |block|
20
- output =
21
- case io
22
- when :stdout then fake_stdout(&block)
23
- when :stderr then fake_stderr(&block)
24
- else fail("Allowed values for `to` are :stdout and :stderr, got `#{io.inspect}`")
25
- end
20
+ stream = case io
21
+ when :stdout
22
+ $stdout
23
+ when :stderr
24
+ $stderr
25
+ else
26
+ io
27
+ end
28
+
29
+ @actual = output = stream.grab &block
26
30
 
27
31
  case message
28
32
  when Hash then output.include?(JSON.pretty_generate message)
@@ -37,36 +41,10 @@ RSpec::Matchers.define :write do |message|
37
41
  %Q[write #{message.inspect} to #{@io}]
38
42
  end
39
43
 
40
- def failure_message(to = 'to')
41
- %Q[expected #{to} #{description} but got #{@buffer.inspect}]
42
- end
43
-
44
- failure_message_for_should do
45
- failure_message 'to'
46
- end
47
-
48
- failure_message_for_should_not do
49
- failure_message 'not to'
50
- end
51
-
52
- # Fake STDERR and return a string written to it.
53
- def fake_stderr
54
- original_stderr = $stderr
55
- $stderr = StringIO.new
56
- yield
57
- @buffer = $stderr.string
58
- ensure
59
- $stderr = original_stderr
60
- end
44
+ diffable
61
45
 
62
- # Fake STDOUT and return a string written to it.
63
- def fake_stdout
64
- original_stdout = $stdout
65
- $stdout = StringIO.new
66
- yield
67
- @buffer = $stdout.string
68
- ensure
69
- $stdout = original_stdout
46
+ failure_message do
47
+ %Q[expected to #{description} but got #{@actual.inspect}]
70
48
  end
71
49
 
72
50
  # default IO is standard output
@@ -74,6 +74,24 @@ class Conjur::Command::Users < Conjur::Command
74
74
  end
75
75
  end
76
76
 
77
+ user.desc "Decommission a user"
78
+ user.arg_name "id"
79
+ user.command :retire do |c|
80
+ c.action do |global_options,options,args|
81
+ id = require_arg(args, 'id')
82
+
83
+ user = api.user(id)
84
+
85
+ retire_resource user
86
+ retire_role user
87
+
88
+ puts "Giving ownership to 'attic'"
89
+ user.resource.give_to api.user('attic')
90
+
91
+ puts "User retired"
92
+ end
93
+ end
94
+
77
95
  user.desc "List users"
78
96
  user.command :list do |c|
79
97
  command_options_for_list c
@@ -65,6 +65,23 @@ class Conjur::Command::Variables < Conjur::Command
65
65
  end
66
66
  end
67
67
 
68
+ var.desc "Decommission a variable"
69
+ var.arg_name "id"
70
+ var.command :retire do |c|
71
+ c.action do |global_options,options,args|
72
+ id = require_arg(args, 'id')
73
+
74
+ variable = api.variable(id)
75
+
76
+ retire_resource variable
77
+
78
+ puts "Giving ownership to 'attic'"
79
+ variable.resource.give_to api.user('attic')
80
+
81
+ puts "Variable retired"
82
+ end
83
+ end
84
+
68
85
  var.desc "List variables"
69
86
  var.command :list do |c|
70
87
  command_options_for_list c
@@ -19,6 +19,6 @@
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
21
  module Conjur
22
- VERSION = "4.14.0"
22
+ VERSION = "4.15.0"
23
23
  ::Version=VERSION
24
24
  end
data/spec/authn_spec.rb CHANGED
@@ -5,24 +5,24 @@ describe Conjur::Authn do
5
5
  describe "credentials from environment" do
6
6
  before {
7
7
  Conjur::Authn.instance_variable_set("@credentials", nil)
8
- ENV.should_receive(:[]).with("CONJUR_AUTHN_LOGIN").and_return "the-login"
9
- ENV.should_receive(:[]).with("CONJUR_AUTHN_API_KEY").and_return "the-api-key"
8
+ expect(ENV).to receive(:[]).with("CONJUR_AUTHN_LOGIN").and_return "the-login"
9
+ expect(ENV).to receive(:[]).with("CONJUR_AUTHN_API_KEY").and_return "the-api-key"
10
10
  }
11
11
  after {
12
12
  Conjur::Authn.instance_variable_set("@credentials", nil)
13
13
  }
14
14
  it "are used to authn" do
15
- Conjur::Authn.get_credentials.should == [ "the-login", "the-api-key" ]
15
+ expect(Conjur::Authn.get_credentials).to eq([ "the-login", "the-api-key" ])
16
16
  end
17
17
  it "are not written to netrc" do
18
- Conjur::Authn.stub(:write_credentials).and_raise "should not write credentials"
18
+ allow(Conjur::Authn).to receive(:write_credentials).and_raise "should not write credentials"
19
19
  Conjur::Authn.get_credentials
20
20
  end
21
21
  end
22
22
  describe "netrc" do
23
23
  before {
24
24
  Conjur::Authn.instance_variable_set("@netrc", nil)
25
- Conjur::Config.should_receive(:[]).with(:netrc_path).and_return path
25
+ expect(Conjur::Config).to receive(:[]).with(:netrc_path).and_return path
26
26
  }
27
27
  after {
28
28
  Conjur::Authn.instance_variable_set("@netrc", nil)
@@ -30,15 +30,15 @@ describe Conjur::Authn do
30
30
  context "with specified netrc_path" do
31
31
  let(:path) { double("path") }
32
32
  it "consults Conjur::Config for netrc_path" do
33
- Netrc.should_receive(:read).with(path).and_return netrc = double("netrc")
34
- Conjur::Authn.netrc.should == netrc
33
+ expect(Netrc).to receive(:read).with(path).and_return netrc = double("netrc")
34
+ expect(Conjur::Authn.netrc).to eq(netrc)
35
35
  end
36
36
  end
37
37
  context "without specified netrc_path" do
38
38
  let(:path) { nil }
39
39
  it "uses default netrc path" do
40
- Netrc.should_receive(:read).with().and_return netrc = double("netrc")
41
- Conjur::Authn.netrc.should == netrc
40
+ expect(Netrc).to receive(:read).with(no_args).and_return netrc = double("netrc")
41
+ expect(Conjur::Authn.netrc).to eq(netrc)
42
42
  end
43
43
  end
44
44
  end
@@ -4,55 +4,55 @@ describe Conjur::Command::Assets, logged_in: true do
4
4
 
5
5
  let(:asset) { double(attributes: asset_attributes ) }
6
6
  let(:asset_attributes) { {"some"=>"attributes" } }
7
- before(:each) { api.stub(KIND.to_sym).and_return(asset) }
7
+ before(:each) { allow(api).to receive(KIND.to_sym).and_return(asset) }
8
8
  def invoke_silently
9
9
  expect { invoke }.to write
10
10
  end
11
11
 
12
12
  context "asset:create" do
13
13
  before(:each) {
14
- api.stub(:method).with("create_#{KIND}").and_return(double(arity:1))
15
- api.stub("create_#{KIND}".to_sym).and_return(asset)
14
+ allow(api).to receive(:method).with("create_#{KIND}").and_return(double(arity:1))
15
+ allow(api).to receive("create_#{KIND}".to_sym).and_return(asset)
16
16
  }
17
17
  describe_command "asset:create #{KIND}:#{ID}" do
18
18
  it "calls api.create_#{KIND}(id:#{ID})" do
19
- api.should_receive("create_#{KIND}".to_sym).with(id: ID)
19
+ expect(api).to receive("create_#{KIND}".to_sym).with(id: ID)
20
20
  invoke_silently
21
21
  end
22
22
  it "writes JSONised attributes to stdout" do
23
- JSON.parse( expect { invoke }.to write ).should == asset_attributes
23
+ expect(JSON.parse( expect { invoke }.to write )).to eq(asset_attributes)
24
24
  end
25
25
  end
26
26
  describe_command "asset:create #{KIND}" do
27
27
  it "calls api.create_#{KIND}({})" do
28
- api.should_receive("create_#{KIND}".to_sym).with({})
28
+ expect(api).to receive("create_#{KIND}".to_sym).with({})
29
29
  invoke_silently
30
30
  end
31
31
  it "writes JSONised attributes to stdout" do
32
- JSON.parse( expect { invoke }.to write ).should == asset_attributes
32
+ expect(JSON.parse( expect { invoke }.to write )).to eq(asset_attributes)
33
33
  end
34
34
  end
35
35
  end
36
36
 
37
37
  describe_command "asset:show #{KIND}:#{ID}" do
38
38
  it "obtains asset instance as api.#{KIND}(#{ID})" do
39
- api.should_receive(KIND.to_sym).with(ID)
39
+ expect(api).to receive(KIND.to_sym).with(ID)
40
40
  invoke_silently
41
41
  end
42
42
  it "writes JSONised attributes to stdout" do
43
- JSON.parse( expect { invoke }.to write ).should == asset_attributes
43
+ expect(JSON.parse( expect { invoke }.to write )).to eq(asset_attributes)
44
44
  end
45
45
  end
46
46
 
47
47
  describe_command "asset:exists #{KIND}:#{ID}" do
48
48
  let(:exists_response) { "exists? response" }
49
- before(:each) { asset.stub(:exists?).and_return(exists_response) }
49
+ before(:each) { allow(asset).to receive(:exists?).and_return(exists_response) }
50
50
  it "obtains asset instance as api.#{KIND}(#{ID})" do
51
- api.should_receive(KIND.to_sym).with(ID)
51
+ expect(api).to receive(KIND.to_sym).with(ID)
52
52
  invoke_silently
53
53
  end
54
54
  it "calls asset.exists?" do
55
- asset.should_receive(:exists?)
55
+ expect(asset).to receive(:exists?)
56
56
  invoke_silently
57
57
  end
58
58
  it "writes response to stdout" do
@@ -67,10 +67,10 @@ describe Conjur::Command::Assets, logged_in: true do
67
67
  double(attributes: { "id" => x } )
68
68
  }
69
69
  }
70
- before(:each) { api.stub("#{KIND}s".to_sym).and_return(assets_list) }
70
+ before(:each) { allow(api).to receive("#{KIND}s".to_sym).and_return(assets_list) }
71
71
 
72
72
  it "calls api.#{KIND}s" do
73
- api.should_receive("#{KIND}s".to_sym)
73
+ expect(api).to receive("#{KIND}s".to_sym)
74
74
  invoke_silently
75
75
  end
76
76
  it "for each asset from response displays it's attributes" do
@@ -83,16 +83,16 @@ describe Conjur::Command::Assets, logged_in: true do
83
83
 
84
84
  shared_examples 'it obtains asset by kind and id' do
85
85
  it "obtains asset instance as api.#{KIND}(#{ID})" do
86
- api.should_receive(KIND.to_sym).with(ID)
86
+ expect(api).to receive(KIND.to_sym).with(ID)
87
87
  invoke_silently
88
88
  end
89
89
  end
90
90
 
91
91
  shared_context "asset instance" do
92
92
  before(:each) {
93
- api.stub(KIND.to_sym).and_return(asset)
94
- asset.stub(:add_member)
95
- asset.stub(:remove_member)
93
+ allow(api).to receive(KIND.to_sym).and_return(asset)
94
+ allow(asset).to receive(:add_member)
95
+ allow(asset).to receive(:remove_member)
96
96
  }
97
97
  end
98
98
 
@@ -100,7 +100,7 @@ describe Conjur::Command::Assets, logged_in: true do
100
100
  include_context "asset instance"
101
101
  it_behaves_like "it obtains asset by kind and id"
102
102
  it 'calls role.grant_to(member,...)' do
103
- asset.should_receive(:add_member).with(ROLE, MEMBER, anything)
103
+ expect(asset).to receive(:add_member).with(ROLE, MEMBER, anything)
104
104
  invoke_silently
105
105
  end
106
106
  it { expect { invoke }.to write "Membership granted" }
@@ -110,7 +110,7 @@ describe Conjur::Command::Assets, logged_in: true do
110
110
  include_context "asset instance"
111
111
  it_behaves_like "it obtains asset by kind and id"
112
112
  it 'calls role.revoke_from(member)' do
113
- asset.should_receive(:remove_member).with(ROLE, MEMBER)
113
+ expect(asset).to receive(:remove_member).with(ROLE, MEMBER)
114
114
  invoke_silently
115
115
  end
116
116
  it { expect { invoke }.to write "Membership revoked" }