class Yao::TokenV3
Attributes
auth_info[RW]
endpoints[RW]
expire_at[RW]
expires[RW]
issued_at[RW]
to_s[RW]
token[RW]
Public Class Methods
issue(cli, auth_info)
click to toggle source
# File lib/yao/tokenv3.rb, line 5 def self.issue(cli, auth_info) t = new(auth_info) t.refresh(cli) t end
new(auth_info, token_data=nil)
click to toggle source
# File lib/yao/tokenv3.rb, line 11 def initialize(auth_info, token_data=nil) @auth_info = auth_info @endpoints = {} end
Public Instance Methods
expired?()
click to toggle source
# File lib/yao/tokenv3.rb, line 29 def expired? return true unless self.expire_at Time.now >= self.expire_at end
refresh(cli)
click to toggle source
# File lib/yao/tokenv3.rb, line 34 def refresh(cli) @endpoints.clear res = cli.post("#{Yao.config.auth_url}/auth/tokens") do |req| req.body = auth_info.to_json req.headers['Content-Type'] = 'application/json' end register(res) register_endpoints(res.body["token"]["catalog"]) self end
register(response)
click to toggle source
# File lib/yao/tokenv3.rb, line 20 def register(response) @token = response.headers["X-Subject-Token"] token_data = response.body["token"] @issued_at = Time.parse(token_data["issued_at"]).localtime @expire_at = Time.parse(token_data["expires_at"]).localtime Yao.current_tenant_id token_data["project"]["id"] end
register_endpoints(_endpoints)
click to toggle source
# File lib/yao/tokenv3.rb, line 47 def register_endpoints(_endpoints) return unless _endpoints _endpoints.each do |endpoint_data| type = endpoint_data["type"] region_name = Yao.config.region_name ? Yao.config.region_name : 'RegionOne' endpoints = endpoint_data["endpoints"].select { |ep| ep.has_value?(region_name) } urls = {} endpoints.each do |ep| name = "#{ep["interface"]}_url".to_sym urls[name] = ep["url"] end @endpoints[type] = urls end Yao.default_client.register_endpoints(@endpoints, token: self) end