Class: Chronicle::ETL::CLI::Authorizations

Inherits:
SubcommandBase show all
Defined in:
lib/chronicle/etl/cli/authorizations.rb

Overview

CLI commands for authorizing chronicle-etl with third-party services

Instance Method Summary collapse

Methods inherited from SubcommandBase

banner, help, subcommand_prefix

Instance Method Details

#new(provider) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chronicle/etl/cli/authorizations.rb', line 22

def new(provider)
  authorizer_klass = find_authorizer_klass(provider)
  credentials = load_credentials(provider: provider, credentials_source: options[:credentials])
  authorizer = authorizer_klass.new(port: options[:port], credentials: credentials)

  secrets = authorizer.authorize!
  secrets_namespace = options[:secrets] || provider
  Chronicle::ETL::Secrets.set_all(secrets_namespace, secrets)

  pp secrets if options[:print]

  cli_exit(message: "Authorization saved to '#{secrets_namespace}' secrets")
rescue StandardError => e
  cli_fail(message: "Authorization not successful.\n#{e.message}", exception: e)
end