knife-opc 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f10de72126959cda281388a2e5ab0e4d0f01313
4
- data.tar.gz: 3ed8f3d554ffa5b72b0d08c2e3b317184b6b1ce0
3
+ metadata.gz: 87ecff3bb04b042ba9a49a4554e851add4d434de
4
+ data.tar.gz: 464ec5db424d80b2fe59712d493b8d0401d41598
5
5
  SHA512:
6
- metadata.gz: 303ad9f15fbb77b3a5d1709c2df28e6b5c897885ba53b2b20a43491b159570240f64f0fbed6f17f0e5a761442724220acf418ec006e4550641e24e02fb741fd2
7
- data.tar.gz: 2c09e76ff39ffaa8a0d6a459f11f834745370a5adac9be58ea94ed91a0a236249fd9ed12bf659e234fd676f50c48d1b523fbfcb06fa0564ab342c76cc5313f2d
6
+ metadata.gz: 834430d0757c6dffd83208127ba461a7954ff2aa22f7e84d4bf9533e90a77e8ad1f8fc3c9c799fc00768d780b7c49894ad2de13c21874455837dbeec261162e9
7
+ data.tar.gz: 0b33736468f0fa75e85d3118d9a3715faa1d76c8d8ec9fb97b11921a6fac10de05902af8c096584cc0b9c634a648313e4fa40751e2e3a4f29ab4c4dcdafe9700
@@ -0,0 +1,47 @@
1
+ #
2
+ # Author:: Steven Danna (<steve@opscode.com>)
3
+ # Copyright:: Copyright 2011 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ module Opc
20
+ class OpcUserEdit < Chef::Knife
21
+ category "OPSCODE PRIVATE CHEF ORGANIZATION MANAGEMENT"
22
+ banner "knife opc user edit USERNAME"
23
+
24
+ def run
25
+ user_name = @name_args[0]
26
+
27
+ if user_name.nil?
28
+ show_usage
29
+ ui.fatal("You must specify a user name")
30
+ exit 1
31
+ end
32
+
33
+ @chef_rest = Chef::REST.new(Chef::Config[:chef_server_root])
34
+ original_user = @chef_rest.get_rest("users/#{user_name}")
35
+ edited_user = edit_data(original_user)
36
+ if original_user != edited_user
37
+ @chef_rest = Chef::REST.new(Chef::Config[:chef_server_root])
38
+ ui.msg edited_user
39
+ result = @chef_rest.put_rest("users/#{user_name}", edited_user)
40
+ ui.msg("Saved #{user_name}.")
41
+ else
42
+ ui.msg("User unchaged, not saving.")
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -50,7 +50,10 @@ module Opc
50
50
  raise e
51
51
  end
52
52
  end
53
- org.add_user_to_group('admins', @username) if config[:admin]
53
+ if config[:admin]
54
+ org.add_user_to_group('admins', @username)
55
+ org.add_user_to_group('billing-admins', @username)
56
+ end
54
57
  end
55
58
  end
56
59
  end
@@ -54,6 +54,15 @@ module Opc
54
54
  :password => password
55
55
  }
56
56
 
57
+ # Check the file before creating the user so the api is more transactional.
58
+ if config[:filename]
59
+ file = config[:filename]
60
+ unless File.exists?(file) ? File.writable?(file) : File.writable?(File.dirname(file))
61
+ ui.fatal "File #{config[:filename]} is not writable. Check permissions."
62
+ exit 1
63
+ end
64
+ end
65
+
57
66
  @chef_rest = Chef::REST.new(Chef::Config[:chef_server_root])
58
67
  result = @chef_rest.post_rest("users/", user_hash)
59
68
  if config[:filename]
@@ -20,6 +20,16 @@ module Opc
20
20
  class OpcUserEdit < Chef::Knife
21
21
  category "OPSCODE PRIVATE CHEF ORGANIZATION MANAGEMENT"
22
22
  banner "knife opc user edit USERNAME"
23
+
24
+ option :input,
25
+ :long => '--input FILENAME',
26
+ :short => '-i FILENAME',
27
+ :description => 'Name of file to use for PUT or POST'
28
+
29
+ option :filename,
30
+ :long => '--filename FILENAME',
31
+ :short => '-f FILENAME',
32
+ :description => 'Write private key to FILENAME rather than STDOUT'
23
33
 
24
34
  def run
25
35
  user_name = @name_args[0]
@@ -32,16 +42,28 @@ module Opc
32
42
 
33
43
  @chef_rest = Chef::REST.new(Chef::Config[:chef_server_root])
34
44
  original_user = @chef_rest.get_rest("users/#{user_name}")
35
- edited_user = edit_data(original_user)
45
+ if config[:input]
46
+ edited_user = JSON.parse(IO.read(config[:input]))
47
+ else
48
+ edited_user = edit_data(original_user)
49
+ end
36
50
  if original_user != edited_user
37
51
  @chef_rest = Chef::REST.new(Chef::Config[:chef_server_root])
38
- ui.msg edited_user
39
52
  result = @chef_rest.put_rest("users/#{user_name}", edited_user)
40
53
  ui.msg("Saved #{user_name}.")
54
+ if ! result['private_key'].nil?
55
+ if config[:filename]
56
+ File.open(config[:filename], "w") do |f|
57
+ f.print(result['private_key'])
58
+ end
59
+ else
60
+ ui.msg result['private_key']
61
+ end
62
+ end
41
63
  else
42
- ui.msg("User unchaged, not saving.")
64
+ ui.msg("User unchanged, not saving.")
43
65
  end
44
66
 
45
67
  end
46
68
  end
47
- end
69
+ end
@@ -1,3 +1,3 @@
1
1
  module KnifeOPC
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-opc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Danna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2015-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -79,6 +79,7 @@ files:
79
79
  - lib/chef/knife/opc_org_create.rb
80
80
  - lib/chef/knife/opc_org_delete.rb
81
81
  - lib/chef/knife/opc_org_edit.rb
82
+ - lib/chef/knife/opc_org_edit.rc~
82
83
  - lib/chef/knife/opc_org_list.rb
83
84
  - lib/chef/knife/opc_org_show.rb
84
85
  - lib/chef/knife/opc_org_user_add.rb
@@ -110,8 +111,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  version: '0'
111
112
  requirements: []
112
113
  rubyforge_project:
113
- rubygems_version: 2.2.2
114
+ rubygems_version: 2.4.4
114
115
  signing_key:
115
116
  specification_version: 4
116
117
  summary: Knife Tools for Opscode Chef Server
117
118
  test_files: []
119
+ has_rdoc: