class Keyrod::CLI
Public Instance Methods
token()
click to toggle source
# File lib/keyrod/cli.rb, line 76 def token merge_config options validate_config options init_logger process_tokens rescue Keyrod::Errors::ParamsError => e abort e.message end
version()
click to toggle source
# File lib/keyrod/cli.rb, line 86 def version $stdout.puts Keyrod::VERSION end
Private Instance Methods
access_token()
click to toggle source
# File lib/keyrod/cli.rb, line 136 def access_token oidc_client = Keyrod::OIDCClient.new Keyrod::Settings[:'access-token'] = oidc_client.access_token end
init_logger()
click to toggle source
# File lib/keyrod/cli.rb, line 94 def init_logger logging_level = Keyrod::Settings[:debug] ? [:debug] : [:info] Yell.new :stdout, name: Object, level: logging_level Object.send :include, Yell::Loggable end
merge_config(options)
click to toggle source
# File lib/keyrod/cli.rb, line 100 def merge_config(options) Keyrod::Settings.clear Keyrod::Settings.merge! options.to_hash ssl_params = { verify: Keyrod::Settings[:'verify-ssl'] } ssl_params[:ca_path] = Keyrod::Settings[:'ca-dir'] if Keyrod::Settings[:'ca-dir'] Keyrod::Settings[:ssl] = ssl_params end
process_tokens()
click to toggle source
# File lib/keyrod/cli.rb, line 124 def process_tokens access_token if Keyrod::Settings[:'refresh-token'] fedcloud_client = Keyrod::FedcloudClient.new unscoped_token = fedcloud_client.unscoped_token project = select_project(fedcloud_client.projects(unscoped_token)) $stdout.puts fedcloud_client.scoped_token(unscoped_token, project) rescue Keyrod::Errors::ProjectError => e abort e.message end
select_project(projects)
click to toggle source
# File lib/keyrod/cli.rb, line 141 def select_project(projects) group = Keyrod::Settings[:group] return group if projects.include? group raise Keyrod::Errors::ProjectError, "Group #{group} is not available" if group && !Keyrod::Settings[:'interactive-fallback'] ask('Choose one of these groups:', limited_to: projects) end
validate_config(options)
click to toggle source
# File lib/keyrod/cli.rb, line 108 def validate_config(options) raise Keyrod::Errors::ParamsError, 'Refresh/access token required' unless options[:'access-token'] || options[:'refresh-token'] raise Keyrod::Errors::ParamsError, 'Use one of refresh/access token' if options[:'access-token'] && options[:'refresh-token'] return unless options[:'refresh-token'] validate_config_group options, ['oidc-site', 'client-id', 'client-secret'], '--oidc-site, --client-id, --client-secret are required with refresh token' end
validate_config_group(options, group, message)
click to toggle source
# File lib/keyrod/cli.rb, line 118 def validate_config_group(options, group, message) return if group.all? { |option| options[option] } raise Keyrod::Errors::ParamsError, message end