knife-opc 0.3.2 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/chef/knife/opc_org_create.rb +15 -15
- data/lib/chef/knife/opc_org_delete.rb +4 -4
- data/lib/chef/knife/opc_org_edit.rb +5 -5
- data/lib/chef/knife/opc_org_list.rb +12 -12
- data/lib/chef/knife/opc_org_show.rb +4 -4
- data/lib/chef/knife/opc_org_user_add.rb +11 -10
- data/lib/chef/knife/opc_org_user_remove.rb +55 -3
- data/lib/chef/knife/opc_user_create.rb +45 -29
- data/lib/chef/knife/opc_user_delete.rb +114 -15
- data/lib/chef/knife/opc_user_edit.rb +43 -19
- data/lib/chef/knife/opc_user_list.rb +19 -9
- data/lib/chef/knife/opc_user_password.rb +10 -11
- data/lib/chef/knife/opc_user_show.rb +9 -9
- data/lib/chef/mixin/root_rest.rb +3 -3
- data/lib/chef/org.rb +35 -37
- data/lib/chef/org/group_operations.rb +46 -6
- data/lib/knife-opc/version.rb +1 -1
- metadata +11 -71
- data/README.md +0 -183
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b3a53e5648286443bac177c18abd99f1fab7c2859e6536c5513a48ca8cc50b84
|
4
|
+
data.tar.gz: eac1bd7ce2e7cd8e18bd4ee29d5d151f89ebe9a2f2b8364f1d5a49e9cfec034a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fe3ab2ac4123cc30e7bdf06035c0cd8fa7d3d1bf24efb971135f54c1e887940b81d76a39596cfe703739d857ae549a2dbca05630586ea56256d6baf0936553f
|
7
|
+
data.tar.gz: 58648d6287565e3b145d7e34224d9873d2199ed2e6d1310e07b5baf5d71bb957662d9266dbcf0f02fc1e7ddf242861519498d4e82b01e3094ece058ef3d2d823
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Steven Danna (<steve@
|
3
|
-
# Copyright:: Copyright 2011
|
2
|
+
# Author:: Steven Danna (<steve@chef.io>)
|
3
|
+
# Copyright:: Copyright 2011-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -18,24 +18,24 @@
|
|
18
18
|
|
19
19
|
module Opc
|
20
20
|
class OpcOrgCreate < Chef::Knife
|
21
|
-
category "
|
21
|
+
category "CHEF ORGANIZATION MANAGEMENT"
|
22
22
|
banner "knife opc org create ORG_SHORT_NAME ORG_FULL_NAME (options)"
|
23
23
|
|
24
24
|
option :filename,
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
long: "--filename FILENAME",
|
26
|
+
short: "-f FILENAME",
|
27
|
+
description: "Write validator private key to FILENAME rather than STDOUT"
|
28
28
|
|
29
29
|
option :association_user,
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
long: "--association_user USERNAME",
|
31
|
+
short: "-a USERNAME",
|
32
|
+
description: "Invite USERNAME to the new organization after creation"
|
33
33
|
|
34
34
|
attr_accessor :org_name, :org_full_name
|
35
35
|
|
36
36
|
deps do
|
37
|
-
|
38
|
-
|
37
|
+
require_relative "../org"
|
38
|
+
require_relative "../org/group_operations"
|
39
39
|
end
|
40
40
|
|
41
41
|
def run
|
@@ -47,8 +47,8 @@ module Opc
|
|
47
47
|
exit 1
|
48
48
|
end
|
49
49
|
|
50
|
-
org = Chef::Org.from_hash({
|
51
|
-
|
50
|
+
org = Chef::Org.from_hash({ "name" => org_name,
|
51
|
+
"full_name" => org_full_name }).create
|
52
52
|
if config[:filename]
|
53
53
|
File.open(config[:filename], "w") do |f|
|
54
54
|
f.print(org.private_key)
|
@@ -59,8 +59,8 @@ module Opc
|
|
59
59
|
|
60
60
|
if config[:association_user]
|
61
61
|
org.associate_user(config[:association_user])
|
62
|
-
org.add_user_to_group(
|
63
|
-
org.add_user_to_group(
|
62
|
+
org.add_user_to_group("admins", config[:association_user])
|
63
|
+
org.add_user_to_group("billing-admins", config[:association_user])
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Steven Danna (<steve@
|
3
|
-
# Copyright:: Copyright 2011
|
2
|
+
# Author:: Steven Danna (<steve@chef.io>)
|
3
|
+
# Copyright:: Copyright 2011-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -15,11 +15,11 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
|
18
|
+
require_relative "../mixin/root_rest"
|
19
19
|
|
20
20
|
module Opc
|
21
21
|
class OpcOrgDelete < Chef::Knife
|
22
|
-
category "
|
22
|
+
category "CHEF ORGANIZATION MANAGEMENT"
|
23
23
|
banner "knife opc org delete ORG_NAME"
|
24
24
|
|
25
25
|
include Chef::Mixin::RootRestv0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Steven Danna (<steve@
|
3
|
-
# Copyright:: Copyright 2011
|
2
|
+
# Author:: Steven Danna (<steve@chef.io>)
|
3
|
+
# Copyright:: Copyright 2011-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -15,11 +15,11 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
|
18
|
+
require_relative "../mixin/root_rest"
|
19
19
|
|
20
20
|
module Opc
|
21
21
|
class OpcOrgEdit < Chef::Knife
|
22
|
-
category "
|
22
|
+
category "CHEF ORGANIZATION MANAGEMENT"
|
23
23
|
banner "knife opc org edit ORG"
|
24
24
|
|
25
25
|
def run
|
@@ -33,7 +33,7 @@ module Opc
|
|
33
33
|
|
34
34
|
include Chef::Mixin::RootRestv0
|
35
35
|
|
36
|
-
original_org =
|
36
|
+
original_org = root_rest.get("organizations/#{org_name}")
|
37
37
|
edited_org = edit_data(original_org)
|
38
38
|
|
39
39
|
if original_org == edited_org
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Steven Danna (<steve@
|
3
|
-
# Copyright:: Copyright 2011
|
2
|
+
# Author:: Steven Danna (<steve@chef.io>)
|
3
|
+
# Copyright:: Copyright 2011-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -15,29 +15,29 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
|
18
|
+
require_relative "../mixin/root_rest"
|
19
19
|
|
20
20
|
module Opc
|
21
21
|
class OpcOrgList < Chef::Knife
|
22
|
-
category "
|
22
|
+
category "CHEF ORGANIZATION MANAGEMENT"
|
23
23
|
banner "knife opc org list"
|
24
24
|
|
25
25
|
option :with_uri,
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
long: "--with-uri",
|
27
|
+
short: "-w",
|
28
|
+
description: "Show corresponding URIs"
|
29
29
|
|
30
30
|
option :all_orgs,
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
long: "--all-orgs",
|
32
|
+
short: "-a",
|
33
|
+
description: "Show auto-generated hidden orgs in output"
|
34
34
|
|
35
35
|
include Chef::Mixin::RootRestv0
|
36
36
|
|
37
37
|
def run
|
38
|
-
results =
|
38
|
+
results = root_rest.get("organizations")
|
39
39
|
unless config[:all_orgs]
|
40
|
-
results = results.select { |k,v| !(k.length == 20 && k =~ /^[a-z]+$/) }
|
40
|
+
results = results.select { |k, v| !(k.length == 20 && k =~ /^[a-z]+$/) }
|
41
41
|
end
|
42
42
|
ui.output(ui.format_list_for_display(results))
|
43
43
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Steven Danna (<steve@
|
3
|
-
# Copyright:: Copyright 2011
|
2
|
+
# Author:: Steven Danna (<steve@chef.io>)
|
3
|
+
# Copyright:: Copyright 2011-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -15,11 +15,11 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
|
18
|
+
require_relative "../mixin/root_rest"
|
19
19
|
|
20
20
|
module Opc
|
21
21
|
class OpcOrgShow < Chef::Knife
|
22
|
-
category "
|
22
|
+
category "CHEF ORGANIZATION MANAGEMENT"
|
23
23
|
banner "knife opc org show ORGNAME"
|
24
24
|
|
25
25
|
include Chef::Mixin::RootRestv0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Marc Paradise (<marc@
|
3
|
-
# Copyright:: Copyright 2014 Chef Software, Inc
|
2
|
+
# Author:: Marc Paradise (<marc@chef.io>)
|
3
|
+
# Copyright:: Copyright 2014-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -18,18 +18,18 @@
|
|
18
18
|
|
19
19
|
module Opc
|
20
20
|
class OpcOrgUserAdd < Chef::Knife
|
21
|
-
category "
|
21
|
+
category "CHEF ORGANIZATION MANAGEMENT"
|
22
22
|
banner "knife opc org user add ORG_NAME USER_NAME"
|
23
23
|
attr_accessor :org_name, :username
|
24
24
|
|
25
25
|
option :admin,
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
long: "--admin",
|
27
|
+
short: "-a",
|
28
|
+
description: "Add user to admin group"
|
29
29
|
|
30
30
|
deps do
|
31
|
-
|
32
|
-
|
31
|
+
require_relative "../org"
|
32
|
+
require_relative "../org/group_operations"
|
33
33
|
end
|
34
34
|
|
35
35
|
def run
|
@@ -52,8 +52,9 @@ module Opc
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
if config[:admin]
|
55
|
-
org.add_user_to_group(
|
56
|
-
org.add_user_to_group(
|
55
|
+
org.add_user_to_group("admins", @username)
|
56
|
+
org.add_user_to_group("billing-admins", @username)
|
57
|
+
ui.msg "User #{username} is added to admins and billing-admins group"
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Marc Paradise (<marc@getchef.com>)
|
3
|
-
# Copyright:: Copyright 2014 Chef Software, Inc
|
3
|
+
# Copyright:: Copyright 2014-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -18,12 +18,19 @@
|
|
18
18
|
|
19
19
|
module Opc
|
20
20
|
class OpcOrgUserRemove < Chef::Knife
|
21
|
-
category "
|
21
|
+
category "CHEF ORGANIZATION MANAGEMENT"
|
22
22
|
banner "knife opc org user remove ORG_NAME USER_NAME"
|
23
23
|
attr_accessor :org_name, :username
|
24
24
|
|
25
|
+
option :force_remove_from_admins,
|
26
|
+
long: "--force",
|
27
|
+
short: "-f",
|
28
|
+
description: "Force removal of user from the organization's admins and billing-admins group."
|
29
|
+
|
25
30
|
deps do
|
26
|
-
|
31
|
+
require_relative "../org"
|
32
|
+
require_relative "../org/group_operations"
|
33
|
+
require "chef/json_compat"
|
27
34
|
end
|
28
35
|
|
29
36
|
def run
|
@@ -36,16 +43,61 @@ module Opc
|
|
36
43
|
end
|
37
44
|
|
38
45
|
org = Chef::Org.new(@org_name)
|
46
|
+
|
47
|
+
if config[:force_remove_from_admins]
|
48
|
+
if org.actor_delete_would_leave_admins_empty?
|
49
|
+
failure_error_message(org_name, username)
|
50
|
+
ui.msg <<~EOF
|
51
|
+
You ran with --force which force removes the user from the admins and billing-admins groups.
|
52
|
+
However, removing #{username} from the admins group would leave it empty, which breaks the org.
|
53
|
+
Please add another user to org #{org_name} admins group and try again.
|
54
|
+
EOF
|
55
|
+
exit 1
|
56
|
+
end
|
57
|
+
remove_user_from_admin_group(org, org_name, username, "admins")
|
58
|
+
remove_user_from_admin_group(org, org_name, username, "billing-admins")
|
59
|
+
end
|
60
|
+
|
39
61
|
begin
|
40
62
|
org.dissociate_user(@username)
|
41
63
|
rescue Net::HTTPServerException => e
|
42
64
|
if e.response.code == "404"
|
43
65
|
ui.msg "User #{username} is not associated with organization #{org_name}"
|
44
66
|
exit 1
|
67
|
+
elsif e.response.code == "403"
|
68
|
+
body = Chef::JSONCompat.from_json(e.response.body)
|
69
|
+
if body.key?("error") && body["error"] == "Please remove #{username} from this organization's admins group before removing him or her from the organization."
|
70
|
+
failure_error_message(org_name, username)
|
71
|
+
ui.msg <<~EOF
|
72
|
+
User #{username} is in the organization's admin group. Removing users from an organization without removing them from the admins group is not allowed.
|
73
|
+
Re-run this command with --force to remove this user from the admins prior to removing it from the organization.
|
74
|
+
EOF
|
75
|
+
exit 1
|
76
|
+
else
|
77
|
+
raise e
|
78
|
+
end
|
45
79
|
else
|
46
80
|
raise e
|
47
81
|
end
|
48
82
|
end
|
49
83
|
end
|
84
|
+
|
85
|
+
def failure_error_message(org_name, username)
|
86
|
+
ui.error "Error removing user #{username} from organization #{org_name}."
|
87
|
+
end
|
88
|
+
|
89
|
+
def remove_user_from_admin_group(org, org_name, username, admin_group_string)
|
90
|
+
org.remove_user_from_group(admin_group_string, username)
|
91
|
+
rescue Net::HTTPServerException => e
|
92
|
+
if e.response.code == "404"
|
93
|
+
ui.warn <<~EOF
|
94
|
+
User #{username} is not in the #{admin_group_string} group for organization #{org_name}.
|
95
|
+
You probably don't need to pass --force.
|
96
|
+
EOF
|
97
|
+
else
|
98
|
+
raise e
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
50
102
|
end
|
51
103
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Steven Danna (<steve@
|
3
|
-
# Copyright:: Copyright 2011
|
2
|
+
# Author:: Steven Danna (<steve@chef.io>)
|
3
|
+
# Copyright:: Copyright 2011-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -15,22 +15,27 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
|
18
|
+
require_relative "../mixin/root_rest"
|
19
19
|
|
20
20
|
module Opc
|
21
21
|
class OpcUserCreate < Chef::Knife
|
22
|
-
category "
|
22
|
+
category "CHEF ORGANIZATION MANAGEMENT"
|
23
23
|
banner "knife opc user create USERNAME FIRST_NAME [MIDDLE_NAME] LAST_NAME EMAIL PASSWORD"
|
24
24
|
|
25
25
|
option :filename,
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
long: "--filename FILENAME",
|
27
|
+
short: "-f FILENAME",
|
28
|
+
description: "Write private key to FILENAME rather than STDOUT"
|
29
29
|
|
30
30
|
option :orgname,
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
long: "--orgname ORGNAME",
|
32
|
+
short: "-o ORGNAME",
|
33
|
+
description: "Associate new user to an organization matching ORGNAME"
|
34
|
+
|
35
|
+
option :passwordprompt,
|
36
|
+
long: "--prompt-for-password",
|
37
|
+
short: "-p",
|
38
|
+
description: "Prompt for user password"
|
34
39
|
|
35
40
|
include Chef::Mixin::RootRestv0
|
36
41
|
|
@@ -40,46 +45,57 @@ module Opc
|
|
40
45
|
username, first_name, middle_name, last_name, email, password = @name_args
|
41
46
|
when 5
|
42
47
|
username, first_name, last_name, email, password = @name_args
|
48
|
+
when 4
|
49
|
+
username, first_name, last_name, email = @name_args
|
43
50
|
else
|
44
51
|
ui.fatal "Wrong number of arguments"
|
45
52
|
show_usage
|
46
53
|
exit 1
|
47
54
|
end
|
55
|
+
password = prompt_for_password if config[:passwordprompt]
|
56
|
+
unless password
|
57
|
+
ui.fatal "You must either provide a password or use the --prompt-for-password (-p) option"
|
58
|
+
exit 1
|
59
|
+
end
|
48
60
|
middle_name ||= ""
|
49
61
|
|
50
62
|
user_hash = {
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
63
|
+
username: username,
|
64
|
+
first_name: first_name,
|
65
|
+
middle_name: middle_name,
|
66
|
+
last_name: last_name,
|
67
|
+
display_name: "#{first_name} #{last_name}",
|
68
|
+
email: email,
|
69
|
+
password: password,
|
58
70
|
}
|
59
71
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
72
|
+
# Check the file before creating the user so the api is more transactional.
|
73
|
+
if config[:filename]
|
74
|
+
file = config[:filename]
|
75
|
+
unless File.exist?(file) ? File.writable?(file) : File.writable?(File.dirname(file))
|
76
|
+
ui.fatal "File #{config[:filename]} is not writable. Check permissions."
|
77
|
+
exit 1
|
78
|
+
end
|
79
|
+
end
|
68
80
|
|
69
81
|
result = root_rest.post("users/", user_hash)
|
70
82
|
if config[:filename]
|
71
83
|
File.open(config[:filename], "w") do |f|
|
72
|
-
f.print(result[
|
84
|
+
f.print(result["private_key"])
|
73
85
|
end
|
74
86
|
else
|
75
|
-
ui.msg result[
|
87
|
+
ui.msg result["private_key"]
|
76
88
|
end
|
77
89
|
if config[:orgname]
|
78
|
-
request_body = {:
|
90
|
+
request_body = { user: username }
|
79
91
|
response = root_rest.post("organizations/#{config[:orgname]}/association_requests", request_body)
|
80
92
|
association_id = response["uri"].split("/").last
|
81
|
-
root_rest.put("users/#{username}/association_requests/#{association_id}", {:
|
93
|
+
root_rest.put("users/#{username}/association_requests/#{association_id}", { response: "accept" })
|
82
94
|
end
|
83
95
|
end
|
96
|
+
|
97
|
+
def prompt_for_password
|
98
|
+
ui.ask("Please enter the user's password: ") { |q| q.echo = false }
|
99
|
+
end
|
84
100
|
end
|
85
101
|
end
|