class Cloudenvoy::Config

Holds cloudenvoy configuration. See Cloudenvoy#configure

Constants

DEFAULT_PROCESSOR_PATH

Default application path used for processing messages

EMULATOR_HOST

Emulator host

PROCESSOR_HOST_MISSING
PROJECT_ID_MISSING_ERROR
SECRET_MISSING_ERROR
SUB_PREFIX_MISSING_ERROR

Attributes

gcp_project_id[W]
gcp_sub_prefix[W]
logger[W]
mode[W]
processor_path[W]
secret[W]

Public Instance Methods

environment() click to toggle source

Return the current environment.

@return [String] The environment name.

# File lib/cloudenvoy/config.rb, line 50
def environment
  ENV['CLOUDENVOY_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
end
gcp_project_id() click to toggle source

Return the GCP project ID.

@return [String] The ID of the project where pub/sub messages are hosted.

# File lib/cloudenvoy/config.rb, line 127
def gcp_project_id
  @gcp_project_id || raise(StandardError, PROJECT_ID_MISSING_ERROR)
end
gcp_sub_prefix() click to toggle source

Return the prefix used for queues.

@return [String] The prefix used when creating subscriptions.

# File lib/cloudenvoy/config.rb, line 118
def gcp_sub_prefix
  @gcp_sub_prefix || raise(StandardError, SUB_PREFIX_MISSING_ERROR)
end
logger() click to toggle source

Return the Cloudenvoy logger.

@return [Logger, any] The cloudenvoy logger.

# File lib/cloudenvoy/config.rb, line 59
def logger
  @logger ||= defined?(Rails) ? Rails.logger : ::Logger.new(STDOUT)
end
mode() click to toggle source

The operating mode.

- :production => send messages to GCP Pub/Sub
- :development => send message to gcloud CLI Pub/Sub emulator

@return [<Type>] <description>

# File lib/cloudenvoy/config.rb, line 41
def mode
  @mode ||= environment == 'development' ? :development : :production
end
processor_host() click to toggle source

The hostname of the application processing the messages. The hostname must be reachable from Cloud Pub/Sub.

@return [String] The processor host.

# File lib/cloudenvoy/config.rb, line 98
def processor_host
  @processor_host || raise(StandardError, PROCESSOR_HOST_MISSING)
end
processor_host=(val) click to toggle source

Set the processor host. In the context of Rails the host will also be added to the list of authorized Rails hosts.

@param [String] val The processor host to set.

# 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_path() click to toggle source

The path on the host when message payloads will be sent. Default to `/cloudenvoy/receive`

@return [String] The processor path

# File lib/cloudenvoy/config.rb, line 109
def processor_path
  @processor_path || DEFAULT_PROCESSOR_PATH
end
processor_url() click to toggle source

Return the full URL of the processor. Message payloads will be sent to this URL.

@return [String] The processor URL.

# File lib/cloudenvoy/config.rb, line 69
def processor_url
  File.join(processor_host, processor_path)
end
publisher_middleware() { |publisher_middleware| ... } click to toggle source

Return the chain of publisher middlewares.

@return [Cloudenvoy::Middleware::Chain] The chain of middlewares.

# File lib/cloudenvoy/config.rb, line 148
def publisher_middleware
  @publisher_middleware ||= Middleware::Chain.new
  yield @publisher_middleware if block_given?
  @publisher_middleware
end
secret() click to toggle source

Return the secret to use to sign the verification tokens attached to messages.

@return [String] The cloudenvoy secret

# 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
subscriber_middleware() { |subscriber_middleware| ... } click to toggle source

Return the chain of subscriber middlewares.

@return [Cloudenvoy::Middleware::Chain] The chain of middlewares.

# File lib/cloudenvoy/config.rb, line 159
def subscriber_middleware
  @subscriber_middleware ||= Middleware::Chain.new
  yield @subscriber_middleware if block_given?
  @subscriber_middleware
end