Sha256: 4b00ca6cffd413a429400b485c0e702eab260e2604df37494647fba622f904ad

Contents?: true

Size: 1.19 KB

Versions: 11

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require_relative '../logger'

require "uri"
require "net/http"
require 'json'
require "logger"


module Middleware
  module RubyGem
    module Auth

      class Authentication

        @response = nil

        def get_response
          @response
        end
        def auth
          mw_api_key = ENV["MW_API_KEY"]
          if mw_api_key == nil
            MwLogger.warn("Profiling is not initialized as MW_API_KEY is not provided")
            return false
          end

          url = URI(ENV["MW_AUTH_URL"] || "https://app.middleware.io/api/v1/auth")

          https = Net::HTTP.new(url.host, url.port)
          https.use_ssl = true

          request = Net::HTTP::Post.new(url)
          request["Content-Type"] = "application/x-www-form-urlencoded"
          request["Authorization"] = "Bearer #{mw_api_key}"

          response = https.request(request)

          body = JSON.parse(response.body)
          success_value = body['success']

          if success_value
            @response = body
          else
            MwLogger.warn("Profiling is not initialized as authentication is failed")
          end

          success_value
        end

      end

    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
middleware_apm_linux-2.1.2 lib/middleware/auth/authentication.rb
middleware_apm_linux-2.1.1 lib/middleware/auth/authentication.rb
middleware_apm_linux-2.1.0 lib/middleware/auth/authentication.rb
middleware_apm_linux-2.0.0 lib/middleware/auth/authentication.rb
middleware_apm_linux-1.0.0 lib/middleware/auth/authentication.rb
middleware_apm-1.1.0 lib/middleware/auth/authentication.rb
middleware_apm-1.0.0 lib/middleware/auth/authentication.rb
middleware_apm_dp-1.0.0 lib/middleware/auth/authentication.rb
middleware_apm_dp-0.3.0 lib/middleware/auth/authentication.rb
middleware_apm_dp-0.2.0 lib/middleware/auth/authentication.rb
middleware_apm-0.2.0 lib/middleware/auth/authentication.rb