Class: LibCLImate::Climate
- Inherits:
-
Object
- Object
- LibCLImate::Climate
- Includes:
- RazorRisk::Core::Diagnostics::Logger
- Defined in:
- lib/razor_risk/cassini/extensions/libclimate/common_options.rb
Instance Method Summary collapse
- #option_authentication_scheme(program_options, schemes, **options) ⇒ Object
- #option_clarite_config_path(program_options) ⇒ Object
-
#option_credentials_encoding_algorithm(program_options, **options) ⇒ Object
TODO: DEPRECIATED.
- #option_domain(program_options, **options) ⇒ Object
- #option_host(program_options) ⇒ Object
- #option_jwt_encoding_algorithm(program_options, **options) ⇒ Object
- #option_password(program_options, **options) ⇒ Object
- #option_port(program_options) ⇒ Object
- #option_razor_alias(program_options) ⇒ Object
- #option_razor_environment(program_options) ⇒ Object
- #option_razor_executable(program_options) ⇒ Object
- #option_razor_space(program_options) ⇒ Object
- #option_secret_server_source(program_options, **options) ⇒ Object
- #option_tls_cert_and_key(program_options) ⇒ Object
- #option_username(program_options, **options) ⇒ Object
- #option_web_server(program_options, **options) ⇒ Object
Instance Method Details
#option_authentication_scheme(program_options, schemes, **options) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 145 def option_authentication_scheme , schemes, ** ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash ::Xqsr3::Quality::ParameterChecking.check_parameter schemes, 'schemes', type: [ ::String ] self.add_option('--authentication-scheme', alias: '-a', help: "specifies the authentication scheme. Must be one of #{schemes.map { |s| %Q{'#{s}'} }.join(', ')}. Defaults to 'jwt'. If 'jwt', this requires a value to be provided for <jwt-secret-server-url>, which will be used to look up all the algorithms by the '--jwt-encoding-algorithm' and '--credentials-encoding-algorithm' as well as those specified as additional values", required: [:required]) do |o, a| [:authentication_scheme] = (o.value || '').map_option_string(schemes) or self.abort "invalid authorisation scheme '#{o.value}'; use --help for usage" end self.add_flag('--authorization-test-mode', help: "specifies that the web services should be in authorization test mode which does not perform authentication. THIS MUST NOT BE USED IN PRODUCTION.") do |o, a| [:auth_test_mode] = true end end |
#option_clarite_config_path(program_options) ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 135 def option_clarite_config_path ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--clarite-config-path', alias: '-o', help: 'specifies the path of the ClarITe config file. Required', required: true, required_message: "\0ClarITe configuration path") do |o, a| [:clarite_config_path] = o.value or self.abort "invalid ClarITe config path '#{o.value}'; use --help for usage" end end |
#option_credentials_encoding_algorithm(program_options, **options) ⇒ Object
TODO: DEPRECIATED.
162 163 164 165 166 167 168 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 162 def option_credentials_encoding_algorithm , ** self.add_option('--credentials-encoding-algorithm', alias: '-c', help: 'Credentials encoding algorithm has been depreciated.') do |o, a| log :warning, 'Credentials encoding algorithm has been depreciated.' end end |
#option_domain(program_options, **options) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 76 def option_domain , ** ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--domain', help: 'specifies the domain', required: [:required]) do |o, a| [:domain] = o.value or self.abort "invalid domain '#{o.value}'; use --help for usage" end end |
#option_host(program_options) ⇒ Object
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 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 87 def option_host ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--host', alias: '-h', help: 'specifies the host. Defaults to \'localhost\' in development; \'0.0.0.0\' otherwise. May also specify one of the host\'s adaptors, via a sentinel of the form \'adaptor-0\', \'adaptor-1\', ... or \'adaptor-?\' to get a list of available adaptors') do |o, a| v = o.value or self.abort "invalid host '#{o.value}'; use --help for usage" if /^adapt[eo]r-\?$/ =~ v self.abort "available adaptors:\n#{Socket.ip_address_list.select { |ai| ai.ipv4_private? }.map.with_index(0) { |ai, index| "\t#{index}:\t#{ai.ip_address}" }.join(%<\n>)}", exit: 0 end if /^adapt[eo]r-([0-9-]+)$/ =~ v index = Integer $1 address = Socket.ip_address_list.select { |ai| ai.ipv4_private? }[index] self.abort "invalid adaptor index #{index}" if index < 0 self.abort "this machine does not have a private adaptor at index #{index}. Specify 'adaptor-?' to obtain list of available adaptor addresses; use --help for usage" unless address v = address.ip_address else begin v = 'localhost' == v.downcase ? '127.0.0.1' : Resolv.getaddress(v) rescue => x self.abort "exception (#{x.class}) thrown when attempting to resolve given host name '#{v}': #{x}" end end [:host] = v end end |
#option_jwt_encoding_algorithm(program_options, **options) ⇒ Object
170 171 172 173 174 175 176 177 178 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 170 def option_jwt_encoding_algorithm , ** ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--jwt-encoding-algorithm', alias: '-j', help: 'specifies the JWT encoding algorithm (for which a secret must be retrieved). Required if the authentication scheme is \'jwt\'', required: [:required]) do |o, a| [:jwt_encoding_algorithm] = o.value or self.abort "invalid JWT encoding algorithm '#{o.value}'; use --help for usage" end end |
#option_password(program_options, **options) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 59 def option_password , ** ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--password', help: 'specifies the password. If no password is supplied, the user will be prompted for it', required: [:required]) do |o, a| password = o.value if (password || '').empty? password = $terminal.ask('enter password: ') { |q| q.echo = '*' } end [:password] = password end end |
#option_port(program_options) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 125 def option_port ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--port', alias: '-p', help: 'specifies the port. Required', required: true, required_message: "\0Port") do |o, a| [:port] = Integer(o.value, nil: true) or self.abort "invalid port '#{o.value}'; use --help for usage" end end |
#option_razor_alias(program_options) ⇒ Object
200 201 202 203 204 205 206 207 208 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 200 def option_razor_alias ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--razor-alias', help: 'specifies the Razor alias.') do |o, a| [:razor_alias] = o.value or self.abort "invalid Razor alias '#{o.value}'; use --help for usage" end end |
#option_razor_environment(program_options) ⇒ Object
190 191 192 193 194 195 196 197 198 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 190 def option_razor_environment ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--razor-environment', alias: '-e', help: 'specifies the Razor environment name.') do |o, a| [:razor_environment] = o.value or self.abort "invalid Razor environment '#{o.value}'; use --help for usage" end end |
#option_razor_executable(program_options) ⇒ Object
220 221 222 223 224 225 226 227 228 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 220 def option_razor_executable ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--razor-executable', alias: '-x', help: 'specifies the Razor executable path. Required', required: true, required_message: "\0Razor executable") do |o, a| [:razor_executable] = o.value or self.abort "invalid Razor executable path '#{o.value}'; use --help for usage" end end |
#option_razor_space(program_options) ⇒ Object
210 211 212 213 214 215 216 217 218 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 210 def option_razor_space ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--razor-space', help: 'specifies the Razor space.') do |o, a| [:razor_space] = o.value or self.abort "invalid Razor space '#{o.value}'; use --help for usage" end end |
#option_secret_server_source(program_options, **options) ⇒ Object
180 181 182 183 184 185 186 187 188 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 180 def option_secret_server_source , ** ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--secret-server-source', alias: '-s', help: 'specifies the secret server source, which may be the URL of a secret-server, or the path of a secrets file. Required if authentication scheme is \'jwt\'') do |o, a| [:secret_server_source] = o.value or self.abort "invalid secret server source '#{o.value}'; use --help for usage" end end |
#option_tls_cert_and_key(program_options) ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 230 def option_tls_cert_and_key ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--tls-certificate-file', help: 'specifies the TLS/SSL certificate file. If it has the extension \'.crt\' then the path will be used to infer the TLS/SSL public-key file with the extension \'.key\', otherwise the option \'--tls-public-key-file\' is required') do |o, a| fe = Recls.stat(o.value) or self.abort "invalid/non-existant TLS certificate file '#{o.value}'; use --help for usage" [:tls_certificate_file] = fe.path unless [:tls_public_key_file] if fe.extension == '.crt' key_path = fe.path[0...-4] + '.key' if File.exist? key_path [:tls_public_key_file] = key_path end end end end self.add_option('--tls-public-key-file', help: 'specifies the TLS/SSL public-key file') do |o, a| fe = Recls.stat(o.value) or self.abort "invalid/non-existant TLS public-key file '#{o.value}'; use --help for usage" [:tls_public_key_file] = fe.path end end |
#option_username(program_options, **options) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 49 def option_username , ** ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--username', help: 'specifies the username', required: [:required]) do |o, a| [:username] = o.value or self.abort "invalid username '#{o.value}'; use --help for usage" end end |
#option_web_server(program_options, **options) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/razor_risk/cassini/extensions/libclimate/common_options.rb', line 39 def option_web_server , ** ::Xqsr3::Quality::ParameterChecking.check_parameter , 'program_options', type: ::Hash self.add_option('--web-server', alias: '-w', help: 'specifies the web-server', required: [:required]) do |o, a| [:web_server] = o.value or self.abort "invalid web server '#{o.value}'; use --help for usage" end end |