Class: ConfigurationService::Base
- Inherits:
-
Object
- Object
- ConfigurationService::Base
- Defined in:
- lib/configuration_service/base.rb
Overview
The configuration service API
The service provides authorized publication and consumption of identified configuration data with metadata.
It is recommended that consumers use a Factory to create and configure the service.
Instance Method Summary collapse
-
#initialize(identifier, token, provider) ⇒ Base
constructor
Creates a new API instance for the service
provider. -
#publish_configuration(data, metadata = {}) ⇒ Object
Publishes configuration
dataand optionalmetadata. -
#request_configuration ⇒ Object
Requests the configuration data and metadata for the
identifier.
Constructor Details
#initialize(identifier, token, provider) ⇒ Base
Creates a new API instance for the service provider
The identifier is a string that uniquely identifies some configuration data and associated metadata. It might be the name of a service or service component. It might include an environment label (e.g. production, staging, etc.) For example:
-
billing.acme.com
-
billing-web1.acme.com
-
billing/production/web1
The token is a string that authorizes the client to access the configuration data and associated metadata. Interpretation of the token is provider-dependent; it is opaque to the API and client.
The provider is a configured service provider instance.
33 34 35 36 37 |
# File 'lib/configuration_service/base.rb', line 33 def initialize(identifier, token, provider) @identifier = identifier @token = token @provider = provider end |
Instance Method Details
#publish_configuration(data, metadata = {}) ⇒ Object
Publishes configuration data and optional metadata
The data and the metadata (if specified) must be dictionaries (responding to #to_hash or #to_h). The provider receives a a Configuration object, whose metadata is decorated with the following keys:
-
“timestamp” - the current UTC time in ISO8601 format
-
“revision” - a UUID for this publication
Returns a Configuration object or raises an Error on failure. When a Configuration object is returned, its metadata is the decorated copy, allowing access to additional metadata added by the API or the provider.
66 67 68 69 70 71 72 73 |
# File 'lib/configuration_service/base.rb', line 66 def publish_configuration(data, = {}) dictionary?(data) or raise ConfigurationService::Error, "data must be a dictionary" dictionary?() or raise ConfigurationService::Error, "metadata must be a dictionary" = decorate() configuration = Configuration.new(@identifier, data, ) @provider.publish_configuration(configuration, @token) end |
#request_configuration ⇒ Object
Requests the configuration data and metadata for the identifier
Delegates the request to the provider.
Returns a Configuration object or raises an Error on failure. Raises ConfigurationNotFoundError if no matching configuration was found.
48 49 50 51 |
# File 'lib/configuration_service/base.rb', line 48 def request_configuration @provider.request_configuration(@identifier, @token) or raise ConfigurationNotFoundError, "configuration not found for identifier: #{@identifier}" end |