Class: SecretConfig::CLI
- Inherits:
-
Object
- Object
- SecretConfig::CLI
- Defined in:
- lib/secret_config/cli.rb
Defined Under Namespace
Modules: Colors
Constant Summary collapse
- PROVIDERS =
%i[ssm].freeze
Instance Attribute Summary collapse
-
#console ⇒ Object
readonly
Returns the value of attribute console.
-
#copy_path ⇒ Object
readonly
Returns the value of attribute copy_path.
-
#delete_key ⇒ Object
readonly
Returns the value of attribute delete_key.
-
#delete_tree ⇒ Object
readonly
Returns the value of attribute delete_tree.
-
#diff ⇒ Object
readonly
Returns the value of attribute diff.
-
#diff_path ⇒ Object
readonly
Returns the value of attribute diff_path.
-
#export ⇒ Object
readonly
Returns the value of attribute export.
-
#fetch_key ⇒ Object
readonly
Returns the value of attribute fetch_key.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#force ⇒ Object
readonly
Returns the value of attribute force.
-
#import ⇒ Object
readonly
Returns the value of attribute import.
-
#import_path ⇒ Object
readonly
Returns the value of attribute import_path.
-
#interpolate ⇒ Object
readonly
Returns the value of attribute interpolate.
-
#key_alias ⇒ Object
readonly
Returns the value of attribute key_alias.
-
#key_id ⇒ Object
readonly
Returns the value of attribute key_id.
-
#no_filter ⇒ Object
readonly
Returns the value of attribute no_filter.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#prune ⇒ Object
readonly
Returns the value of attribute prune.
-
#random_size ⇒ Object
readonly
Returns the value of attribute random_size.
-
#set_key ⇒ Object
readonly
Returns the value of attribute set_key.
-
#set_value ⇒ Object
readonly
Returns the value of attribute set_value.
-
#show_version ⇒ Object
readonly
Returns the value of attribute show_version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #parser ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
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 |
# File 'lib/secret_config/cli.rb', line 44 def initialize(argv) @export = false @import = false @path = nil @key_id = nil @key_alias = nil @provider = :ssm @random_size = 32 @no_filter = false @prune = false @replace = false @copy_path = nil @show_version = false @console = false @diff = false @set_key = nil @set_value = nil @fetch_key = nil @delete_key = nil @delete_tree = nil @diff_path = nil @import_path = nil @force = false @interpolate = false if argv.empty? puts parser exit(-10) end parser.parse!(argv) end |
Instance Attribute Details
#console ⇒ Object (readonly)
Returns the value of attribute console.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def console @console end |
#copy_path ⇒ Object (readonly)
Returns the value of attribute copy_path.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def copy_path @copy_path end |
#delete_key ⇒ Object (readonly)
Returns the value of attribute delete_key.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def delete_key @delete_key end |
#delete_tree ⇒ Object (readonly)
Returns the value of attribute delete_tree.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def delete_tree @delete_tree end |
#diff ⇒ Object (readonly)
Returns the value of attribute diff.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def diff @diff end |
#diff_path ⇒ Object (readonly)
Returns the value of attribute diff_path.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def diff_path @diff_path end |
#export ⇒ Object (readonly)
Returns the value of attribute export.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def export @export end |
#fetch_key ⇒ Object (readonly)
Returns the value of attribute fetch_key.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def fetch_key @fetch_key end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def file_name @file_name end |
#force ⇒ Object (readonly)
Returns the value of attribute force.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def force @force end |
#import ⇒ Object (readonly)
Returns the value of attribute import.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def import @import end |
#import_path ⇒ Object (readonly)
Returns the value of attribute import_path.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def import_path @import_path end |
#interpolate ⇒ Object (readonly)
Returns the value of attribute interpolate.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def interpolate @interpolate end |
#key_alias ⇒ Object (readonly)
Returns the value of attribute key_alias.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def key_alias @key_alias end |
#key_id ⇒ Object (readonly)
Returns the value of attribute key_id.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def key_id @key_id end |
#no_filter ⇒ Object (readonly)
Returns the value of attribute no_filter.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def no_filter @no_filter end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def path @path end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def provider @provider end |
#prune ⇒ Object (readonly)
Returns the value of attribute prune.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def prune @prune end |
#random_size ⇒ Object (readonly)
Returns the value of attribute random_size.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def random_size @random_size end |
#set_key ⇒ Object (readonly)
Returns the value of attribute set_key.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def set_key @set_key end |
#set_value ⇒ Object (readonly)
Returns the value of attribute set_value.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def set_value @set_value end |
#show_version ⇒ Object (readonly)
Returns the value of attribute show_version.
29 30 31 |
# File 'lib/secret_config/cli.rb', line 29 def show_version @show_version end |
Class Method Details
.run!(argv) ⇒ Object
40 41 42 |
# File 'lib/secret_config/cli.rb', line 40 def self.run!(argv) new(argv).run! end |
Instance Method Details
#parser ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/secret_config/cli.rb', line 110 def parser @parser ||= OptionParser.new do |opts| opts. = <<~BANNER Secret Config v#{VERSION} For more information, see: https://rocketjob.github.io/secret_config/ secret-config [options] BANNER opts.on "-e", "--export SOURCE_PATH", "Export configuration. Use --file to specify the file name, otherwise stdout is used." do |path| @export = path end opts.on "-i", "--import TARGET_PATH", "Import configuration. Use --file to specify the file name, --path for the SOURCE_PATH, otherwise stdin is used." do |path| @import = path end opts.on "-f", "--file FILE_NAME", "Import/Export/Diff to/from this file." do |file_name| @file_name = file_name end opts.on "-p", "--path PATH", "Import/Export/Diff to/from this path." do |path| @path = path end opts.on "--diff TARGET_PATH", "Compare configuration to this path. Use --file to specify the source file name, --path for the SOURCE_PATH, otherwise stdin is used." do |file_name| @diff = file_name end opts.on "-s", "--set KEY=VALUE", "Set one key to value. Example: --set mysql/database=localhost" do |param| @set_key, @set_value = param.split("=") unless @set_key && @set_value raise(ArgumentError, "Supply key and value separated by '='. Example: --set mysql/database=localhost") end end opts.on "-f", "--fetch KEY", "Fetch the value for one setting. Example: --fetch mysql/database." do |key| @fetch_key = key end opts.on "-d", "--delete KEY", "Delete one specific key." do |key| @delete_key = key end opts.on "-r", "--delete-tree PATH", "Recursively delete all keys under the specified path." do |path| @delete_tree = path end opts.on "-c", "--console", "Start interactive console." do @console = true end opts.on "--provider PROVIDER", "Provider to use. [ssm | file]. Default: ssm" do |provider| @provider = provider.to_sym end opts.on "--no-filter", "For --export only. Do not filter passwords and keys." do @no_filter = true end opts.on "--interpolate", "For --export only. Evaluate string interpolation and __import__." do @interpolate = true end opts.on "--prune", "For --import only. During import delete all existing keys for which there is no key in the import file. Only works with --import." do @prune = true end opts.on "--force", "For --import only. Overwrite all values, not just the changed ones. Useful for changing the KMS key." do @force = true end opts.on "--key_id KEY_ID", "For --import only. Encrypt config settings with this AWS KMS key id. Default: AWS Default key." do |key_id| @key_id = key_id end opts.on "--key_alias KEY_ALIAS", "For --import only. Encrypt config settings with this AWS KMS alias." do |key_alias| @key_alias = key_alias end opts.on "--random_size INTEGER", Integer, "For --import only. Size to use when generating random values when $(random) is encountered in the source. Default: 32" do |random_size| @random_size = random_size end opts.on "-v", "--version", "Display Secret Config version." do @show_version = true end opts.on("-h", "--help", "Prints this help.") do puts opts exit end end end |
#run! ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/secret_config/cli.rb', line 76 def run! if show_version puts "Secret Config v#{VERSION}" elsif console run_console elsif export raise(ArgumentError, "--path option is not valid for --export") if path run_export(export, file_name || STDOUT, filtered: !no_filter) elsif import if path run_import_path(import, path, prune, force) else run_import(import, file_name || STDIN, prune, force) end elsif diff if path run_diff_path(diff, path) else run_diff(diff, file_name || STDIN) end elsif set_key run_set(set_key, set_value) elsif fetch_key run_fetch(fetch_key) elsif delete_key run_delete(delete_key) elsif delete_tree run_delete_tree(delete_tree) else puts parser end end |