Class: Fhcap::Tasks::Chef::Server::CreateUser
- Inherits:
-
ChefTaskBase
- Object
- TaskBase
- ChefTaskBase
- Fhcap::Tasks::Chef::Server::CreateUser
- Defined in:
- lib/fhcap/tasks/chef/server/create_user.rb
Instance Attribute Summary collapse
-
#chef_server_version ⇒ Object
readonly
Returns the value of attribute chef_server_version.
-
#user_config ⇒ Object
readonly
Returns the value of attribute user_config.
Attributes inherited from TaskBase
#config, #options, #thor, #verbose
Instance Method Summary collapse
-
#initialize(options) ⇒ CreateUser
constructor
A new instance of CreateUser.
- #run ⇒ Object
Methods inherited from ChefTaskBase
#knife_config_dir, #knife_config_file_for, #run_chef_client_cmd, #run_knife_cmd, #run_knife_ssh_cmd
Methods inherited from TaskBase
#ask_config, #color_pad, #exit_with_error, #set_color, #suppress_stdout, #table_header, #table_row, #with_progress
Methods included from KnifeHelper
#chef_server_config_for, #chef_server_config_hash_for, #chef_server_names, #knife_config, #knife_config_dir, #knife_config_file_for
Methods included from ProvidersHelper
#provider_availability_zones, #provider_config, #provider_credentials, #provider_for, #provider_names, #provider_names_for, #provider_regions, #provider_type, #providers_config
Methods included from ReposHelper
#find_cluster, #find_cluster_pwds, #find_cluster_pwds_with_repo, #find_cluster_with_repo, #find_data_bag, #find_data_bag_item, #find_environment, #find_repo_item, #find_role, #get_cookbook_deps, #get_cookbook_meta, #get_cookbook_versions, #get_cookbooks, #get_entry_dependencies, #get_modified_cookbooks, #is_dirty?, #modified?, #repo_cfg, #repo_clusters_dir, #repo_cookbook_paths, #repo_dir, #repo_names, #repo_paths, #repos_config, #repos_dir, #run_inside_repo_dir
Methods included from FhcapHelper
Constructor Details
#initialize(options) ⇒ CreateUser
Returns a new instance of CreateUser.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fhcap/tasks/chef/server/create_user.rb', line 13 def initialize() super @chef_server_version = [:'chef-server-version'] || 'osc' @user_config = { chef_server: [:'chef-server'], username: [:username], display_name: [:'display-name'] || @username, first_name: [:'first-name'] || @username, last_name: [:'last-name'] || @username, email: [:email], password: [:password] || SecureRandom.urlsafe_base64(6), validation_client_name: @validation_client_name, } end |
Instance Attribute Details
#chef_server_version ⇒ Object (readonly)
Returns the value of attribute chef_server_version.
11 12 13 |
# File 'lib/fhcap/tasks/chef/server/create_user.rb', line 11 def chef_server_version @chef_server_version end |
#user_config ⇒ Object (readonly)
Returns the value of attribute user_config.
11 12 13 |
# File 'lib/fhcap/tasks/chef/server/create_user.rb', line 11 def user_config @user_config end |
Instance Method Details
#run ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fhcap/tasks/chef/server/create_user.rb', line 28 def run thor.say "Knife::CreateUser", :yellow ask_config(required_config, user_config) if @chef_server_version == 'osc' cmd = "osc_user create #{user_config[:username]} -p #{user_config[:password]} -y -d -a" else cmd = "user create #{user_config[:username]} #{user_config[:display_name]} #{user_config[:first_name]} #{user_config[:last_name]} #{user_config[:email]} #{user_config[:password]} -y" end import_cfg = {} #ToDo [RHMAP-2898] Use knife object private_key = run_knife_cmd(cmd, user_config[:chef_server]) if $?.exitstatus == 0 knife_config_dir = config[:knife_dir] || File.join(config.default_dir, '.chef') knife_config_file = File.join(knife_config_dir, "knife-#{user_config[:chef_server]}.rb") ::Chef::Config.from_file(knife_config_file) file = File.open(::Chef::Config[:validation_key], "rb") validation_key = file.read import_cfg[:chef_server_url] = ::Chef::Config[:chef_server_url] import_cfg[:validation_client_name] = ::Chef::Config[:validation_client_name] import_cfg[:node_name] = user_config[:username] import_cfg[:private_key] = private_key import_cfg[:validation_key] = validation_key import_file = File.join(config.tmp_dir,"#{user_config[:username]}-#{user_config[:chef_server]}_import.json") thor.create_file(import_file, JSON.pretty_generate(import_cfg), :force => true) table_contents = [table_header('Username', 'Password', 'Chef Server URL')] table_contents << table_row(user_config[:username], user_config[:password], ::Chef::Config[:chef_server_url]) thor.print_table table_contents table_contents = [table_header('Private Key')] table_contents << table_row(private_key) thor.print_table table_contents table_contents = [table_header('Validation Key')] table_contents << table_row(validation_key) thor.print_table table_contents thor.say_status 'warning', "The validation key shown above is the validation key used by you for '#{user_config[:chef_server]}'. If you don't normally share this key between users, you should create a new one manually for '#{user_config[:username]}'", :yellow thor.say_status 'Import Command:', "fhcap knife add --name #{user_config[:chef_server]} --import-file #{import_file}", :cyan end end |