Skip to content

Commit

Permalink
Improvements for configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
candanedo committed Feb 9, 2024
1 parent 6e00fc4 commit 34da420
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
22 changes: 7 additions & 15 deletions lib/use_paragon/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(user_id)
def generate_token
validate_user_id!

rsa_private = OpenSSL::PKey::RSA.new(private_key)
rsa_private = OpenSSL::PKey::RSA.new(config.private_key)
created_at = Time.now.floor.to_i

payload = {
Expand All @@ -31,16 +31,12 @@ def generate_token

private

def base_url
"https://zeus.useparagon.com"
end

def connection
@connection ||= Faraday.new do |conn|
conn.request :authorization, "Bearer", generate_token
conn.response :logger, Rails.logger, { errors: true, bodies: true }

conn.url_prefix = base_url
conn.url_prefix = config.base_url
conn.request :json
conn.response :json, content_type: "application/json"
conn.response :raise_error
Expand All @@ -59,19 +55,15 @@ def logger_enabled?
end

def path(endpoint)
"/projects/#{project_id}/#{endpoint}"
end

def private_key
UseParagon.configuration.private_key
end

def project_id
UseParagon.configuration.project_id
"/projects/#{config.project_id}/#{endpoint}"
end

def validate_user_id!
raise UseParagon::InvalidUserIdError if user_id.nil? || user_id.to_s.empty?
end

def config
UseParagon.configuration
end
end
end
6 changes: 5 additions & 1 deletion lib/use_paragon/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
module UseParagon
# Allows configuration using an initializer
class Configuration
attr_accessor :private_key, :project_id
attr_accessor :private_key, :project_id, :base_url

def initialize
@base_url = "https://zeus.useparagon.com"
end
end
end

0 comments on commit 34da420

Please sign in to comment.