Class: Dev::Template::Application::Config
- Inherits:
-
Dev::Template::ApplicationInterface
- Object
- BaseInterface
- Dev::Template::ApplicationInterface
- Dev::Template::Application::Config
- Defined in:
- lib/firespring_dev_commands/templates/config.rb
Overview
Contains rake tasks for displaying and setting application variables in parameter store
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes inherited from Dev::Template::ApplicationInterface
Attributes inherited from BaseInterface
Instance Method Summary collapse
-
#create_list_task! ⇒ Object
Create the list rake task.
-
#create_set_task! ⇒ Object
rubocop:disable Metrics/MethodLength Create the set task.
-
#initialize(name, path, exclude: []) ⇒ Config
constructor
Allow for custom config path for the application.
Methods inherited from BaseInterface
Constructor Details
#initialize(name, path, exclude: []) ⇒ Config
Allow for custom config path for the application
12 13 14 15 |
# File 'lib/firespring_dev_commands/templates/config.rb', line 12 def initialize(name, path, exclude: []) @path = path super(name, exclude:) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/firespring_dev_commands/templates/config.rb', line 9 def path @path end |
Instance Method Details
#create_list_task! ⇒ Object
Create the list rake task
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/firespring_dev_commands/templates/config.rb', line 18 def create_list_task! # Have to set a local variable to be accessible inside of the instance_eval block application = @name path = @path exclude = @exclude DEV_COMMANDS_TOP_LEVEL.instance_eval do namespace application do namespace :config do return if exclude.include?(:list) desc "List all #{application} configs" task list: %w(init) do puts Dev::Aws::Parameter.new.list(path).each do |it| puts " #{it.name} => #{it.value} (#{it.type})" end puts end end end end end |
#create_set_task! ⇒ Object
rubocop:disable Metrics/MethodLength Create the set task
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/firespring_dev_commands/templates/config.rb', line 44 def create_set_task! # Have to set a local variable to be accessible inside of the instance_eval block application = @name path = @path exclude = @exclude DEV_COMMANDS_TOP_LEVEL.instance_eval do namespace application do namespace :config do return if exclude.include?(:set) desc 'Updates the parameter with the given name to the new value' \ "\n\tspecify NAME as the name of the parameter to be set (it will be prefixed with the base path for this app)" \ "\n\tspecify VALUE is required and is the value you wish the paramete to be set to" \ "\n\toptionally specify ENCRYPT=true to change a String type to a SecureString type" task set: %w(ensure_aws_credentials) do raise 'NAME is required' if ENV['NAME'].to_s.strip.blank? raise 'NAME is not found in this apps parameters' if Dev::Aws::Parameter.new.list(path).none? { |it| it.name == ENV['NAME'] } raise 'VALUE is required' if ENV['VALUE'].to_s.strip.blank? param_path = ENV.fetch('NAME', nil) new_value = ENV.fetch('VALUE', nil) old_value = Dev::Aws::Parameter.new.get(param_path) params = {type: 'String'} if ENV['ENCRYPT'].to_s.strip == 'true' || old_value.type == 'SecureString' params[:type] = 'SecureString' params[:key_id] = Dev::Aws::Parameter.new.get_value("#{path}/kms/id") end = 'This will change '.light_green + param_path.light_yellow + ' from "'.light_green + old_value.value.light_yellow + '" ('.light_green + old_value.type.light_yellow + ') to "'.light_green + new_value.light_yellow + '" ('.light_green + params[:type].light_yellow + '). Continue'.light_green Dev::Common.new.with_confirmation(, color_message: false) do Dev::Aws::Parameter.new.put(param_path, new_value, **params) end end end end end end |