module Formatron::CLI::Generators::Bootstrap
CLI
command for bootstrap generator rubocop:disable Metrics/ModuleLength
Public Instance Methods
bootstrap_action(c)
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/formatron/cli/generators/bootstrap.rb, line 227 def bootstrap_action(c) c.action do |_args, options| directory = bootstrap_directory options Formatron::Generators::Bootstrap.generate( directory, bootstrap_params(options, directory) ) end end
bootstrap_availability_zone(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 132 def bootstrap_availability_zone(options) options.availability_zone || ask('Availability Zone? ') end
bootstrap_cookbooks_bucket_prefix(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 136 def bootstrap_cookbooks_bucket_prefix(options) options.cookbooks_bucket_prefix || ask( 'Chef Server Cookbooks Bucket Prefix? ' ) do |q| q.default = "#{options.s3_bucket}-cookbooks" end end
bootstrap_directory(options)
click to toggle source
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength
# File lib/formatron/cli/generators/bootstrap.rb, line 104 def bootstrap_directory(options) options.directory || ask('Directory? ') do |q| q.default = Dir.pwd end end
bootstrap_ec2_key_pair(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 124 def bootstrap_ec2_key_pair(options) options.ec2_key_pair || ask('EC2 Key Pair? ') end
bootstrap_email(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 162 def bootstrap_email(options) options.email || ask('Chef Server User Email? ') end
bootstrap_first_name(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 166 def bootstrap_first_name(options) options.first_name || ask('Chef Server User First Name? ') end
bootstrap_formatron_command()
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 237 def bootstrap_formatron_command command :'generate bootstrap' do |c| c.syntax = 'formatron generate bootstrap [options]' c.summary = 'Generate a bootstrap configuration' c.description = 'Generate a bootstrap configuration' bootstrap_options c bootstrap_action c end end
bootstrap_hosted_zone_id(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 128 def bootstrap_hosted_zone_id(options) options.hosted_zone_id || ask('Hosted Zone ID? ') end
bootstrap_kms_key(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 120 def bootstrap_kms_key(options) options.kms_key || ask('KMS Key? ') end
bootstrap_last_name(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 170 def bootstrap_last_name(options) options.last_name || ask('Chef Server User Last Name? ') end
bootstrap_name(options, directory)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 110 def bootstrap_name(options, directory) options.name || ask('Name? ') do |q| q.default = File.basename directory end end
bootstrap_options(c)
click to toggle source
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
# File lib/formatron/cli/generators/bootstrap.rb, line 11 def bootstrap_options(c) c.option '-n', '--name STRING', 'The name for the configuration' c.option( '-s', '--s3-bucket STRING', 'The S3 bucket to store encrypted configuration' ) c.option( '-k', '--kms-key STRING', 'The KMS key to use for encryption' ) c.option( '-e', '--ec2-key-pair STRING', 'The EC2 key pair to associate with EC2 instances' ) c.option( '-z', '--hosted-zone-id STRING', 'The Route53 Hosted Zone ID for the public hosted zone' ) c.option( '-a', '--availability-zone STRING', 'The AWS availability zone letter (region is already taken ' \ 'from the AWS credentials)' ) c.option( '-b', '--cookbooks-bucket-prefix STRING', 'Used to generate target specific S3 bucket names ' \ '(PREFIX-TARGET) for the Chef Server to store its ' \ 'cookbook library' ) c.option( '-o', '--organization-short-name STRING', 'The short name of the organization to create on the ' \ 'Chef Server (should not contain spaces, etc)' ) c.option( '-w', '--organization-full-name STRING', 'The full name of the organization to create on the Chef Server' ) c.option( '-u', '--username STRING', 'The username to create on the Chef Server' ) c.option( '-p', '--password STRING', 'The password for the Chef Server user' ) c.option( '-m', '--email STRING', 'The email address for the Chef Server user' ) c.option( '-f', '--first-name STRING', 'The first name of the Chef Server user' ) c.option( '-l', '--last-name STRING', 'The last name of the Chef Server user' ) c.option( '-i', '--instance-cookbook STRING', 'The instance cookbook to apply additional ' \ 'configuration to the Chef Server' ) c.option( '-x', '--protected-targets LIST', Array, 'The protected targets (eg. production)' ) c.option( '-q', '--unprotected-targets LIST', Array, 'The unprotected targets (eg. test)' ) end
bootstrap_organization_full_name(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 149 def bootstrap_organization_full_name(options) options.organization_full_name || ask('Chef Server Organization Full Name? ') end
bootstrap_organization_short_name(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 144 def bootstrap_organization_short_name(options) options.organization_short_name || ask('Chef Server Organization Short Name? ') end
bootstrap_params(options, directory)
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/formatron/cli/generators/bootstrap.rb, line 201 def bootstrap_params(options, directory) { name: bootstrap_name(options, directory), s3_bucket: bootstrap_s3_bucket(options), kms_key: bootstrap_kms_key(options), ec2_key_pair: bootstrap_ec2_key_pair(options), hosted_zone_id: bootstrap_hosted_zone_id(options), availability_zone: bootstrap_availability_zone(options), chef_server: { cookbooks_bucket_prefix: bootstrap_cookbooks_bucket_prefix(options), organization: { short_name: bootstrap_organization_short_name(options), full_name: bootstrap_organization_full_name(options) }, username: bootstrap_username(options), password: bootstrap_password(options), email: bootstrap_email(options), first_name: bootstrap_first_name(options), last_name: bootstrap_last_name(options) }, targets: bootstrap_targets(options) } end
bootstrap_password(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 158 def bootstrap_password(options) options.password || password('Chef Server Password? ') end
bootstrap_protected_targets(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 174 def bootstrap_protected_targets(options) options.protected_targets || ask('Protected Targets? ', Array) do |q| q.default = 'production' end end
bootstrap_s3_bucket(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 116 def bootstrap_s3_bucket(options) options.s3_bucket || ask('S3 Bucket? ') end
bootstrap_targets(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 187 def bootstrap_targets(options) protected_targets = bootstrap_protected_targets options unprotected_targets = bootstrap_unprotected_targets options targets = {} protected_targets.each do |target| targets[target.to_sym] = { protect: true } end unprotected_targets.each do |target| targets[target.to_sym] = { protect: false } end targets end
bootstrap_unprotected_targets(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 180 def bootstrap_unprotected_targets(options) options.unprotected_targets || ask('Unprotected Targets? ', Array) do |q| q.default = 'test' end end
bootstrap_username(options)
click to toggle source
# File lib/formatron/cli/generators/bootstrap.rb, line 154 def bootstrap_username(options) options.username || ask('Chef Server Username? ') end