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
@@ -1,19 +1,59 @@
|
|
1
|
-
|
1
|
+
require_relative "../org"
|
2
2
|
|
3
3
|
class Chef
|
4
4
|
class Org
|
5
5
|
module GroupOperations
|
6
|
+
def group(groupname)
|
7
|
+
@group ||= {}
|
8
|
+
@group[groupname] ||= chef_rest.get_rest "organizations/#{name}/groups/#{groupname}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def user_member_of_group?(username, groupname)
|
12
|
+
group = group(groupname)
|
13
|
+
group["actors"].include? username
|
14
|
+
end
|
15
|
+
|
6
16
|
def add_user_to_group(groupname, username)
|
7
|
-
group =
|
17
|
+
group = group(groupname)
|
8
18
|
body_hash = {
|
9
|
-
:
|
10
|
-
:
|
19
|
+
groupname: "#{groupname}",
|
20
|
+
actors: {
|
11
21
|
"users" => group["actors"].concat([username]),
|
12
|
-
"groups" => group["groups"]
|
13
|
-
}
|
22
|
+
"groups" => group["groups"],
|
23
|
+
},
|
14
24
|
}
|
15
25
|
chef_rest.put_rest "organizations/#{name}/groups/#{groupname}", body_hash
|
16
26
|
end
|
27
|
+
|
28
|
+
def remove_user_from_group(groupname, username)
|
29
|
+
group = group(groupname)
|
30
|
+
group["actors"].delete(username)
|
31
|
+
body_hash = {
|
32
|
+
groupname: "#{groupname}",
|
33
|
+
actors: {
|
34
|
+
"users" => group["actors"],
|
35
|
+
"groups" => group["groups"],
|
36
|
+
},
|
37
|
+
}
|
38
|
+
chef_rest.put_rest "organizations/#{name}/groups/#{groupname}", body_hash
|
39
|
+
end
|
40
|
+
|
41
|
+
def actor_delete_would_leave_admins_empty?
|
42
|
+
admins = group("admins")
|
43
|
+
if admins["groups"].empty?
|
44
|
+
# exclude 'pivotal' but don't mutate the group since we're caching it
|
45
|
+
if admins["actors"].include? "pivotal"
|
46
|
+
admins["actors"].length <= 2
|
47
|
+
else
|
48
|
+
admins["actors"].length <= 1
|
49
|
+
end
|
50
|
+
else
|
51
|
+
# We don't check recursively. If the admins group contains a group,
|
52
|
+
# and the user is the only member of that group,
|
53
|
+
# we'll still turn up a 'safe to delete'.
|
54
|
+
false
|
55
|
+
end
|
56
|
+
end
|
17
57
|
end
|
18
58
|
include Chef::Org::GroupOperations
|
19
59
|
end
|
data/lib/knife-opc/version.rb
CHANGED
metadata
CHANGED
@@ -1,81 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-opc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Danna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: chef
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: sdoc
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
description: Knife Tools for Opscode Chef Server
|
70
|
-
email: steve@opscode.com
|
11
|
+
date: 2020-09-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Knife Tools for Chef Server
|
14
|
+
email: steve@chef.io
|
71
15
|
executables: []
|
72
16
|
extensions: []
|
73
|
-
extra_rdoc_files:
|
74
|
-
- README.md
|
75
|
-
- LICENSE
|
17
|
+
extra_rdoc_files: []
|
76
18
|
files:
|
77
19
|
- LICENSE
|
78
|
-
- README.md
|
79
20
|
- lib/chef/knife/opc_org_create.rb
|
80
21
|
- lib/chef/knife/opc_org_delete.rb
|
81
22
|
- lib/chef/knife/opc_org_edit.rb
|
@@ -93,8 +34,9 @@ files:
|
|
93
34
|
- lib/chef/org.rb
|
94
35
|
- lib/chef/org/group_operations.rb
|
95
36
|
- lib/knife-opc/version.rb
|
96
|
-
homepage:
|
97
|
-
licenses:
|
37
|
+
homepage: https://github.com/knife-opc
|
38
|
+
licenses:
|
39
|
+
- Apache-2.0
|
98
40
|
metadata: {}
|
99
41
|
post_install_message:
|
100
42
|
rdoc_options: []
|
@@ -111,10 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
53
|
- !ruby/object:Gem::Version
|
112
54
|
version: '0'
|
113
55
|
requirements: []
|
114
|
-
|
115
|
-
rubygems_version: 2.4.4
|
56
|
+
rubygems_version: 3.0.3
|
116
57
|
signing_key:
|
117
58
|
specification_version: 4
|
118
|
-
summary: Knife Tools for
|
59
|
+
summary: Knife Tools for Chef Server
|
119
60
|
test_files: []
|
120
|
-
has_rdoc:
|
data/README.md
DELETED
@@ -1,183 +0,0 @@
|
|
1
|
-
# knife OPC #
|
2
|
-
|
3
|
-
* Documentation: http://docs.opscode.com/
|
4
|
-
* Tickets/Issues: http://tickets.opscode.com
|
5
|
-
* IRC: [#chef](irc://irc.freenode.net/chef) and [#chef-hacking](irc://irc.freenode.net/chef-hacking) on Freenode
|
6
|
-
* Mailing list: http://lists.opscode.com
|
7
|
-
|
8
|
-
# Description
|
9
|
-
|
10
|
-
This knife plugin supports basic organization and user operations in
|
11
|
-
Enterprise Chef (formerly Opscode Private Chef) and Chef Server 12.
|
12
|
-
|
13
|
-
# Installation
|
14
|
-
|
15
|
-
This knife plugin is packaged as a gem. To install it, run:
|
16
|
-
|
17
|
-
gem install knife-opc
|
18
|
-
|
19
|
-
If you are using ChefDK, run:
|
20
|
-
|
21
|
-
chef gem install knife-opc
|
22
|
-
|
23
|
-
## Development version
|
24
|
-
|
25
|
-
To install the latest development version:
|
26
|
-
|
27
|
-
git clone https://github.com/opscode/knife-opc.git
|
28
|
-
cd knife-opc
|
29
|
-
gem build knife-opc.gemspec
|
30
|
-
gem install knife-opc-0.3.2.gem
|
31
|
-
|
32
|
-
# Configuration
|
33
|
-
|
34
|
-
## knife.rb
|
35
|
-
Unlike other knife subcommands the subcommands in the knife-opc
|
36
|
-
plugin make API calls against the root of your OPC installations API
|
37
|
-
endpoint.
|
38
|
-
|
39
|
-
Typically the chef_server_url for your OPC installation may look like
|
40
|
-
this:
|
41
|
-
|
42
|
-
chef_server_url https://chef.yourdomain.com/organizations/ORGNAME
|
43
|
-
|
44
|
-
To configure knife-opc, set the `chef_server_root` option to the root
|
45
|
-
of your OPC installation:
|
46
|
-
|
47
|
-
chef_server_root https://chef.yourdomain.com/
|
48
|
-
|
49
|
-
Note that most users in an OPC installation lack the permissions to
|
50
|
-
run most of the commands from this plugin. On Chef Server 12, the
|
51
|
-
majority of the commands provided by this plugin can be accessed via
|
52
|
-
`chef-server-ctl` wrapper commands that properly configure knife-opc
|
53
|
-
for administrative action. We recommend you use the wrapper commands
|
54
|
-
whenever possible
|
55
|
-
|
56
|
-
When using knife-opc directly, many of the commands require special
|
57
|
-
permissions. For instance, in order to use commands such as `knife opc
|
58
|
-
org create`, you must authenticate as the 'pivotal' user.
|
59
|
-
|
60
|
-
Note that the key for the pivotal user is in /etc/opscode on any node
|
61
|
-
in your Chef Server cluster. We recommend that you only use the
|
62
|
-
pivotal user from a Chef Server itself and not copy this key off the
|
63
|
-
machine. In that case, you should run knife opc on the **Frontend
|
64
|
-
server** as root, with a `knife.rb` in root's home directory.
|
65
|
-
|
66
|
-
current_dir = File.dirname(__FILE__)
|
67
|
-
log_level :info
|
68
|
-
log_location STDOUT
|
69
|
-
node_name "pivotal"
|
70
|
-
client_key "/etc/opscode/pivotal.pem"
|
71
|
-
chef_server_root "https://chef.yourdomain.com/"
|
72
|
-
|
73
|
-
# Subcommands
|
74
|
-
|
75
|
-
## knife opc user list (options)
|
76
|
-
|
77
|
-
*Options*
|
78
|
-
|
79
|
-
* `-w`, `--with-uri`:
|
80
|
-
Show corresponding URIs
|
81
|
-
|
82
|
-
Show a list of all users in your OPC installation.
|
83
|
-
|
84
|
-
## knife opc user show USERNAME (options)
|
85
|
-
|
86
|
-
* `-l`, `--with-orgs`:
|
87
|
-
Show the organizations of which the user is a member.
|
88
|
-
|
89
|
-
Shows the details of a user in your OPC installation.
|
90
|
-
|
91
|
-
## knife opc user create USERNAME FIRST_NAME [MIDDLE_NAME] LAST_NAME EMAIL PASSWORD (options)
|
92
|
-
|
93
|
-
* `-f FILENAME`, `--filename FILENAME`:
|
94
|
-
Write private key to FILENAME rather than STDOUT.
|
95
|
-
|
96
|
-
Creates a new user in your OPC installation. The user's private key
|
97
|
-
will be returned in response. Without this key, the user will need to
|
98
|
-
log into the WebUI and regenerate their key before they can use knife.
|
99
|
-
|
100
|
-
## knife opc user delete USERNAME [-d]
|
101
|
-
|
102
|
-
Deletes the given OPC user.
|
103
|
-
|
104
|
-
## knife opc user edit USERNAME
|
105
|
-
|
106
|
-
Will open $EDITOR. When finished, Knife will update the given OPC user.
|
107
|
-
|
108
|
-
## knife opc user password USERNAME [PASSWORD | --enable_external_auth]
|
109
|
-
|
110
|
-
Command for managing password and authentication for a user.
|
111
|
-
|
112
|
-
The last argument should either be a string you want the password to or you can pass --enable_external_auth instead of a password to enable external authentication for this user.
|
113
|
-
|
114
|
-
## knife opc org list
|
115
|
-
|
116
|
-
* `-w`, `--with-uri`:
|
117
|
-
Show corresponding URIs
|
118
|
-
|
119
|
-
* `-a`, `--all-orgs`:
|
120
|
-
Display hidden orgs
|
121
|
-
|
122
|
-
Show a list of all organizations in your OPC installation.
|
123
|
-
|
124
|
-
## knife opc org show ORG_NAME
|
125
|
-
|
126
|
-
Shows description of given ORG_NAME.
|
127
|
-
|
128
|
-
## knife opc org create ORG_NAME ORG_FULL_NAME
|
129
|
-
|
130
|
-
* `-f FILENAME`, `--filename FILENAME`:
|
131
|
-
Write private key to FILENAME rather than STDOUT.
|
132
|
-
|
133
|
-
* `-a USERNAME`, `--association_user USERNAME`,
|
134
|
-
Associate USERNAME with the organization after creation.
|
135
|
-
|
136
|
-
Creates a new OPC Organization. The private key for the organization's
|
137
|
-
validator client is returned.
|
138
|
-
|
139
|
-
## knife opc org delete ORG_NAME
|
140
|
-
|
141
|
-
Deletes the given OPC organization.
|
142
|
-
|
143
|
-
## knife opc org user add ORGNAME USERNAME
|
144
|
-
|
145
|
-
Adds a user to an organization. Requires that the named organization
|
146
|
-
and user both exist.
|
147
|
-
|
148
|
-
## knife opc org user remove ORGNAME USERNAME
|
149
|
-
|
150
|
-
Removes a user from an organization. Requires that the named
|
151
|
-
organization and user both exist, and that the user is currently
|
152
|
-
associated with the organization.
|
153
|
-
|
154
|
-
# KNOWN ISSUES
|
155
|
-
|
156
|
-
* Attempting to delete and immediately recreate an organization will
|
157
|
-
result in an error (a 500 or a 409 Conflict depending on the server
|
158
|
-
version). This is because of a server-side cache that must be
|
159
|
-
cleared. Restarting the frontend services before recreating the org
|
160
|
-
is necessary to avoid the error.
|
161
|
-
|
162
|
-
# TODO
|
163
|
-
|
164
|
-
* `--with-users` option for `org show` subcommand.
|
165
|
-
|
166
|
-
## License ##
|
167
|
-
|
168
|
-
| | |
|
169
|
-
|:---------------------|:-----------------------------------------|
|
170
|
-
| **Copyright:** | Copyright (c) 2011-2014 Opscode, Inc.
|
171
|
-
| **License:** | Apache License, Version 2.0
|
172
|
-
|
173
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
174
|
-
you may not use this file except in compliance with the License.
|
175
|
-
You may obtain a copy of the License at
|
176
|
-
|
177
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
178
|
-
|
179
|
-
Unless required by applicable law or agreed to in writing, software
|
180
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
181
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
182
|
-
See the License for the specific language governing permissions and
|
183
|
-
limitations under the License.
|