lib/nightcrawler_swift/connection.rb in nightcrawler_swift-0.4.0 vs lib/nightcrawler_swift/connection.rb in nightcrawler_swift-0.5.0
- old
+ new
@@ -5,11 +5,11 @@
def connect!
authenticate!
configure
- NightcrawlerSwift.logger.debug "[NightcrawlerSwift] Connected, token_id: #{token_id}"
+ NightcrawlerSwift.logger.debug "[NightcrawlerSwift] Connected, token_id: #{token_id}"
self
end
def connected?
!self.token_id.nil? and self.expires_at > Time.now
@@ -26,28 +26,28 @@
def opts
NightcrawlerSwift.options
end
def authenticate!
- auth_options = {
- tenantName: opts.tenant_name,
- passwordCredentials: {username: opts.username, password: opts.password}
- }
+ url = opts.auth_url
+ headers = {content_type: :json, accept: :json}
+ response = Gateway.new(url).request {|r| r.post(auth_options.to_json, headers)}
- resource = RestClient::Resource.new(
- opts.auth_url,
- verify_ssl: NightcrawlerSwift.options.verify_ssl,
- timeout: NightcrawlerSwift.options.timeout
- )
-
- response = resource.post({ auth: auth_options }.to_json, content_type: :json, accept: :json)
-
@auth_response = OpenStruct.new(JSON.parse(response.body))
rescue StandardError => e
raise Exceptions::ConnectionError.new(e)
end
+ def auth_options
+ {
+ auth: {
+ tenantName: opts.tenant_name,
+ passwordCredentials: {username: opts.username, password: opts.password}
+ }
+ }
+ end
+
def select_token
@token_id = auth_response.access["token"]["id"]
@expires_at = auth_response.access["token"]["expires"]
@expires_at = DateTime.parse(@expires_at).to_time
end
@@ -61,11 +61,11 @@
raise Exceptions::ConfigurationError.new "No catalog of type 'object-store' found" if catalog.nil?
@endpoints = catalog["endpoints"].first
end
def configure_urls
- @admin_url = @endpoints["adminURL"]
+ @admin_url = opts.admin_url || @endpoints["adminURL"]
+ @public_url = opts.public_url || @endpoints["publicURL"]
@upload_url = "#{@admin_url}/#{opts.bucket}"
- @public_url = @endpoints["publicURL"]
end
end
end