summaryrefslogtreecommitdiff
path: root/knife/lib/chef/knife/org_user_add.rb
diff options
context:
space:
mode:
authorMarc A. Paradise <marc.paradise@gmail.com>2021-03-08 15:03:46 -0500
committerMarc A. Paradise <marc.paradise@gmail.com>2021-03-10 12:56:36 -0500
commitbefdb8dc5f2df3058d96dd45e7859f1d47a21947 (patch)
treed3388cb89b9acfc4d269651651f8f3c33027cc1c /knife/lib/chef/knife/org_user_add.rb
parente0b289ab53c407d8448ac7f312102a1415ee71e2 (diff)
downloadchef-befdb8dc5f2df3058d96dd45e7859f1d47a21947.tar.gz
knife lib file moves - see msg for git log info
To see the complete history for these files, use 'git log --follow', or use 'git config log.follow true' to make it the default behavior in this repository; or 'git config --global log.follow true' to make it the global default. Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
Diffstat (limited to 'knife/lib/chef/knife/org_user_add.rb')
-rw-r--r--knife/lib/chef/knife/org_user_add.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/knife/lib/chef/knife/org_user_add.rb b/knife/lib/chef/knife/org_user_add.rb
new file mode 100644
index 0000000000..cd0ea88d56
--- /dev/null
+++ b/knife/lib/chef/knife/org_user_add.rb
@@ -0,0 +1,62 @@
+#
+# Author:: Marc Paradise (<marc@chef.io>)
+# Copyright:: Copyright (c) Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class Chef
+ class Knife
+ class OrgUserAdd < Knife
+ category "CHEF ORGANIZATION MANAGEMENT"
+ banner "knife org user add ORG_NAME USER_NAME"
+ attr_accessor :org_name, :username
+
+ option :admin,
+ long: "--admin",
+ short: "-a",
+ description: "Add user to admin group"
+
+ deps do
+ require_relative "../org"
+ end
+
+ def run
+ @org_name, @username = @name_args
+
+ if !org_name || !username
+ ui.fatal "You must specify an ORG_NAME and USER_NAME"
+ show_usage
+ exit 1
+ end
+
+ org = Chef::Org.new(@org_name)
+ begin
+ org.associate_user(@username)
+ rescue Net::HTTPServerException => e
+ if e.response.code == "409"
+ ui.msg "User #{username} already associated with organization #{org_name}"
+ else
+ raise e
+ end
+ end
+ if config[:admin]
+ org.add_user_to_group("admins", @username)
+ org.add_user_to_group("billing-admins", @username)
+ ui.msg "User #{username} is added to admins and billing-admins group"
+ end
+ end
+ end
+ end
+end