Class: Strata::CLI::Credentials
- Inherits:
-
Object
- Object
- Strata::CLI::Credentials
- Includes:
- Thor::Shell
- Defined in:
- lib/strata/cli/credentials.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
Class Method Summary collapse
-
.fetch(ds_key) ⇒ Object
Retrieve existing credentials for the given ds_key or empty hash.
Instance Method Summary collapse
- #collect ⇒ Object
- #collected? ⇒ Boolean
-
#initialize(adapter, datasource_config: nil) ⇒ Credentials
constructor
A new instance of Credentials.
- #required? ⇒ Boolean
- #write_local(ds_key, context) ⇒ Object
Constructor Details
#initialize(adapter, datasource_config: nil) ⇒ Credentials
Returns a new instance of Credentials.
19 20 21 22 23 |
# File 'lib/strata/cli/credentials.rb', line 19 def initialize(adapter, datasource_config: nil) @adapter = adapter.downcase.strip @datasource_config = datasource_config || {} @prompt = TTY::Prompt.new end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
17 18 19 |
# File 'lib/strata/cli/credentials.rb', line 17 def adapter @adapter end |
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
17 18 19 |
# File 'lib/strata/cli/credentials.rb', line 17 def credentials @credentials end |
Class Method Details
Instance Method Details
#collect ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/strata/cli/credentials.rb', line 29 def collect credentials = {} case adapter when "snowflake" auth_mode = @prompt.select("Authentication mode:", %w[pat kp], default: "pat") credentials["auth_mode"] = auth_mode case auth_mode when "pat" credentials["personal_access_token"] = @prompt.ask("Enter Personal Access Token:") when "kp" credentials["username"] = @prompt.ask("Enter Username:") credentials["private_key"] = @prompt.ask("Enter Private Key Absolute Path:") end when "athena" credentials["access_key_id"] = @prompt.ask("AWS Access Key ID:") credentials["secret_access_key"] = @prompt.ask("AWS Secret Access Key:") when "databricks" credentials["auth_mode"] = "oauth_m2m" credentials["oauth_client_id"] = @prompt.ask("OAuth Client ID:") credentials["oauth_client_secret"] = @prompt.ask("OAuth Client Secret:") else if required? unless %w[postgres mysql trino sqlserver].include?(adapter) credentials["username"] = @prompt.ask("Enter Username:") end credentials["password"] = @prompt.mask("Enter Password:") end end @credentials = credentials end |
#collected? ⇒ Boolean
63 64 65 |
# File 'lib/strata/cli/credentials.rb', line 63 def collected? !@credentials.keys.empty? end |
#required? ⇒ Boolean
25 26 27 |
# File 'lib/strata/cli/credentials.rb', line 25 def required? adapter != "duckdb" end |
#write_local(ds_key, context) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/strata/cli/credentials.rb', line 67 def write_local(ds_key, context) context.gsub_file Configuration::STRATA_CONFIG_FILE, Utils.yaml_block_matcher(ds_key), "" creds = "#{ds_key}:" credentials.each do |key, val| creds << "\n #{key}: #{val}" unless val.nil? || val.empty? end context.append_to_file Configuration::STRATA_CONFIG_FILE, creds # Set restrictive permissions (read/write for owner only) strata_file = Configuration::STRATA_CONFIG_FILE File.chmod(0o600, strata_file) if File.exist?(strata_file) rescue Errno::EACCES => e raise Strata::CommandError, "Permission denied setting permissions on #{strata_file}: #{e.}" end |