Class: Cloudenvoy::Config
- Inherits:
-
Object
- Object
- Cloudenvoy::Config
- Defined in:
- lib/cloudenvoy/config.rb
Overview
Holds cloudenvoy configuration. See Cloudenvoy#configure
Constant Summary collapse
- EMULATOR_HOST =
Emulator host
ENV['PUBSUB_EMULATOR_HOST'] || 'localhost:8085'
- DEFAULT_PROCESSOR_PATH =
Default application path used for processing messages
'/cloudenvoy/receive'
- PROCESSOR_HOST_MISSING =
<<~DOC Missing host for processing. Please specify a processor hostname in form of `https://some-public-dns.example.com`' DOC
- SUB_PREFIX_MISSING_ERROR =
<<~DOC Missing GCP subscription prefix. Please specify a subscription prefix in the form of `my-app`. DOC
- PROJECT_ID_MISSING_ERROR =
<<~DOC Missing GCP project ID. Please specify a project ID in the cloudenvoy configurator. DOC
- SECRET_MISSING_ERROR =
<<~DOC Missing cloudenvoy secret. Please specify a secret in the cloudenvoy initializer or add Rails secret_key_base in your credentials DOC
Instance Attribute Summary collapse
-
#gcp_project_id ⇒ String
Return the GCP project ID.
-
#gcp_sub_prefix ⇒ String
Return the prefix used for queues.
-
#logger ⇒ Logger, any
Return the Cloudenvoy logger.
-
#mode ⇒ <Type>
The operating mode.
-
#processor_path ⇒ String
The path on the host when message payloads will be sent.
-
#secret ⇒ String
Return the secret to use to sign the verification tokens attached to messages.
Instance Method Summary collapse
-
#environment ⇒ String
Return the current environment.
-
#processor_host ⇒ String
The hostname of the application processing the messages.
-
#processor_host=(val) ⇒ Object
Set the processor host.
-
#processor_url ⇒ String
Return the full URL of the processor.
-
#publisher_middleware {|@publisher_middleware| ... } ⇒ Cloudenvoy::Middleware::Chain
Return the chain of publisher middlewares.
-
#subscriber_middleware {|@subscriber_middleware| ... } ⇒ Cloudenvoy::Middleware::Chain
Return the chain of subscriber middlewares.
Instance Attribute Details
#gcp_project_id ⇒ String
Return the GCP project ID.
127 128 129 |
# File 'lib/cloudenvoy/config.rb', line 127 def gcp_project_id @gcp_project_id || raise(StandardError, PROJECT_ID_MISSING_ERROR) end |
#gcp_sub_prefix ⇒ String
Return the prefix used for queues.
118 119 120 |
# File 'lib/cloudenvoy/config.rb', line 118 def gcp_sub_prefix @gcp_sub_prefix || raise(StandardError, SUB_PREFIX_MISSING_ERROR) end |
#logger ⇒ Logger, any
Return the Cloudenvoy logger.
59 60 61 |
# File 'lib/cloudenvoy/config.rb', line 59 def logger @logger ||= defined?(Rails) ? Rails.logger : ::Logger.new($stdout) end |
#mode ⇒ <Type>
The operating mode.
- :production => send messages to GCP Pub/Sub
- :development => send message to gcloud CLI Pub/Sub emulator
41 42 43 |
# File 'lib/cloudenvoy/config.rb', line 41 def mode @mode ||= environment == 'development' ? :development : :production end |
#processor_path ⇒ String
The path on the host when message payloads will be sent. Default to ‘/cloudenvoy/receive`
109 110 111 |
# File 'lib/cloudenvoy/config.rb', line 109 def processor_path @processor_path || DEFAULT_PROCESSOR_PATH end |
#secret ⇒ String
Return the secret to use to sign the verification tokens attached to messages.
137 138 139 140 141 |
# File 'lib/cloudenvoy/config.rb', line 137 def secret @secret || ( defined?(Rails) && Rails.application.credentials&.dig(:secret_key_base) ) || raise(StandardError, SECRET_MISSING_ERROR) end |
Instance Method Details
#environment ⇒ String
Return the current environment.
50 51 52 |
# File 'lib/cloudenvoy/config.rb', line 50 def environment ENV['CLOUDENVOY_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' end |
#processor_host ⇒ String
The hostname of the application processing the messages. The hostname must be reachable from Cloud Pub/Sub.
98 99 100 |
# File 'lib/cloudenvoy/config.rb', line 98 def processor_host @processor_host || raise(StandardError, PROCESSOR_HOST_MISSING) end |
#processor_host=(val) ⇒ Object
Set the processor host. In the context of Rails the host will also be added to the list of authorized Rails hosts.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cloudenvoy/config.rb', line 79 def processor_host=(val) @processor_host = val # Check if Rails supports host filtering return unless val && defined?(Rails) && Rails.application.config.respond_to?(:hosts) && Rails.application.config.hosts&.any? # Add processor host to the list of authorized hosts Rails.application.config.hosts << val.gsub(%r{https?://}, '') end |
#processor_url ⇒ String
Return the full URL of the processor. Message payloads will be sent to this URL.
69 70 71 |
# File 'lib/cloudenvoy/config.rb', line 69 def processor_url File.join(processor_host, processor_path) end |
#publisher_middleware {|@publisher_middleware| ... } ⇒ Cloudenvoy::Middleware::Chain
Return the chain of publisher middlewares.
148 149 150 151 152 |
# File 'lib/cloudenvoy/config.rb', line 148 def publisher_middleware @publisher_middleware ||= Middleware::Chain.new yield @publisher_middleware if block_given? @publisher_middleware end |
#subscriber_middleware {|@subscriber_middleware| ... } ⇒ Cloudenvoy::Middleware::Chain
Return the chain of subscriber middlewares.
159 160 161 162 163 |
# File 'lib/cloudenvoy/config.rb', line 159 def subscriber_middleware @subscriber_middleware ||= Middleware::Chain.new yield @subscriber_middleware if block_given? @subscriber_middleware end |