module Magellan::Gcs::Proxy::GCP
Constants
- METADATA_HEADER
- METADATA_HOST
- METADATA_PATH_BASE
- SCOPES
Public Instance Methods
auth()
click to toggle source
# File lib/magellan/gcs/proxy/gcp.rb, line 32 def auth @auth ||= new_auth end
logging()
click to toggle source
# File lib/magellan/gcs/proxy/gcp.rb, line 70 def logging @logging ||= Google::Cloud::Logging.new(project: project_id) end
new_auth()
click to toggle source
# File lib/magellan/gcs/proxy/gcp.rb, line 36 def new_auth logger.debug("#{self.class.name}#new_auth") Google::Auth.get_application_default(SCOPES).tap(&:fetch_access_token!) end
project_id()
click to toggle source
# File lib/magellan/gcs/proxy/gcp.rb, line 19 def project_id @project_id ||= retrieve_project_id end
pubsub()
click to toggle source
# File lib/magellan/gcs/proxy/gcp.rb, line 58 def pubsub @pubsub ||= Google::Apis::PubsubV1::PubsubService.new.tap { |api| api.authorization = auth } end
reset()
click to toggle source
# File lib/magellan/gcs/proxy/gcp.rb, line 74 def reset instance_variables.each { |ivar| instance_variable_set(ivar, nil) } end
retrieve_metadata(key)
click to toggle source
# File lib/magellan/gcs/proxy/gcp.rb, line 45 def retrieve_metadata(key) http = Net::HTTP.new(METADATA_HOST) res = http.get(METADATA_PATH_BASE + key, METADATA_HEADER) case res.code when /\A2\d{2}\z/ then res.body else raise "[#{res.code}] #{res.body}" end end
retrieve_project_id()
click to toggle source
# File lib/magellan/gcs/proxy/gcp.rb, line 23 def retrieve_project_id ENV['BLOCKS_BATCH_PROJECT_ID'] || retrieve_metadata('project/project-id') end
storage()
click to toggle source
# File lib/magellan/gcs/proxy/gcp.rb, line 54 def storage @storage ||= Google::Cloud::Storage.new(project: project_id) end
subscription()
click to toggle source
# File lib/magellan/gcs/proxy/gcp.rb, line 62 def subscription unless @subscription @subscription = PubsubSubscription.new(ENV['BLOCKS_BATCH_PUBSUB_SUBSCRIPTION'] || 'test-subscription') logger.info("subscription: #{@subscription.inspect}") end @subscription end