Class: RightScaleCLI::Refresh
- Inherits:
-
Thor
- Object
- Thor
- RightScaleCLI::Refresh
- Defined in:
- lib/rightscale_cli/refresh.rb
Overview
Represents an API token refresh
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ Refresh
constructor
namespace :volumes.
- #token ⇒ Object
Constructor Details
#initialize(*args) ⇒ Refresh
namespace :volumes
30 31 32 33 34 35 36 |
# File 'lib/rightscale_cli/refresh.rb', line 30 def initialize(*args) super # @client = RightScaleCLI::Client.new(options) @logger = RightScaleCLI::Logger.new @config = RightScaleCLI::Config.new @directives = @config.directives end |
Class Method Details
.banner(task, _namespace = true, subcommand = false) ⇒ Object
59 60 61 |
# File 'lib/rightscale_cli/refresh.rb', line 59 def self.(task, _namespace = true, subcommand = false) "#{basename} #{task.formatted_usage(self, true, subcommand)}" end |
Instance Method Details
#token ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rightscale_cli/refresh.rb', line 40 def token token_endpoint = @directives[:token_endpoint] refresh_token = @directives[:refresh_token] @logger.info "Requesting API token from #{token_endpoint}" uri = URI.parse(token_endpoint) https = Net::HTTP.new(uri.host, uri.port) https.set_debug_output($stdout) if [:debug] https.use_ssl = true request = Net::HTTP::Post.new(uri.path) request['X-API-Version'] = '1.5' request.set_form_data(grant_type: 'refresh_token', refresh_token: refresh_token) response = https.request(request) access_token = JSON.parse(response.body)['access_token'] @directives[:access_token] = access_token File.open(@config.config_path, 'w') {|f| f.write(ERB.new(IO.read(@config.template_path)).result(binding)) } @logger.info 'API token refreshed.' end |