Class: SecretConfig::CLI
- Inherits:
-
Object
- Object
- SecretConfig::CLI
- Defined in:
- lib/secret_config/cli.rb
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_path ⇒ Object
readonly
Returns the value of attribute delete_path.
-
#diff ⇒ Object
readonly
Returns the value of attribute diff.
-
#export ⇒ Object
readonly
Returns the value of attribute export.
-
#fetch_key ⇒ Object
readonly
Returns the value of attribute fetch_key.
-
#import ⇒ Object
readonly
Returns the value of attribute import.
-
#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.
-
#overwrite ⇒ Object
readonly
Returns the value of attribute overwrite.
-
#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.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#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
25 26 27 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 |
# File 'lib/secret_config/cli.rb', line 25 def initialize(argv) @export = false @import = false @path = nil @key_id = nil @key_alias = nil @region = ENV["AWS_REGION"] @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_path = nil if argv.empty? puts parser exit(-10) end parser.parse!(argv) end |
Instance Attribute Details
#console ⇒ Object (readonly)
Returns the value of attribute console.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def console @console end |
#copy_path ⇒ Object (readonly)
Returns the value of attribute copy_path.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def copy_path @copy_path end |
#delete_key ⇒ Object (readonly)
Returns the value of attribute delete_key.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def delete_key @delete_key end |
#delete_path ⇒ Object (readonly)
Returns the value of attribute delete_path.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def delete_path @delete_path end |
#diff ⇒ Object (readonly)
Returns the value of attribute diff.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def diff @diff end |
#export ⇒ Object (readonly)
Returns the value of attribute export.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def export @export end |
#fetch_key ⇒ Object (readonly)
Returns the value of attribute fetch_key.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def fetch_key @fetch_key end |
#import ⇒ Object (readonly)
Returns the value of attribute import.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def import @import end |
#key_alias ⇒ Object (readonly)
Returns the value of attribute key_alias.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def key_alias @key_alias end |
#key_id ⇒ Object (readonly)
Returns the value of attribute key_id.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def key_id @key_id end |
#no_filter ⇒ Object (readonly)
Returns the value of attribute no_filter.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def no_filter @no_filter end |
#overwrite ⇒ Object (readonly)
Returns the value of attribute overwrite.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def overwrite @overwrite end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def path @path end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def provider @provider end |
#prune ⇒ Object (readonly)
Returns the value of attribute prune.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def prune @prune end |
#random_size ⇒ Object (readonly)
Returns the value of attribute random_size.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def random_size @random_size end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def region @region end |
#set_key ⇒ Object (readonly)
Returns the value of attribute set_key.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def set_key @set_key end |
#set_value ⇒ Object (readonly)
Returns the value of attribute set_value.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def set_value @set_value end |
#show_version ⇒ Object (readonly)
Returns the value of attribute show_version.
11 12 13 |
# File 'lib/secret_config/cli.rb', line 11 def show_version @show_version end |
Class Method Details
.run!(argv) ⇒ Object
21 22 23 |
# File 'lib/secret_config/cli.rb', line 21 def self.run!(argv) new(argv).run! end |
Instance Method Details
#parser ⇒ Object
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 109 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 |
# File 'lib/secret_config/cli.rb', line 83 def parser @parser ||= OptionParser.new do |opts| opts. = " Secret Config v\#{VERSION}\n\n For more information, see: https://rocketjob.github.io/secret_config/\n\n secret_config [options]\n BANNER\n\n opts.on \"-e\", \"--export [FILE_NAME]\", \"Export configuration to a file or stdout if no file_name supplied.\" do |file_name|\n @export = file_name || STDOUT\n end\n\n opts.on \"-i\", \"--import [FILE_NAME]\", \"Import configuration from a file or stdin if no file_name supplied.\" do |file_name|\n @import = file_name || STDIN\n end\n\n opts.on \"--copy SOURCE_PATH\", \"Import configuration from a file or stdin if no file_name supplied.\" do |path|\n @copy_path = path\n end\n\n opts.on \"--diff [FILE_NAME]\", \"Compare configuration from a file or stdin if no file_name supplied.\" do |file_name|\n @diff = file_name\n end\n\n opts.on \"-s\", \"--set KEY=VALUE\", \"Set one key to value. Example: --set mysql/database=localhost\" do |param|\n @set_key, @set_value = param.split(\"=\")\n unless @set_key && @set_value\n raise(ArgumentError, \"Supply key and value separated by '='. Example: --set mysql/database=localhost\")\n end\n end\n\n opts.on \"-f\", \"--fetch KEY\", \"Fetch the value for one setting. Example: --get mysql/database. \" do |key|\n @fetch_key = key\n end\n\n opts.on \"-d\", \"--delete KEY\", \"Delete one specific key. See --delete-path to delete all keys under a specific path \" do |key|\n @delete_key = key\n end\n\n opts.on \"-r\", \"--delete-path PATH\", \"Recursively delete all keys under the specified path.. \" do |path|\n @delete_path = path\n end\n\n opts.on \"-c\", \"--console\", \"Start interactive console.\" do\n @console = true\n end\n\n opts.on \"-p\", \"--path PATH\", \"Path to import from / export to.\" do |path|\n @path = path\n end\n\n opts.on \"--provider PROVIDER\", \"Provider to use. [ssm | file]. Default: ssm\" do |provider|\n @provider = provider.to_sym\n end\n\n opts.on \"--no-filter\", \"Do not filter passwords and keys.\" do\n @no_filter = true\n end\n\n opts.on \"--prune\", \"During import delete all existing keys for which there is no key in the import file.\" do\n @prune = true\n end\n\n opts.on \"--key_id KEY_ID\", \"Encrypt config settings with this AWS KMS key id. Default: AWS Default key.\" do |key_id|\n @key_id = key_id\n end\n\n opts.on \"--key_alias KEY_ALIAS\", \"Encrypt config settings with this AWS KMS alias.\" do |key_alias|\n @key_alias = key_alias\n end\n\n opts.on \"--region REGION\", \"AWS Region to use. Default: AWS_REGION env var.\" do |region|\n @region = region\n end\n\n opts.on \"--random_size INTEGER\", Integer, \"Size to use when generating random values. Whenever \#{RANDOM} is encountered during an import. Default: 32\" do |random_size|\n @random_size = random_size\n end\n\n opts.on \"-v\", \"--version\", \"Display Symmetric Encryption version.\" do\n @show_version = true\n end\n\n opts.on(\"-h\", \"--help\", \"Prints this help.\") do\n puts opts\n exit\n end\n end\nend\n" |
#run! ⇒ Object
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 |
# File 'lib/secret_config/cli.rb', line 54 def run! if show_version puts "Secret Config v#{VERSION}" puts "Region: #{region}" elsif console run_console elsif export run_export(export, filtered: !no_filter) elsif import && prune run_import_and_prune(import) elsif import run_import(import) elsif copy_path run_copy(copy_path, path) elsif diff run_diff(diff) 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_path run_delete_path(delete_path) else puts parser end end |