knife-acl 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,175 @@
1
+ # knife ACL
2
+
3
+ # Description
4
+
5
+ This is an UNOFFICIAL and EXPERIMENTAL knife plugin to support basic
6
+ user/group operations for Hosted Chef. All commands assume a working
7
+ knife config for an org on Hosted Chef.
8
+
9
+ You can use these commands to manage a read-only group. To do so:
10
+
11
+ 1. Run `knife actor map` to create/update a local actor map file
12
+ `actor-map.yaml`:
13
+
14
+ knife actor map
15
+
16
+ 2. In the webUI, create a group that will hold read-only users.
17
+
18
+ 3. For each user you wish to have read only access as defined by
19
+ permissions given to the "read-only" group do the following:
20
+
21
+ knife group add actor read-only USER
22
+ knife group remove actor users USER
23
+
24
+ This adds the user to the 'read-only' group and removes them from the
25
+ 'users' group which has more permissions by default (users are
26
+ added to 'users' when added to an org).
27
+
28
+ # Installation
29
+
30
+ This knife plugin is packaged as a gem. To install it, enter the
31
+ following:
32
+
33
+ #### Gem installed chef-client on a workstation
34
+ gem install knife-acl
35
+
36
+ # or if the gem has yet to be published to Rubygems
37
+ gem build knife-acl.gemspec
38
+ gem install knife-acl-x.y.z.gem
39
+
40
+ #### Opscode hosted Enterprise Chef (OHC) with an Omnibus-installed chef-client on a workstation
41
+ /opt/chef/embedded/bin/gem install knife-acl
42
+
43
+ #### Opscode Enterprise Chef (OPC) Directly on the active backend
44
+ as root: /opt/opscode/embedded/bin/gem install knife-acl
45
+
46
+ # Subcommands
47
+
48
+ ## knife user list
49
+
50
+ Show a list of users associated with your org
51
+
52
+ ## knife actor map
53
+
54
+ Create a local map file actor-map.yaml" that maps users to their User
55
+ Specific Association Group (USAG) and stores a list of clients. USAGs
56
+ are an implementation detail that will likely be hidden or otherwise
57
+ change in the future. USAGs are currently the correct way to
58
+ add/remove users to/from groups in an org.
59
+
60
+ This command creates a local cache of the user to USAG mapping as well
61
+ as a local cache of clients and is used by the following commands:
62
+ - `knife group show`,
63
+ - `knife group add actor`, and
64
+ - `knife group remove actor`.
65
+
66
+ ## knife group list
67
+
68
+ List groups in the org.
69
+
70
+ ## knife group show GROUP
71
+
72
+ Show the details membership details for `GROUP`. If you have run
73
+ `knife actor map`, the user map file will be used to annotate USAGs so
74
+ you can see what user they represent.
75
+
76
+ ## knife group add actor GROUP ACTOR
77
+
78
+ Add ACTOR to GROUP. ACTOR can be a user name or a client
79
+ name. Requires an up-to-date actor map as created by `knife actor
80
+ map`. The user's USAG will be added as a subgroup of GROUP if ACTOR
81
+ is a user.
82
+
83
+ ## knife group remove actor GROUP ACTOR
84
+
85
+ Remove ACTOR from GROUP. Requires an up-to-date actor map as created by
86
+ `knife actor map`. The user's USAG will be removed from the subgroups
87
+ of GROUP if ACTOR is a user.
88
+
89
+ ## knife acl show OBJECT_TYPE OBJECT_NAME
90
+
91
+ Shows the ACL for the specified object. Objects are identified by the
92
+ combination of their type and name.
93
+
94
+ Valid `OBJECT_TYPE`'s are
95
+
96
+ - clients
97
+ - groups
98
+ - containers
99
+ - data
100
+ - nodes
101
+ - roles
102
+ - cookbooks
103
+ - environments
104
+
105
+ For example, use the following command to obtain the ACL for a node
106
+ named "web.example.com":
107
+
108
+ knife acl show nodes web.example.com
109
+
110
+ ## knife acl add OBJECT_TYPE OBJECT_NAME PERM [group|client] NAME
111
+
112
+ Add the group or client with NAME to the PERM access control entry of
113
+ the object. Objects are specified by the combination of
114
+ their type and name. See the `knife acl show` documentation above for
115
+ the permitted types.
116
+
117
+ Valid `PERM`s are:
118
+
119
+ - create
120
+ - read
121
+ - update
122
+ - delete
123
+ - grant
124
+
125
+ For example, use the following command to give the superuser group
126
+ the ability to delete the node called "api.example.com":
127
+
128
+ knife acl add node api.exmaple.com delete group superusers
129
+
130
+ ## knife acl remove OBJECT_TYPE OBJECT_NAME PERM [group|client] NAME
131
+
132
+ Remove group or client with NAME from the PERM access control entry of
133
+ the specified object. Objects are specified by the combination of
134
+ their type and name. See the `knife acl show` documentation above for
135
+ the permitted types. See the `knife acl add` documentation abouve for
136
+ the permitted `PERMS`s.
137
+
138
+ For example, use the following command to remove the superuser group's
139
+ ability to delete the node called "api.example.com":
140
+
141
+ knife acl remove node api.exmaple.com delete group superusers
142
+
143
+
144
+ ## TODO
145
+
146
+ - Feature: create/delete groups
147
+ - Feature: build group membership graph
148
+ - Remove duplication in commands
149
+ - Staleness detector for actor map
150
+ - Improve error messages when actor map is missing
151
+ - Don't save group if it will be a no-op
152
+
153
+ ## LICENSE
154
+
155
+ Unless otherwise specified all works in this repository are
156
+
157
+ Copyright 2013 Opscode, Inc
158
+
159
+ |||
160
+ | ------------- |-------------:|
161
+ | Author |Seth Falcon (seth@opscode.com)|
162
+ | Copyright |Copyright (c) 2013 Opscode, Inc.|
163
+ | License |Apache License, Version 2.0|
164
+
165
+ Licensed under the Apache License, Version 2.0 (the "License");
166
+ you may not use this file except in compliance with the License.
167
+ You may obtain a copy of the License at
168
+
169
+ [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0)
170
+
171
+ Unless required by applicable law or agreed to in writing, software
172
+ distributed under the License is distributed on an "AS IS" BASIS,
173
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
174
+ See the License for the specific language governing permissions and
175
+ limitations under the License.
@@ -0,0 +1,63 @@
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 OpscodeAcl
20
+ class AclAdd < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner "knife acl add OBJECT_TYPE OBJECT_NAME PERM [group|client] NAME"
23
+
24
+ attr_reader :object_type, :object_name, :perm, :actor_type, :actor_name
25
+
26
+ deps do
27
+ include OpscodeAcl::AclBase
28
+ end
29
+
30
+ def run
31
+ @object_type, @object_name, @perm, @actor_type, @actor_name = name_args
32
+
33
+ if name_args.length < 5
34
+ show_usage
35
+ ui.fatal "You must specify the object type, object name, perm, actor type (client or group), and actor name"
36
+ exit 1
37
+ end
38
+
39
+ validate_all_params!
40
+ ace = get_ace(object_type, object_name, perm)
41
+
42
+ case actor_type
43
+ when "client"
44
+ add_actor_to_ace!(actor_name, ace)
45
+ when "group"
46
+ add_group_to_ace!(actor_name, ace)
47
+ when "users"
48
+ # Not Implemented yet, we shouldn't get here.
49
+ end
50
+
51
+ update_ace!(object_type, object_name, perm, ace)
52
+ end
53
+
54
+ def add_group_to_ace!(name, ace)
55
+ ace['groups'] << name unless ace['groups'].include?(name)
56
+ end
57
+
58
+ def add_actor_to_ace!(name, ace)
59
+ ace['actors'] << name unless ace['actors'].include?(name)
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,85 @@
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 OpscodeAcl
20
+ module AclBase
21
+
22
+ PERM_TYPES = %w(create read update delete grant)
23
+ ACTOR_TYPES = %w(client group)
24
+ OBJECT_TYPES = %w(clients groups containers data nodes roles cookbooks sandboxes environments)
25
+ OBJECT_NAME_SPEC = /^[\-[:alnum:]_\.]+$/
26
+
27
+ def validate_object_type!(type)
28
+ if ! OBJECT_TYPES.include?(type)
29
+ ui.fatal "Unknown object type \"#{type}\". The following types are permitted: #{OBJECT_TYPES.join(', ')}"
30
+ exit 1
31
+ end
32
+ end
33
+
34
+ def validate_object_name!(name)
35
+ if ! OBJECT_NAME_SPEC.match(name)
36
+ ui.fatal "Invalid name: #{name}"
37
+ exit 1
38
+ end
39
+ end
40
+
41
+ def validate_actor_type!(type)
42
+ if ! ACTOR_TYPES.include?(type)
43
+ ui.fatal "Unknown actor type \"#{type}\". The following types are permitted: #{ACTOR_TYPES.join(', ')}"
44
+ exit 1
45
+ end
46
+ end
47
+
48
+ def validate_actor_name!(name)
49
+ # Same rules apply to object's and actors
50
+ validate_object_name!(name)
51
+ end
52
+
53
+ def validate_perm_type!(perm)
54
+ if ! PERM_TYPES.include?(perm)
55
+ ui.fatal "Invalid permission \"#{perm}\". The following permissions are permitted: #{PERM_TYPES.join(',')}"
56
+ exit 1
57
+ end
58
+
59
+ end
60
+
61
+ def validate_all_params!
62
+ # Helper method to valid parameters for commands that modify permisisons
63
+ # This assumes including class has the necessary accessors
64
+ # We the validation to ensure we can give the user more helpful error messages.
65
+ validate_perm_type!(perm)
66
+ validate_actor_type!(actor_type)
67
+ validate_actor_name!(actor_name)
68
+ validate_object_name!(object_name)
69
+ validate_object_type!(object_type)
70
+ end
71
+
72
+ def get_acl(object_type, object_name)
73
+ rest.get_rest("#{object_type}/#{object_name}/_acl")
74
+ end
75
+
76
+ def get_ace(object_type, object_name, perm)
77
+ get_acl(object_type, object_name)[perm]
78
+ end
79
+
80
+ def update_ace!(object_type, object_name, ace_type, ace)
81
+ rest.put_rest("#{object_type}/#{object_name}/_acl/#{ace_type}", ace_type => ace)
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,63 @@
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 OpscodeAcl
20
+ class AclRemove < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner "knife acl remove OBJECT_TYPE OBJECT_NAME PERM ACTOR_TYPE ACTOR_NAME"
23
+
24
+ attr_reader :object_type, :object_name, :perm, :actor_type, :actor_name
25
+
26
+ deps do
27
+ include OpscodeAcl::AclBase
28
+ end
29
+
30
+ def run
31
+ @object_type, @object_name, @perm, @actor_type, @actor_name = name_args
32
+
33
+ if name_args.length < 5
34
+ show_usage
35
+ ui.fatal "You must specify the object_type, object_name, perm, actor type (client or group), and actor name"
36
+ exit 1
37
+ end
38
+
39
+ validate_all_params!
40
+ ace = get_ace(object_type, object_name, perm)
41
+
42
+ case actor_type
43
+ when "client"
44
+ remove_actor_from_ace!(actor_name, ace)
45
+ when "group"
46
+ remove_group_from_ace!(actor_name, ace)
47
+ when "users"
48
+ # Not Implemented yet, we shouldn't get here.
49
+ end
50
+
51
+ update_ace!(object_type, object_name, perm, ace)
52
+ end
53
+
54
+ def remove_group_from_ace!(name, ace)
55
+ ace['groups'].delete(name)
56
+ end
57
+
58
+ def remove_actor_from_ace!(name, ace)
59
+ ace['actors'].delete(name)
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,43 @@
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 OpscodeAcl
20
+ class AclShow < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner "knife acl show OBJECT_TYPE OBJECT_NAME"
23
+
24
+ deps do
25
+ include OpscodeAcl::AclBase
26
+ end
27
+
28
+ def run
29
+ object_type, object_name = name_args
30
+
31
+ if ! object_name || ! object_type
32
+ show_usage
33
+ ui.fatal "You must specify an object type and object name"
34
+ exit 1
35
+ end
36
+
37
+ validate_object_type!(object_type)
38
+ validate_object_name!(object_name)
39
+ acl = get_acl(object_type, object_name)
40
+ ui.output acl
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,57 @@
1
+ #
2
+ # Author:: Seth Falcon (<seth@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 OpscodeAcl
20
+ class ActorMap < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner "knife actor map"
23
+
24
+ # writes a yaml file to current working directly named
25
+ # 'actor-map.yaml'
26
+ # group add/remove operations will read this file
27
+ #
28
+ deps do
29
+ require 'pp'
30
+ require 'yaml'
31
+ end
32
+
33
+ def run
34
+ chef_rest = Chef::REST.new(Chef::Config[:chef_server_url])
35
+ usags = chef_rest.get_rest("groups").keys.select do |gname|
36
+ gname.length == 32 && gname =~ /^[0-9a-f]+$/
37
+ end
38
+ user_map = {:users => {}, :usags => {}}
39
+ user_map = usags.inject(user_map) do |map, usag|
40
+ a_group = chef_rest.get_rest("groups/#{usag}")
41
+ actors = a_group["actors"]
42
+ if actors.length == 1
43
+ user_map[:users][actors.first] = usag
44
+ user_map[:usags][usag] = actors.first
45
+ end
46
+ user_map
47
+ end
48
+ clients = chef_rest.get_rest("clients").keys.inject({}) { |h, c| h[c] = c; h }
49
+ open("actor-map.yaml", "w") do |f|
50
+ f.write({ :user_map => user_map, :clients => clients }.to_yaml)
51
+ end
52
+ ui.msg "Found %d users and %d clients" % [user_map[:users].size, clients.size]
53
+ ui.msg "wrote map to 'actor-map.yaml'"
54
+ end
55
+ end
56
+ end
57
+
@@ -0,0 +1,89 @@
1
+ #
2
+ # Author:: Seth Falcon (<seth@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 OpscodeAcl
20
+ class GroupAddActor < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner "knife group add actor GROUP ACTOR"
23
+ attr_reader :actor_name, :group_name, :user_map, :clients
24
+ deps do
25
+ require 'yaml'
26
+ end
27
+
28
+ def run
29
+ if !File.exists?("actor-map.yaml")
30
+ ui.error "unable to find 'actor-map.yaml'. Run 'knife actor map' and try again."
31
+ exit 1
32
+ end
33
+ actor_map = YAML.load(IO.read("actor-map.yaml"))
34
+ @user_map = actor_map[:user_map]
35
+ @clients = actor_map[:clients]
36
+ @group_name = name_args[0]
37
+ @actor_name = name_args[1]
38
+
39
+ if !group_name || !actor_name
40
+ ui.error "must specify GROUP and ACTOR"
41
+ exit 1
42
+ end
43
+ find_actor_in_map
44
+ @chef_rest = Chef::REST.new(Chef::Config[:chef_server_url])
45
+ group = @chef_rest.get_rest("groups/#{group_name}")
46
+ save_group(group)
47
+ end
48
+
49
+ def save_group(group)
50
+ new_group = make_group_for_put(group)
51
+ @chef_rest.put_rest("groups/#{new_group["groupname"]}", new_group)
52
+ end
53
+
54
+ def make_group_for_put(existing_group)
55
+ new_group = {
56
+ "groupname" => existing_group["groupname"],
57
+ "orgname" => existing_group["orgname"],
58
+ "actors" => {
59
+ # users are added to groups via the user's USAG so we never
60
+ # modify the users directly
61
+ "users" => existing_group["users"],
62
+ "clients" => maybe_add_actor(:client, existing_group["clients"]),
63
+ "groups" => maybe_add_actor(:user, existing_group["groups"])
64
+ }
65
+ }
66
+ end
67
+
68
+ def maybe_add_actor(type, actors)
69
+ new_actors = actors.dup
70
+ if @actor_type == type && !new_actors.include?(@actor_id)
71
+ new_actors << @actor_id
72
+ end
73
+ new_actors
74
+ end
75
+
76
+ def find_actor_in_map
77
+ @actor_type, @actor_id = if user_map[:users][actor_name]
78
+ [:user, user_map[:users][actor_name]]
79
+ else
80
+ [:client, clients[actor_name]]
81
+ end
82
+ if @actor_id.nil?
83
+ ui.error("no user or client named '#{actor_name}' in actor-map.yaml")
84
+ exit 1
85
+ end
86
+ true
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,40 @@
1
+ #
2
+ # Author:: Seth Falcon (<seth@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 OpscodeAcl
20
+ class GroupCreate < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner "knife group create GROUP"
23
+
24
+ deps do
25
+ require 'yaml'
26
+ end
27
+
28
+ def run
29
+ group_name = name_args[0]
30
+ if !group_name || group_name.empty?
31
+ ui.error "must specify a group name"
32
+ exit 1
33
+ end
34
+ chef_rest = Chef::REST.new(Chef::Config[:chef_server_url])
35
+ group = chef_rest.post_rest("groups", {:groupname => group_name})
36
+ ui.output group
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,40 @@
1
+ #
2
+ # Author:: Seth Falcon (<seth@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 OpscodeAcl
20
+ class GroupList < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner "knife group list"
23
+
24
+ def run
25
+ chef_rest = Chef::REST.new(Chef::Config[:chef_server_url])
26
+ groups = chef_rest.get_rest("groups").keys.sort
27
+
28
+ ui.output(remove_usags(groups))
29
+ end
30
+
31
+ def remove_usags(groups)
32
+ groups.select { |gname| !is_usag?(gname) }
33
+ end
34
+
35
+ def is_usag?(gname)
36
+ gname.length == 32 && gname =~ /^[0-9a-f]+$/
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,86 @@
1
+ #
2
+ # Author:: Seth Falcon (<seth@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 OpscodeAcl
20
+ class GroupRemoveActor < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner "knife group remove actor GROUP ACTOR"
23
+ attr_reader :actor_name, :group_name, :user_map, :clients
24
+ deps do
25
+ require 'yaml'
26
+ end
27
+
28
+ def run
29
+ if !File.exists?("actor-map.yaml")
30
+ ui.error "unable to find 'actor-map.yaml'. Run 'knife actor map' and try again."
31
+ exit 1
32
+ end
33
+ actor_map = YAML.load(IO.read("actor-map.yaml"))
34
+ @user_map = actor_map[:user_map]
35
+ @clients = actor_map[:clients]
36
+ @group_name = name_args[0]
37
+ @actor_name = name_args[1]
38
+
39
+ if !group_name || !actor_name
40
+ ui.error "must specify GROUP and ACTOR"
41
+ exit 1
42
+ end
43
+ find_actor_in_map
44
+ @chef_rest = Chef::REST.new(Chef::Config[:chef_server_url])
45
+ group = @chef_rest.get_rest("groups/#{group_name}")
46
+ case @actor_type
47
+ when :user
48
+ group["groups"].delete(@actor_id)
49
+ group["users"].delete(actor_name)
50
+ when :client
51
+ group["clients"].delete(@actor_id)
52
+ end
53
+ save_group(group)
54
+ end
55
+
56
+ def save_group(group)
57
+ new_group = make_group_for_put(group)
58
+ @chef_rest.put_rest("groups/#{new_group["groupname"]}", new_group)
59
+ end
60
+
61
+ def make_group_for_put(existing_group)
62
+ new_group = {
63
+ "groupname" => existing_group["groupname"],
64
+ "orgname" => existing_group["orgname"],
65
+ "actors" => {
66
+ "clients" => existing_group["clients"],
67
+ "groups" => existing_group["groups"],
68
+ "users" => existing_group["users"]
69
+ }
70
+ }
71
+ end
72
+
73
+ def find_actor_in_map
74
+ @actor_type, @actor_id = if user_map[:users][actor_name]
75
+ [:user, user_map[:users][actor_name]]
76
+ else
77
+ [:client, clients[actor_name]]
78
+ end
79
+ if @actor_id.nil?
80
+ ui.error("no user or client named '#{actor_name}' in actor-map.yaml")
81
+ exit 1
82
+ end
83
+ true
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,56 @@
1
+ #
2
+ # Author:: Seth Falcon (<seth@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 OpscodeAcl
20
+ class GroupShow < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner "knife group show GROUP"
23
+
24
+ deps do
25
+ require 'pp'
26
+ require 'yaml'
27
+ end
28
+
29
+ def run
30
+ @user_map = if ::File.exists?("actor-map.yaml")
31
+ YAML.load(IO.read("actor-map.yaml"))[:user_map]
32
+ else
33
+ {:users => {}, :usags => {}}
34
+ end
35
+ group_name = name_args[0]
36
+ if !group_name || group_name.empty?
37
+ ui.error "must specify a group name"
38
+ exit 1
39
+ end
40
+ chef_rest = Chef::REST.new(Chef::Config[:chef_server_url])
41
+ group = chef_rest.get_rest("groups/#{group_name}")
42
+ ui.output(annotate_usags(group))
43
+ end
44
+
45
+ def annotate_usags(group)
46
+ annotated = group["groups"].map do |name|
47
+ user = @user_map[:usags][name] || ""
48
+ {"group_id" => name,
49
+ "user_usag" => user}
50
+ end
51
+ group["annotated_groups"] = annotated
52
+ group
53
+ end
54
+ end
55
+ end
56
+
@@ -0,0 +1,38 @@
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 OpscodeAcl
20
+ class UserDissociate < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner 'knife user dissociate USERNAMES'
23
+
24
+ def run
25
+ if name_args.length < 1
26
+ show_usage
27
+ ui.fatal("You must specify a username.")
28
+ exit 1
29
+ end
30
+ users = name_args
31
+ ui.confirm("Are you sure you want to dissociate the following users: #{users.join(', ')}")
32
+ users.each do |u|
33
+ api_endpoint = "users/#{u}"
34
+ rest.delete_rest(api_endpoint)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,40 @@
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 OpscodeAcl
20
+ class UserInviteAdd < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner 'knife user invite add USERNAMES'
23
+
24
+ def run
25
+
26
+ if name_args.length < 1
27
+ show_usage
28
+ ui.fatal("You must specify a username.")
29
+ exit 1
30
+ end
31
+
32
+ users = name_args
33
+ api_endpoint = "association_requests/"
34
+ users.each do |u|
35
+ body = {:user => u}
36
+ rest.post_rest(api_endpoint, body)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,30 @@
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 OpscodeAcl
20
+ class UserInviteList < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner 'knife user invite list'
23
+
24
+ def run
25
+ api_endpoint = "association_requests/"
26
+ invited_users = rest.get_rest(api_endpoint).map { |i| i['username'] }
27
+ ui.output(invited_users)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,59 @@
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 OpscodeAcl
20
+ class UserInviteRecind < Chef::Knife
21
+ banner 'knife user invite recind [USERNAMES] (options)'
22
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
23
+
24
+ option :all,
25
+ :short => "-a",
26
+ :long => "--all",
27
+ :description => "Recind all invites!"
28
+
29
+ def run
30
+ if name_args.length < 1 and ! config.has_key?(:all)
31
+ show_usage
32
+ ui.fatal("You must specify a username.")
33
+ exit 1
34
+ end
35
+
36
+ # To recind we need to send a DELETE to association_requests/INVITE_ID
37
+ # For user friendliness we look up the invite ID based on username.
38
+ @invites = Hash.new
39
+ usernames = name_args
40
+ rest.get_rest("association_requests").each { |i| @invites[i['username']] = i['id'] }
41
+ if config[:all]
42
+ ui.confirm("Are you sure you want to recind all association requests")
43
+ @invites.each do |u,i|
44
+ rest.delete_rest("association_requests/#{i}")
45
+ end
46
+ else
47
+ ui.confirm("Are you sure you want to recind the association requests for: #{usernames.join(', ')}")
48
+ usernames.each do |u|
49
+ if @invites.has_key?(u)
50
+ rest.delete_rest("association_requests/#{@invites[u]}")
51
+ else
52
+ ui.fatal("No association request for #{u}.")
53
+ exit 1
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,35 @@
1
+ #
2
+ # Author:: Seth Falcon (<seth@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 OpscodeAcl
20
+ class UserList < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner "knife user list"
23
+
24
+ deps do
25
+ require 'pp'
26
+ end
27
+
28
+ def run
29
+ chef_rest = Chef::REST.new(Chef::Config[:chef_server_url])
30
+ users = chef_rest.get_rest("users").map { |u| u["user"]["username"] }
31
+ pp users.sort
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,46 @@
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 OpscodeAcl
20
+ class UserShow < Chef::Knife
21
+ category "OPSCODE HOSTED CHEF ACCESS CONTROL"
22
+ banner 'knife user show [USERNAME]'
23
+
24
+ # ui.format_for_display has logic to handle displaying
25
+ # any attributes set in the config[:attribute] Array.
26
+ attrs_to_show = []
27
+ option :attribute,
28
+ :short => "-a [ATTR]",
29
+ :long => "--attribute [ATTR]",
30
+ :proc => lambda {|val| attrs_to_show << val},
31
+ :description => "Show attribute ATTR. Use multiple times to show multiple attributes."
32
+
33
+ def run
34
+ if name_args.length < 1
35
+ show_usage
36
+ ui.fatal "You must specify a username."
37
+ exit 1
38
+ end
39
+
40
+ username = name_args[0]
41
+ api_endpoint = "users/#{username}"
42
+ user = rest.get_rest(api_endpoint)
43
+ ui.output(ui.format_for_display(user))
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module KnifeACL
2
+ VERSION = "0.0.10"
3
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-acl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.10
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Seth Falcon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ACL Knife Tools for Opscode hosted Enterprise Chef/Enterprise Chef
15
+ email: support@opscode.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README.md
20
+ - LICENSE
21
+ files:
22
+ - LICENSE
23
+ - README.md
24
+ - lib/chef/knife/acl_add.rb
25
+ - lib/chef/knife/acl_base.rb
26
+ - lib/chef/knife/acl_remove.rb
27
+ - lib/chef/knife/acl_show.rb
28
+ - lib/chef/knife/actor_map.rb
29
+ - lib/chef/knife/group_add_actor.rb
30
+ - lib/chef/knife/group_create.rb
31
+ - lib/chef/knife/group_list.rb
32
+ - lib/chef/knife/group_remove_actor.rb
33
+ - lib/chef/knife/group_show.rb
34
+ - lib/chef/knife/user_dissociate.rb
35
+ - lib/chef/knife/user_invite_add.rb
36
+ - lib/chef/knife/user_invite_list.rb
37
+ - lib/chef/knife/user_invite_recind.rb
38
+ - lib/chef/knife/user_list.rb
39
+ - lib/chef/knife/user_show.rb
40
+ - lib/knife-acl/version.rb
41
+ homepage: http://docs.opscode.com
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.25
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: ACL Knife Tools for Opscode hosted Enterprise Chef/Enterprise Chef
65
+ test_files: []