module SwiftStorage::Auth::V2_0
Attributes
auth_path[RW]
Public Instance Methods
authenticate!()
click to toggle source
# File lib/swift_storage/auth/v2_0.rb, line 9 def authenticate! res = request("#{auth_url}/tokens", method: :post, json_data: auth_data) JSON.parse(res.body).tap do |body| @auth_token = body['access']['token']['id'] @expires = body['access']['token']['expires'] storage_endpoint(body['access']['serviceCatalog']) do |endpoint| self.storage_url = endpoint['publicURL'] @storage_token = endpoint['id'] @auth_at = Time.now end end end
authenticated?()
click to toggle source
# File lib/swift_storage/auth/v2_0.rb, line 23 def authenticated? !!(self.storage_url && auth_token && expires && Time.now.utc < Time.parse(expires).utc) end
Private Instance Methods
auth_data()
click to toggle source
# File lib/swift_storage/auth/v2_0.rb, line 33 def auth_data case configuration.auth_method when :password { auth: { passwordCredentials: { username: username, password: password }, configuration.authtenant_type => tenant || username } } when :rax_kskey { auth: { 'RAX-KSKEY:apiKeyCredentials' => { username: username, apiKey: password } } } when :key { auth: { apiAccessKeyCredentials: { accessKey: username, secretKey: password }, configuration.authtenant_type => tenant || username } } else fail "Unsupported authentication method #{configuration.auth_method}" end end
auth_url()
click to toggle source
# File lib/swift_storage/auth/v2_0.rb, line 29 def auth_url File.join(endpoint, @auth_path || 'v2.0').chomp('/') end
storage_endpoint(service_catalog) { |sample| ... }
click to toggle source
# File lib/swift_storage/auth/v2_0.rb, line 69 def storage_endpoint(service_catalog) unless (swift = service_catalog.find { |service| service['type'] == 'object-store' }) fail SwiftStorage::Errors::NotFoundError.new 'No object-store service found' end yield swift['endpoints'].sample end