Sha256: 1484f8b08eb642fe7d0d45d08ee466bc6570050fa8f6a28fdf55902dcbf624ae
Contents?: true
Size: 1.25 KB
Versions: 3
Compression:
Stored size: 1.25 KB
Contents
module ProxyAuth # Connects to proxy and gets service token class Connection def service_token register_service @response && JSON.parse(@response.body)['token'] end private def register_service @response = http.post('/services', params, headers) Rails.logger.info "Service #{service_name} registered." rescue Errno::ECONNREFUSED Rails.logger.fatal 'Proxy connection refused.' end def registration_token encoder = ActionController::HttpAuthentication::Token token = Rails.application.secrets.proxy['token'] @registration_token ||= encoder.encode_credentials token end def headers { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => registration_token } end def http @http ||= Net::HTTP.new(uri.host, uri.port) end def params { service: { name: service_name, host: service_url } }.to_json end def service_name @service_name ||= Rails.application.secrets.service['name'] end def service_url @service_url ||= Rails.application.secrets.service['url'] end def uri @uri ||= URI.parse(Rails.application.secrets.proxy['url']) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
proxy_auth-0.0.4 | lib/proxy_auth/connection.rb |
proxy_auth-0.0.3 | lib/proxy_auth/connection.rb |
proxy_auth-0.0.2 | lib/proxy_auth/connection.rb |