lib/yao/token.rb in yao-0.3.2 vs lib/yao/token.rb in yao-0.3.3

- old
+ new

@@ -2,11 +2,11 @@ module Yao class Token def self.issue(cli, auth_info) t = new(auth_info) - t.reflesh(cli) + t.refresh(cli) t end def initialize(auth_info, token_data=nil) @auth_info = auth_info @@ -27,14 +27,14 @@ def expired? return true unless self.expire_at Time.now >= self.expire_at end - def reflesh(cli) + def refresh(cli) @endpoints.clear - res = cli.post('/v2.0/tokens') do |req| + res = cli.post("#{Yao.config.auth_url}/tokens") do |req| req.body = auth_info.to_json req.headers['Content-Type'] = 'application/json' end body = res.body["access"] @@ -46,14 +46,16 @@ def register_endpoints(_endpoints) return unless _endpoints _endpoints.each do |endpoint_data| type = endpoint_data["type"] - endpoint = endpoint_data["endpoints"].first + region_name = Yao.config.region_name ? Yao.config.region_name : 'RegionOne' + endpoint = endpoint_data["endpoints"].find { |ep| ep.has_value?(region_name) } urls = {} - urls[:public_url] = endpoint["publicURL"] if endpoint["publicURL"] - urls[:admin_url] = endpoint["adminURL"] if endpoint["adminURL"] - + if endpoint + urls[:public_url] = endpoint["publicURL"] if endpoint["publicURL"] + urls[:admin_url] = endpoint["adminURL"] if endpoint["adminURL"] + end @endpoints[type] = urls end Yao.default_client.register_endpoints(@endpoints, token: self) end