knife-opc 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/chef/knife/opc_org_delete.rb +4 -2
- data/lib/chef/knife/opc_org_edit.rb +5 -4
- data/lib/chef/knife/opc_org_list.rb +5 -3
- data/lib/chef/knife/opc_org_show.rb +4 -2
- data/lib/chef/knife/opc_user_create.rb +6 -4
- data/lib/chef/knife/opc_user_delete.rb +6 -4
- data/lib/chef/knife/opc_user_edit.rb +6 -5
- data/lib/chef/knife/opc_user_list.rb +4 -2
- data/lib/chef/knife/opc_user_password.rb +6 -6
- data/lib/chef/knife/opc_user_show.rb +5 -3
- data/lib/chef/mixin/root_rest.rb +31 -0
- data/lib/knife-opc/version.rb +1 -1
- metadata +3 -4
- data/lib/chef/knife/opc_org_edit.rc~ +0 -47
- data/lib/chef/org/group_operations.rb~ +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3257cb3b536d35a41ec3fccb5c73162012fa9953
|
4
|
+
data.tar.gz: a439aff11ffa9bde8fe771cc4d39800875c26ae0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3195effbdcb420a5a81d75dcbdede8345174b733e0b6a8cfe0e71cded805592b5c941a09848d4cbbf09e0429128a42702949b9ef1b25901f5184c00ac698a1c2
|
7
|
+
data.tar.gz: df351c0d42dadc75f675121a6e39bb4da13a5e7abca00dd0392f2aae521300f5959549ad8d10ef69321777397050349ac164c6cf29f664d9993b4e76059dc91a
|
data/README.md
CHANGED
@@ -15,17 +15,19 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
+
require 'chef/mixin/root_rest'
|
18
19
|
|
19
20
|
module Opc
|
20
21
|
class OpcOrgDelete < Chef::Knife
|
21
22
|
category "OPSCODE PRIVATE CHEF ORGANIZATION MANAGEMENT"
|
22
23
|
banner "knife opc org delete ORG_NAME"
|
23
24
|
|
25
|
+
include Chef::Mixin::RootRestv0
|
26
|
+
|
24
27
|
def run
|
25
28
|
org_name = @name_args[0]
|
26
|
-
@chef_rest = Chef::REST.new(Chef::Config[:chef_server_root])
|
27
29
|
ui.confirm "Do you want to delete the organization #{org_name}"
|
28
|
-
ui.output
|
30
|
+
ui.output root_rest.delete("organizations/#{org_name}")
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -15,6 +15,7 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
+
require 'chef/mixin/root_rest'
|
18
19
|
|
19
20
|
module Opc
|
20
21
|
class OpcOrgEdit < Chef::Knife
|
@@ -30,8 +31,9 @@ module Opc
|
|
30
31
|
exit 1
|
31
32
|
end
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
include Chef::Mixin::RootRestv0
|
35
|
+
|
36
|
+
original_org = root_rest.get("organizations/#{org_name}")
|
35
37
|
edited_org = edit_data(original_org)
|
36
38
|
|
37
39
|
if original_org == edited_org
|
@@ -39,9 +41,8 @@ module Opc
|
|
39
41
|
exit
|
40
42
|
end
|
41
43
|
|
42
|
-
@chef_rest = Chef::REST.new(Chef::Config[:chef_server_root])
|
43
44
|
ui.msg edited_org
|
44
|
-
|
45
|
+
root_rest.put("organizations/#{org_name}", edited_org)
|
45
46
|
ui.msg("Saved #{org_name}.")
|
46
47
|
end
|
47
48
|
end
|
@@ -15,6 +15,7 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
+
require 'chef/mixin/root_rest'
|
18
19
|
|
19
20
|
module Opc
|
20
21
|
class OpcOrgList < Chef::Knife
|
@@ -31,10 +32,11 @@ module Opc
|
|
31
32
|
:short => "-a",
|
32
33
|
:description => "Show auto-generated hidden orgs in output"
|
33
34
|
|
35
|
+
include Chef::Mixin::RootRestv0
|
36
|
+
|
34
37
|
def run
|
35
|
-
|
36
|
-
|
37
|
-
unless config[:all_orgs]
|
38
|
+
results = root_rest.get("organizations")
|
39
|
+
unless config[:all_orgs]
|
38
40
|
results = results.select { |k,v| !(k.length == 20 && k =~ /^[a-z]+$/) }
|
39
41
|
end
|
40
42
|
ui.output(ui.format_list_for_display(results))
|
@@ -15,16 +15,18 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
+
require 'chef/mixin/root_rest'
|
18
19
|
|
19
20
|
module Opc
|
20
21
|
class OpcOrgShow < Chef::Knife
|
21
22
|
category "OPSCODE PRIVATE CHEF ORGANIZATION MANAGEMENT"
|
22
23
|
banner "knife opc org show ORGNAME"
|
23
24
|
|
25
|
+
include Chef::Mixin::RootRestv0
|
26
|
+
|
24
27
|
def run
|
25
28
|
org_name = @name_args[0]
|
26
|
-
|
27
|
-
ui.output @chef_rest.get_rest("organizations/#{org_name}")
|
29
|
+
ui.output root_rest.get("organizations/#{org_name}")
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -15,6 +15,7 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
+
require 'chef/mixin/root_rest'
|
18
19
|
|
19
20
|
module Opc
|
20
21
|
class OpcUserCreate < Chef::Knife
|
@@ -31,6 +32,8 @@ module Opc
|
|
31
32
|
:short => '-o ORGNAME',
|
32
33
|
:description => 'Associate new user to an organization matching ORGNAME'
|
33
34
|
|
35
|
+
include Chef::Mixin::RootRestv0
|
36
|
+
|
34
37
|
def run
|
35
38
|
case @name_args.count
|
36
39
|
when 6
|
@@ -63,8 +66,7 @@ module Opc
|
|
63
66
|
end
|
64
67
|
end
|
65
68
|
|
66
|
-
|
67
|
-
result = @chef_rest.post_rest("users/", user_hash)
|
69
|
+
result = root_rest.post("users/", user_hash)
|
68
70
|
if config[:filename]
|
69
71
|
File.open(config[:filename], "w") do |f|
|
70
72
|
f.print(result['private_key'])
|
@@ -74,9 +76,9 @@ module Opc
|
|
74
76
|
end
|
75
77
|
if config[:orgname]
|
76
78
|
request_body = {:user => username}
|
77
|
-
response =
|
79
|
+
response = root_rest.post("organizations/#{config[:orgname]}/association_requests", request_body)
|
78
80
|
association_id = response["uri"].split("/").last
|
79
|
-
|
81
|
+
root_rest.put("users/#{username}/association_requests/#{association_id}", {:response => 'accept'})
|
80
82
|
end
|
81
83
|
end
|
82
84
|
end
|
@@ -15,6 +15,7 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
+
require 'chef/mixin/root_rest'
|
18
19
|
|
19
20
|
module Opc
|
20
21
|
class OpcUserDelete < Chef::Knife
|
@@ -26,18 +27,19 @@ module Opc
|
|
26
27
|
:short => "-d",
|
27
28
|
:description => "Don't disassociate the user first"
|
28
29
|
|
30
|
+
include Chef::Mixin::RootRestv0
|
31
|
+
|
29
32
|
def run
|
30
33
|
username = @name_args[0]
|
31
|
-
@chef_rest = Chef::REST.new(Chef::Config[:chef_server_root])
|
32
34
|
ui.confirm "Do you want to delete the user #{username}"
|
33
35
|
unless config[:no_disassociate_user]
|
34
|
-
orgs =
|
36
|
+
orgs = root_rest.get("users/#{username}/organizations")
|
35
37
|
org_names = orgs.map {|o| o['organization']['name']}
|
36
38
|
org_names.each do |org|
|
37
|
-
ui.output
|
39
|
+
ui.output root_rest.delete("organizations/#{org}/users/#{username}")
|
38
40
|
end
|
39
41
|
end
|
40
|
-
ui.output
|
42
|
+
ui.output root_rest.delete("users/#{username}")
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
@@ -15,12 +15,13 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
+
require 'chef/mixin/root_rest'
|
18
19
|
|
19
20
|
module Opc
|
20
21
|
class OpcUserEdit < Chef::Knife
|
21
22
|
category "OPSCODE PRIVATE CHEF ORGANIZATION MANAGEMENT"
|
22
23
|
banner "knife opc user edit USERNAME"
|
23
|
-
|
24
|
+
|
24
25
|
option :input,
|
25
26
|
:long => '--input FILENAME',
|
26
27
|
:short => '-i FILENAME',
|
@@ -31,6 +32,8 @@ module Opc
|
|
31
32
|
:short => '-f FILENAME',
|
32
33
|
:description => 'Write private key to FILENAME rather than STDOUT'
|
33
34
|
|
35
|
+
include Chef::Mixin::RootRestv0
|
36
|
+
|
34
37
|
def run
|
35
38
|
user_name = @name_args[0]
|
36
39
|
|
@@ -40,16 +43,14 @@ module Opc
|
|
40
43
|
exit 1
|
41
44
|
end
|
42
45
|
|
43
|
-
|
44
|
-
original_user = @chef_rest.get_rest("users/#{user_name}")
|
46
|
+
original_user = root_rest.get("users/#{user_name}")
|
45
47
|
if config[:input]
|
46
48
|
edited_user = JSON.parse(IO.read(config[:input]))
|
47
49
|
else
|
48
50
|
edited_user = edit_data(original_user)
|
49
51
|
end
|
50
52
|
if original_user != edited_user
|
51
|
-
|
52
|
-
result = @chef_rest.put_rest("users/#{user_name}", edited_user)
|
53
|
+
result = root_rest.put("users/#{user_name}", edited_user)
|
53
54
|
ui.msg("Saved #{user_name}.")
|
54
55
|
if ! result['private_key'].nil?
|
55
56
|
if config[:filename]
|
@@ -15,6 +15,7 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
+
require 'chef/mixin/root_rest'
|
18
19
|
|
19
20
|
module Opc
|
20
21
|
class OpcUserList < Chef::Knife
|
@@ -26,9 +27,10 @@ module Opc
|
|
26
27
|
:short => "-w",
|
27
28
|
:description => "Show corresponding URIs"
|
28
29
|
|
30
|
+
include Chef::Mixin::RootRestv0
|
31
|
+
|
29
32
|
def run
|
30
|
-
|
31
|
-
results = @chef_rest.get_rest("users")
|
33
|
+
results = root_rest.get("users")
|
32
34
|
ui.output(ui.format_list_for_display(results))
|
33
35
|
end
|
34
36
|
end
|
@@ -15,17 +15,20 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
+
require 'chef/mixin/root_rest'
|
18
19
|
|
19
20
|
module Opc
|
20
21
|
class OpcUserPassword < Chef::Knife
|
21
22
|
category "OPSCODE PRIVATE CHEF ORGANIZATION MANAGEMENT"
|
22
|
-
banner "knife opc user password USERNAME [PASSWORD | --
|
23
|
+
banner "knife opc user password USERNAME [PASSWORD | --enable-external-auth]"
|
23
24
|
|
24
25
|
option :enable_external_auth,
|
25
26
|
:long => "--enable-external-auth",
|
26
27
|
:short => "-e",
|
27
28
|
:description => "Enable external authentication for this user (such as LDAP)"
|
28
29
|
|
30
|
+
include Chef::Mixin::RootRestv0
|
31
|
+
|
29
32
|
def run
|
30
33
|
# check that correct number of args was passed, should be either
|
31
34
|
# USERNAME PASSWORD or USERNAME --enable-external-auth
|
@@ -43,13 +46,11 @@ module Opc
|
|
43
46
|
# note that this will be nil if config[:enable_external_auth] is true
|
44
47
|
password = @name_args[1]
|
45
48
|
|
46
|
-
@chef_rest = Chef::REST.new(Chef::Config[:chef_server_root])
|
47
|
-
|
48
49
|
# since the API does not pass back whether recovery_authentication_enabled is
|
49
50
|
# true or false, there is no way of knowing if the user is using ldap or not,
|
50
51
|
# so we will update the user every time, instead of checking if we are actually
|
51
52
|
# changing anything before we PUT.
|
52
|
-
user =
|
53
|
+
user = root_rest.get("users/#{user_name}")
|
53
54
|
|
54
55
|
user["password"] = password if not password.nil?
|
55
56
|
|
@@ -59,9 +60,8 @@ module Opc
|
|
59
60
|
# wants to disable ldap and put user in recover (if they are using ldap).
|
60
61
|
user["recovery_authentication_enabled"] = !config[:enable_external_auth]
|
61
62
|
|
62
|
-
@chef_rest = Chef::REST.new(Chef::Config[:chef_server_root])
|
63
63
|
begin
|
64
|
-
|
64
|
+
root_rest.put("users/#{user_name}", user)
|
65
65
|
rescue => e
|
66
66
|
raise e
|
67
67
|
exit 1
|
@@ -15,6 +15,7 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
+
require 'chef/mixin/root_rest'
|
18
19
|
|
19
20
|
module Opc
|
20
21
|
class OpcUserShow < Chef::Knife
|
@@ -25,12 +26,13 @@ module Opc
|
|
25
26
|
:long => "--with-orgs",
|
26
27
|
:short => "-l"
|
27
28
|
|
29
|
+
include Chef::Mixin::RootRestv0
|
30
|
+
|
28
31
|
def run
|
29
32
|
user_name = @name_args[0]
|
30
|
-
|
31
|
-
results = @chef_rest.get_rest("users/#{user_name}")
|
33
|
+
results = root_rest.get("users/#{user_name}")
|
32
34
|
if config[:with_orgs]
|
33
|
-
orgs =
|
35
|
+
orgs = root_rest.get("users/#{user_name}/organizations")
|
34
36
|
results["organizations"] = orgs.map {|o| o['organization']['name']}
|
35
37
|
end
|
36
38
|
ui.output results
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Steven Danna (<steve@chef.io>)
|
3
|
+
# Copyright:: Copyright 2011 Chef Software, 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
|
+
require 'chef/server_api'
|
19
|
+
class Chef
|
20
|
+
module Mixin
|
21
|
+
module RootRestv0
|
22
|
+
def root_rest
|
23
|
+
# Use v0 API for now
|
24
|
+
# Rather than upgrade all of this code to move to v1, the goal is to remove the
|
25
|
+
# need for this plugin. See
|
26
|
+
# https://github.com/chef/chef/issues/3517
|
27
|
+
@root_rest ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], {:api_version => "0"})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/knife-opc/version.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Danna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -79,7 +79,6 @@ 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~
|
83
82
|
- lib/chef/knife/opc_org_list.rb
|
84
83
|
- lib/chef/knife/opc_org_show.rb
|
85
84
|
- lib/chef/knife/opc_org_user_add.rb
|
@@ -90,9 +89,9 @@ files:
|
|
90
89
|
- lib/chef/knife/opc_user_list.rb
|
91
90
|
- lib/chef/knife/opc_user_password.rb
|
92
91
|
- lib/chef/knife/opc_user_show.rb
|
92
|
+
- lib/chef/mixin/root_rest.rb
|
93
93
|
- lib/chef/org.rb
|
94
94
|
- lib/chef/org/group_operations.rb
|
95
|
-
- lib/chef/org/group_operations.rb~
|
96
95
|
- lib/knife-opc/version.rb
|
97
96
|
homepage: http://wiki.opscode.com/display/chef
|
98
97
|
licenses: []
|
@@ -1,47 +0,0 @@
|
|
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
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'chef/org'
|
2
|
-
|
3
|
-
class Chef
|
4
|
-
class Org
|
5
|
-
module GroupOperations
|
6
|
-
def add_user_to_group(groupname, username)
|
7
|
-
group = chef_rest.get_rest "organizations/#{name}/groups/#{groupname}"
|
8
|
-
body_hash = {
|
9
|
-
:groupname => "#{groupname}",
|
10
|
-
:actors => {
|
11
|
-
"users" => group["actors"].concat([username]),
|
12
|
-
"groups" => group["groups"]
|
13
|
-
}
|
14
|
-
}
|
15
|
-
chef_rest.put_rest "organizations/#{name}/groups/#{groupname}", body_hash
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
include Chef::Org::GroupOperations
|
21
|
-
end
|