Skip to content

Commit

Permalink
Merge pull request #13 from instacart/ISC-35647
Browse files Browse the repository at this point in the history
Isc 35647 - add isc lookup for config
  • Loading branch information
atanner27 authored Feb 15, 2023
2 parents caebe69 + 4e62fd1 commit a2326c5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ gem "activerecord-import"
gem "combustion"
gem "pg"
gem "pg_query"
gem "httparty"
8 changes: 8 additions & 0 deletions lib/pghero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
require "pghero/database"
require "pghero/engine" if defined?(Rails)
require "pghero/version"
require "pghero/isc"

module PgHero
autoload :Connection, "pghero/connection"
Expand Down Expand Up @@ -135,6 +136,13 @@ def config
"databases" => databases
}
end

@isc ||= PgHero::ISC.new
isc_pghero_config = @isc.pghero_config
Rails.logger.info("[PGHero] isc_pghero_config is loaded: #{not isc_pghero_config.nil?}")
Rails.logger.info("config is: #{isc_pghero_config}")
config.merge!(isc_pghero_config) unless isc_pghero_config.nil?

end
end

Expand Down
21 changes: 21 additions & 0 deletions lib/pghero/isc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'httparty'

def authorization
return "Bearer #{ENV['ISC_JWT_TOKEN']}" if ENV.has_key? "ISC_JWT_TOKEN"
"Token #{ENV['STORAGE_ISC_ACCESS_TOKEN']}"
end

module PgHero
class ISC
include HTTParty
base_uri "#{ENV['ISC_URL']}"
headers "Authorization" => authorization
raise_on [404, 400, 500, 503]

def pghero_config
self.class.get("/api/datastore_clusters/pghero_config/", {timeout: 10})
rescue
nil
end
end
end

0 comments on commit a2326c5

Please sign in to comment.