Class: Sfn::Command::Conf

Inherits:
Sfn::Command show all
Includes:
Sfn::CommandModule::Base
Defined in:
lib/sfn/command/conf.rb

Overview

Config command

Constant Summary collapse

SFN_CONFIG_CONTENTS =
"# This is an auto-generated configuration file for\n# the sfn CLI. To view all available configuration\n# options, please see:\n# http://www.sparkleformation.io/docs/sfn/configuration.html\nConfiguration.new do\n  #   Set style of stack nesting\n  apply_nesting 'deep'\n  #   Enable processing of SparkleFormation templates\n  processing true\n  #   Provider specific options used when creating\n  #   new stacks. Options defined here are AWS specific.\n  options do\n    on_failure 'nothing'\n    notification_topics []\n    capabilities ['CAPABILITY_IAM']\n    tags do\n      creator ENV['USER']\n    end\n  end\n  #   Name of bucket in object store to hold nested\n  #   stack templates\n  # nesting_bucket 'BUCKET_NAME'\n  #   Prefix used on generated template path prior to storage\n  #   in the object store\n  # nesting_prefix 'nested-templates'\n  #   Remote provider credentials\n  credentials do\n    #  Remote provider name (:aws, :azure, :google, :open_stack, :rackspace)\n    provider :aws\n    #  AWS credentials information\n    aws_access_key_id ENV['AWS_ACCESS_KEY_ID']\n    aws_secret_access_key ENV['AWS_SECRET_ACCESS_KEY']\n    aws_region ENV['AWS_REGION']\n    aws_bucket_region ENV['AWS_REGION']\n    # aws_sts_role_arn ENV['AWS_STS_ROLE_ARN']\n    #  Eucalyptus related additions\n    # api_endpoint ENV['EUCA_ENDPOINT']\n    # euca_compat 'path'\n    # ssl_enabled false\n    #  Azure credentials information\n    azure_tenant_id ENV['AZURE_TENANT_ID']\n    azure_client_id ENV['AZURE_CLIENT_ID']\n    azure_subscription_id ENV['AZURE_SUBSCRIPTION_ID']\n    azure_client_secret ENV['AZURE_CLIENT_SECRET']\n    azure_region ENV['AZURE_REGION']\n    azure_blob_account_name ENV['AZURE_BLOB_ACCOUNT_NAME']\n    azure_blob_secret_key ENV['AZURE_BLOB_SECRET_KEY']\n    #  Defaults to \"miasma-orchestration-templates\"\n    azure_root_orchestration_container ENV['AZURE_ROOT_ORCHESTRATION_CONTAINER']\n    #  OpenStack credentials information\n    open_stack_identity_url ENV['OPENSTACK_IDENTITY_URL']\n    open_stack_username ENV['OPENSTACK_USERNAME']\n    open_stack_user_id ENV['OPENSTACK_USER_ID']\n    open_stack_password ENV['OPENSTACK_PASSWORD']\n    open_stack_token ENV['OPENSTACK_TOKEN']\n    open_stack_region ENV['OPENSTACK_REGION']\n    open_stack_tenant_name ENV['OPENSTACK_TENANT_NAME']\n    open_stack_domain ENV['OPENSTACK_DOMAIN']\n    open_stack_project ENV['OPENSTACK_PROJECT']\n    #  Rackspace credentials information\n    rackspace_api_key ENV['RACKSPACE_API_KEY']\n    rackspace_username ENV['RACKSPACE_USERNAME']\n    rackspace_region ENV['RACKSPACE_REGION']\n    #  Google Cloud Deployment Manager credentials\n    google_service_account_email ENV['GOOGLE_SERVICE_ACCOUNT_EMAIL']\n    google_service_account_private_key ENV['GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY']\n    google_project ENV['GOOGLE_PROJECT']\n  end\nend\n"

Constants inherited from Sfn::Command

CONFIG_BASE_NAME, VALID_CONFIG_EXTENSIONS

Instance Method Summary collapse

Methods included from Sfn::CommandModule::Base

included

Methods inherited from Sfn::Command

#config, #initialize

Methods included from Sfn::CommandModule::Callbacks

#api_action!, #callbacks_for, #run_callbacks_for

Constructor Details

This class inherits a constructor from Sfn::Command

Instance Method Details

#execute!Object

Run the list command



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sfn/command/conf.rb', line 11

def execute!
  ui.info ui.color("Current configuration state:")
  Config::Conf.attributes.sort_by(&:first).each do |k, val|
    if(config.has_key?(k))
      ui.print "  #{ui.color(k, :bold, :green)}: "
      format_value(config[k], '  ')
    end
  end
  if(config[:generate])
    ui.puts
    ui.info 'Generating .sfn configuration file..'
    generate_config!
    ui.info "Generation of .sfn configuration file #{ui.color('complete!', :green, :bold)}"
  end
end

#format_value(value, indent = '') ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sfn/command/conf.rb', line 40

def format_value(value, indent='')
  if(value.is_a?(Hash))
    ui.puts
    value.sort_by(&:first).each do |k,v|
      ui.print "#{indent}  #{ui.color(k, :bold)}: "
      format_value(v, indent + '  ')
    end
  elsif(value.is_a?(Array))
    ui.puts
    value.map(&:to_s).sort.each do |v|
      ui.print "#{indent}  "
      format_value(v, indent + '  ')
    end
  else
    ui.puts value.to_s
  end
end

#generate_config!Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sfn/command/conf.rb', line 27

def generate_config!
  if(File.exists?('.sfn'))
    ui.warn 'Existing .sfn configuration file detected!'
    ui.confirm 'Overwrite current .sfn configuration file?'
  end
  run_action 'Writing .sfn file' do
    File.open('.sfn', 'w') do |file|
      file.write SFN_CONFIG_CONTENTS
    end
    nil
  end
end