knife-opc 0.4.1 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef/knife/opc_org_create.rb +8 -8
- data/lib/chef/knife/opc_org_delete.rb +1 -1
- data/lib/chef/knife/opc_org_edit.rb +1 -1
- data/lib/chef/knife/opc_org_list.rb +7 -7
- data/lib/chef/knife/opc_org_show.rb +1 -1
- data/lib/chef/knife/opc_org_user_add.rb +5 -5
- data/lib/chef/knife/opc_org_user_remove.rb +8 -8
- data/lib/chef/knife/opc_user_create.rb +12 -12
- data/lib/chef/knife/opc_user_delete.rb +6 -6
- data/lib/chef/knife/opc_user_edit.rb +38 -13
- data/lib/chef/knife/opc_user_list.rb +16 -6
- data/lib/chef/knife/opc_user_password.rb +6 -6
- data/lib/chef/knife/opc_user_show.rb +3 -3
- data/lib/chef/org/group_operations.rb +1 -1
- data/lib/chef/org.rb +5 -5
- data/lib/knife-opc/version.rb +1 -1
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ab5d18c861be31be68d9f618c1aacf63b984cbd92880bba749013bcdfb8f4f6
|
4
|
+
data.tar.gz: 2f06594a523aee643a27caec8eeec29afb6c237b3021a1ec55cc8033e8887778
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9404db55e036c8bd2a869c3c65c542f97d0736784ad02546c7e19349421f9a497ae0422189057dad0f1f73f1e2f4e3252bfba4721c8698c308fa1f673bfc077
|
7
|
+
data.tar.gz: 327dd1ad9b5efd280aaf54546944bf48f41d455365e258813e72acf505099a0138ab7e45a006b551b518781fff5ef22b40f79a6bad80eb6ddf90f5bac4a45b74
|
@@ -22,20 +22,20 @@ module Opc
|
|
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
|
@@ -15,7 +15,7 @@
|
|
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
|
@@ -23,14 +23,14 @@ module Opc
|
|
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
|
|
@@ -23,13 +23,13 @@ module Opc
|
|
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
|
@@ -23,13 +23,13 @@ module Opc
|
|
23
23
|
attr_accessor :org_name, :username
|
24
24
|
|
25
25
|
option :force_remove_from_admins,
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
long: "--force",
|
27
|
+
short: "-f",
|
28
|
+
description: "Force removal of user from the organization's admins and billing-admins group."
|
29
29
|
|
30
30
|
deps do
|
31
|
-
|
32
|
-
|
31
|
+
require_relative "../org"
|
32
|
+
require_relative "../org/group_operations"
|
33
33
|
require "chef/json_compat"
|
34
34
|
end
|
35
35
|
|
@@ -51,7 +51,7 @@ module Opc
|
|
51
51
|
You ran with --force which force removes the user from the admins and billing-admins groups.
|
52
52
|
However, removing #{username} from the admins group would leave it empty, which breaks the org.
|
53
53
|
Please add another user to org #{org_name} admins group and try again.
|
54
|
-
EOF
|
54
|
+
EOF
|
55
55
|
exit 1
|
56
56
|
end
|
57
57
|
remove_user_from_admin_group(org, org_name, username, "admins")
|
@@ -71,7 +71,7 @@ EOF
|
|
71
71
|
ui.msg <<~EOF
|
72
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
73
|
Re-run this command with --force to remove this user from the admins prior to removing it from the organization.
|
74
|
-
EOF
|
74
|
+
EOF
|
75
75
|
exit 1
|
76
76
|
else
|
77
77
|
raise e
|
@@ -93,7 +93,7 @@ EOF
|
|
93
93
|
ui.warn <<~EOF
|
94
94
|
User #{username} is not in the #{admin_group_string} group for organization #{org_name}.
|
95
95
|
You probably don't need to pass --force.
|
96
|
-
EOF
|
96
|
+
EOF
|
97
97
|
else
|
98
98
|
raise e
|
99
99
|
end
|
@@ -15,7 +15,7 @@
|
|
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
|
@@ -23,19 +23,19 @@ module Opc
|
|
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
34
|
|
35
35
|
option :passwordprompt,
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
long: "--prompt-for-password",
|
37
|
+
short: "-p",
|
38
|
+
description: "Prompt for user password"
|
39
39
|
|
40
40
|
include Chef::Mixin::RootRestv0
|
41
41
|
|
@@ -69,7 +69,7 @@ module Opc
|
|
69
69
|
password: password,
|
70
70
|
}
|
71
71
|
|
72
|
-
|
72
|
+
# Check the file before creating the user so the api is more transactional.
|
73
73
|
if config[:filename]
|
74
74
|
file = config[:filename]
|
75
75
|
unless File.exist?(file) ? File.writable?(file) : File.writable?(File.dirname(file))
|
@@ -95,7 +95,7 @@ module Opc
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def prompt_for_password
|
98
|
-
ui.ask("Please enter the user's password: "
|
98
|
+
ui.ask("Please enter the user's password: ", echo: false)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -15,7 +15,7 @@
|
|
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 OpcUserDelete < Chef::Knife
|
@@ -36,8 +36,8 @@ module Opc
|
|
36
36
|
include Chef::Mixin::RootRestv0
|
37
37
|
|
38
38
|
deps do
|
39
|
-
|
40
|
-
|
39
|
+
require_relative "../org"
|
40
|
+
require_relative "../org/group_operations"
|
41
41
|
end
|
42
42
|
|
43
43
|
def run
|
@@ -117,7 +117,7 @@ module Opc
|
|
117
117
|
Run this command again with the --remove-from-admin-groups option to
|
118
118
|
remove the user from these admin group(s) automatically.
|
119
119
|
|
120
|
-
EOM
|
120
|
+
EOM
|
121
121
|
ui.fatal message
|
122
122
|
exit 1
|
123
123
|
end
|
@@ -128,7 +128,7 @@ EOM
|
|
128
128
|
#{username} is the only member of the 'admins' group of the
|
129
129
|
following organization(s):
|
130
130
|
|
131
|
-
EOM
|
131
|
+
EOM
|
132
132
|
only_admin_of.each { |org| message << "- #{org.name}\n" }
|
133
133
|
message << <<~EOM
|
134
134
|
|
@@ -136,7 +136,7 @@ EOM
|
|
136
136
|
Assign additional users or groups to the admin group(s) before
|
137
137
|
deleting this user.
|
138
138
|
|
139
|
-
EOM
|
139
|
+
EOM
|
140
140
|
ui.fatal message
|
141
141
|
exit 1
|
142
142
|
end
|
@@ -15,7 +15,7 @@
|
|
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 OpcUserEdit < Chef::Knife
|
@@ -23,14 +23,14 @@ module Opc
|
|
23
23
|
banner "knife opc user edit USERNAME"
|
24
24
|
|
25
25
|
option :input,
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
long: "--input FILENAME",
|
27
|
+
short: "-i FILENAME",
|
28
|
+
description: "Name of file to use for PUT or POST"
|
29
29
|
|
30
30
|
option :filename,
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
long: "--filename FILENAME",
|
32
|
+
short: "-f FILENAME",
|
33
|
+
description: "Write private key to FILENAME rather than STDOUT"
|
34
34
|
|
35
35
|
include Chef::Mixin::RootRestv0
|
36
36
|
|
@@ -44,15 +44,11 @@ module Opc
|
|
44
44
|
end
|
45
45
|
|
46
46
|
original_user = root_rest.get("users/#{user_name}")
|
47
|
-
|
48
|
-
edited_user = JSON.parse(IO.read(config[:input]))
|
49
|
-
else
|
50
|
-
edited_user = edit_data(original_user)
|
51
|
-
end
|
47
|
+
edited_user = get_updated_user(original_user)
|
52
48
|
if original_user != edited_user
|
53
49
|
result = root_rest.put("users/#{user_name}", edited_user)
|
54
50
|
ui.msg("Saved #{user_name}.")
|
55
|
-
|
51
|
+
unless result["private_key"].nil?
|
56
52
|
if config[:filename]
|
57
53
|
File.open(config[:filename], "w") do |f|
|
58
54
|
f.print(result["private_key"])
|
@@ -65,5 +61,34 @@ module Opc
|
|
65
61
|
ui.msg("User unchanged, not saving.")
|
66
62
|
end
|
67
63
|
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
# Check the options for ex: input or filename
|
68
|
+
# Read Or Open file to update user information
|
69
|
+
# return updated user
|
70
|
+
def get_updated_user(original_user)
|
71
|
+
if config[:input]
|
72
|
+
edited_user = JSON.parse(IO.read(config[:input]))
|
73
|
+
elsif config[:filename]
|
74
|
+
file = config[:filename]
|
75
|
+
unless File.exist?(file) ? File.writable?(file) : File.writable?(File.dirname(file))
|
76
|
+
ui.fatal "File #{file} is not writable. Check permissions."
|
77
|
+
exit 1
|
78
|
+
else
|
79
|
+
output = Chef::JSONCompat.to_json_pretty(original_user)
|
80
|
+
File.open(file, "w") do |f|
|
81
|
+
f.sync = true
|
82
|
+
f.puts output
|
83
|
+
f.close
|
84
|
+
raise "Please set EDITOR environment variable. See https://docs.chef.io/knife_setup/ for details." unless system("#{config[:editor]} #{f.path}")
|
85
|
+
|
86
|
+
edited_user = JSON.parse(IO.read(f.path))
|
87
|
+
end
|
88
|
+
end
|
89
|
+
else
|
90
|
+
edited_user = JSON.parse(edit_data(original_user, false))
|
91
|
+
end
|
92
|
+
end
|
68
93
|
end
|
69
94
|
end
|
@@ -15,7 +15,7 @@
|
|
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 OpcUserList < Chef::Knife
|
@@ -23,15 +23,25 @@ module Opc
|
|
23
23
|
banner "knife opc user list"
|
24
24
|
|
25
25
|
option :with_uri,
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
long: "--with-uri",
|
27
|
+
short: "-w",
|
28
|
+
description: "Show corresponding URIs"
|
29
|
+
|
30
|
+
option :all_info,
|
31
|
+
long: "--all-info",
|
32
|
+
short: "-a",
|
33
|
+
description: "Show corresponding details i.e. username, email, first_name, last_name, display_name"
|
29
34
|
|
30
35
|
include Chef::Mixin::RootRestv0
|
31
36
|
|
32
37
|
def run
|
33
|
-
|
34
|
-
|
38
|
+
if config[:all_info]
|
39
|
+
results = root_rest.get("users?verbose=true")
|
40
|
+
ui.output results
|
41
|
+
else
|
42
|
+
results = root_rest.get("users")
|
43
|
+
ui.output(ui.format_list_for_display(results))
|
44
|
+
end
|
35
45
|
end
|
36
46
|
end
|
37
47
|
end
|
@@ -15,7 +15,7 @@
|
|
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 OpcUserPassword < Chef::Knife
|
@@ -23,9 +23,9 @@ module Opc
|
|
23
23
|
banner "knife opc user password USERNAME [PASSWORD | --enable-external-auth]"
|
24
24
|
|
25
25
|
option :enable_external_auth,
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
long: "--enable-external-auth",
|
27
|
+
short: "-e",
|
28
|
+
description: "Enable external authentication for this user (such as LDAP)"
|
29
29
|
|
30
30
|
include Chef::Mixin::RootRestv0
|
31
31
|
|
@@ -34,7 +34,7 @@ module Opc
|
|
34
34
|
# USERNAME PASSWORD or USERNAME --enable-external-auth
|
35
35
|
#
|
36
36
|
# note that you can't pass USERNAME PASSWORD --enable-external-auth
|
37
|
-
|
37
|
+
unless (@name_args.length == 2 && !config[:enable_external_auth]) || (@name_args.length == 1 && config[:enable_external_auth])
|
38
38
|
show_usage
|
39
39
|
ui.fatal("You must pass two arguments")
|
40
40
|
ui.fatal("Note that --enable-external-auth cannot be passed with a password")
|
@@ -52,7 +52,7 @@ module Opc
|
|
52
52
|
# changing anything before we PUT.
|
53
53
|
user = root_rest.get("users/#{user_name}")
|
54
54
|
|
55
|
-
user["password"] = password
|
55
|
+
user["password"] = password unless password.nil?
|
56
56
|
|
57
57
|
# if --enable-external-auth was passed, enable it, else disable it.
|
58
58
|
# there is never a situation where we would want to enable ldap
|
@@ -15,7 +15,7 @@
|
|
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 OpcUserShow < Chef::Knife
|
@@ -23,8 +23,8 @@ module Opc
|
|
23
23
|
banner "knife opc user show USERNAME"
|
24
24
|
|
25
25
|
option :with_orgs,
|
26
|
-
|
27
|
-
|
26
|
+
long: "--with-orgs",
|
27
|
+
short: "-l"
|
28
28
|
|
29
29
|
include Chef::Mixin::RootRestv0
|
30
30
|
|
data/lib/chef/org.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "chef/json_compat"
|
2
2
|
require "chef/mixin/params_validate"
|
3
3
|
require "chef/server_api"
|
4
|
-
|
4
|
+
require_relative "org/group_operations"
|
5
5
|
|
6
6
|
class Chef
|
7
7
|
class Org
|
@@ -24,22 +24,22 @@ class Chef
|
|
24
24
|
|
25
25
|
def name(arg = nil)
|
26
26
|
set_or_return(:name, arg,
|
27
|
-
|
27
|
+
regex: /^[a-z0-9\-_]+$/)
|
28
28
|
end
|
29
29
|
|
30
30
|
def full_name(arg = nil)
|
31
31
|
set_or_return(:full_name,
|
32
|
-
|
32
|
+
arg, kind_of: String)
|
33
33
|
end
|
34
34
|
|
35
35
|
def private_key(arg = nil)
|
36
36
|
set_or_return(:private_key,
|
37
|
-
|
37
|
+
arg, kind_of: String)
|
38
38
|
end
|
39
39
|
|
40
40
|
def guid(arg = nil)
|
41
41
|
set_or_return(:guid,
|
42
|
-
|
42
|
+
arg, kind_of: String)
|
43
43
|
end
|
44
44
|
|
45
45
|
def to_hash
|
data/lib/knife-opc/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-opc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Danna
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Knife Tools for Chef Server
|
13
|
+
description: Knife Tools for Chef Infra Server
|
14
14
|
email: steve@chef.io
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
@@ -34,11 +34,11 @@ files:
|
|
34
34
|
- lib/chef/org.rb
|
35
35
|
- lib/chef/org/group_operations.rb
|
36
36
|
- lib/knife-opc/version.rb
|
37
|
-
homepage: https://github.com/knife-opc
|
37
|
+
homepage: https://github.com/chef/knife-opc
|
38
38
|
licenses:
|
39
39
|
- Apache-2.0
|
40
40
|
metadata: {}
|
41
|
-
post_install_message:
|
41
|
+
post_install_message:
|
42
42
|
rdoc_options: []
|
43
43
|
require_paths:
|
44
44
|
- lib
|
@@ -53,9 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
|
-
|
57
|
-
|
58
|
-
signing_key:
|
56
|
+
rubygems_version: 3.2.32
|
57
|
+
signing_key:
|
59
58
|
specification_version: 4
|
60
|
-
summary: Knife Tools for Chef Server
|
59
|
+
summary: Knife Tools for Chef Infra Server
|
61
60
|
test_files: []
|