Class: Google::Cloud::Gemserver::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/gemserver/configuration.rb

Overview

Configuration

Stores configurations for the gemserver and provides methods for altering that configuration.

Constant Summary collapse

PROD_DB_DEFAULTS =

Default configuration settings for the production database.

{
    database: "mygems",
    username: "test",
    password: "test",
    host: "localhost",
    socket: "# this will be set automatically"
}.freeze
DEV_DB_DEFAULTS =

Default configuration settings for the dev database.

{
    database: "mygems",
    username: "test",
    password: "test",
    host: "localhost",
    socket: "# this will need to be set manually"
}.freeze
TEST_DB_DEFAULTS =

Default configuration settings for the test database.

{
    database: "testgems",
    username: "test",
    password: "test",
    host: "localhost",
}.freeze
BETA_SETTING_DEFAULTS =

Beta setting used by Google App Engine to connect to the Cloud SQL instance.

{
  "cloud_sql_instances" => "# automatically set"
}.freeze
HEALTH_CHECK_DEFAULT =

Setting used by Google App Engine to disable health checks for faster deploys.

{
  "enable_health_check" => false
}.freeze
AUTO_SCALING_DEFAULT =

Setting used by Google App Engine to enable auto scaling.

{
  "min_num_instances" => 1,
  "max_num_instances" => 5
}.freeze
DEFAULT_CONFIG =

Default configuration settings for the production gemserver.

{
  db_connection_options: PROD_DB_DEFAULTS,
  db_adapter: "cloud_sql",
  cache_type: "memory",
  protected_fetch: true,
  bind: "tcp://0.0.0.0:8080",
  :log_file => :stdout
}.freeze
DEFAULT_DEV_CONFIG =

Default configuration settings for the development gemserver.

{
  db_connection_options: DEV_DB_DEFAULTS,
  db_adapter: "cloud_sql",
  cache_type: "memory",
  protected_fetch: true,
  bind: "tcp://0.0.0.0:8080",
  :log_file => :stdout
}.freeze
DEFAULT_TEST_CONFIG =

Default configuration settings for the test gemserver.

{
  db_connection_options: TEST_DB_DEFAULTS,
  db_adapter: "sqlite3",
  cache_type: "memory",
  protected_fetch: true,
  bind: "tcp://0.0.0.0:8080",
  :log_file => :stdout
}.freeze
CONFIG_PREFIX =

Prefix for all general configuration setting fields in app.yaml.

"gen".freeze
CONFIG_DB_PREFIX =

Prefix for all database configuration setting fields in app.yaml.

"db".freeze
APP_ENGINE_ENV_VARS =

Environment variables used by app.yaml for gemserver deployment.

{
  "GEMSERVER_ON_APPENGINE" => true,
  "production_db_database" => "mygems",
  "production_db_username" => "test",
  "production_db_password" => "test",
  "production_db_host" => "localhost",
  "production_db_socket" => "# this is set automatically",
  "production_db_adapter" => "cloud_sql",
  "dev_db_database" => "mygems",
  "dev_db_username" => "test",
  "dev_db_password" => "test",
  "dev_db_host" => "localhost",
  "dev_db_socket" => "# this must be set manually",
  "dev_db_adapter" => "cloud_sql",
  "test_db_database" => "mygems",
  "test_db_username" => "test",
  "test_db_password" => "test",
  "test_db_host" => "localhost",
  "test_db_adapter" => "sqlite3",
  "gen_cache_type" => "memory",
  "gen_protected_fetch" => true,
  "gen_bind" => "tcp://0.0.0.0:8080",
  "gen_log_file" => :stdout
}.freeze
APP_DEFAULTS =

Default settings for gemserver deployment to Google App Engine via app.yaml.

{
  "runtime" => "ruby",
  "env" => "flex",
  "entrypoint" => "./bin/google-cloud-gemserver start",
  "beta_settings" => BETA_SETTING_DEFAULTS,
  "health_check" =>  HEALTH_CHECK_DEFAULT,
  "automatic_scaling" => AUTO_SCALING_DEFAULT,
  "env_variables" => APP_ENGINE_ENV_VARS
}.freeze
GEM_NAME =

The name of the gem.

"google-cloud-gemserver".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Instantiate a new instance of Configuration



215
216
217
218
# File 'lib/google/cloud/gemserver/configuration.rb', line 215

def initialize
  @app    = load_app
  @config = load_config
end

Instance Attribute Details

#appHash

The configuration used by gcloud to deploy the gemserver to Google App Engine.

Returns:

  • (Hash)


211
212
213
# File 'lib/google/cloud/gemserver/configuration.rb', line 211

def app
  @app
end

#configHash

The configuration used by the gemserver.

Returns:

  • (Hash)


205
206
207
# File 'lib/google/cloud/gemserver/configuration.rb', line 205

def config
  @config
end

Class Method Details

.deployed?Boolean

Checks if the gemserver was deployed by the existence of the config file used to deploy it on a specific path on Google Cloud Storage.

Returns:

  • (Boolean)


319
320
321
# File 'lib/google/cloud/gemserver/configuration.rb', line 319

def self.deployed?
  !GCS.get_file(GCS_PATH).nil?
end

.display_configObject

Displays the configuration used by the current gemserver



303
304
305
306
307
308
309
310
311
312
# File 'lib/google/cloud/gemserver/configuration.rb', line 303

def self.display_config
  unless deployed?
    puts "No configuration found. Was the gemserver deployed?"
    return
  end
  prepare GCS.get_file(GCS_PATH)
  puts "Gemserver is running with this configuration:"
  puts YAML.load_file(GCS_PATH).to_yaml
  cleanup
end

Instance Method Details

#[](key) ⇒ String

Accesses a key in the Configuration object.

Parameters:

  • key (String)

    Name of the key accessed.

Returns:

  • (String)


267
268
269
# File 'lib/google/cloud/gemserver/configuration.rb', line 267

def [] key
  @config[key]
end

#app_pathString

Fetches the path to the relevant app configuration file.

Returns:

  • (String)


297
298
299
# File 'lib/google/cloud/gemserver/configuration.rb', line 297

def app_path
  "#{config_dir}/app.yaml"
end

#config_pathString

Fetches the path to the relevant configuration file based on the environment (production, test, development).

Returns:

  • (String)


289
290
291
# File 'lib/google/cloud/gemserver/configuration.rb', line 289

def config_path
  "#{config_dir}/#{suffix}"
end

#delete_from_cloudObject

Deletes the configuration file used for a deployment



229
230
231
# File 'lib/google/cloud/gemserver/configuration.rb', line 229

def delete_from_cloud
  GCS.delete_file GCS_PATH
end

#save_to_cloudObject

Saves the configuration file used for a deployment.



222
223
224
225
# File 'lib/google/cloud/gemserver/configuration.rb', line 222

def save_to_cloud
  puts "Saving configuration"
  GCS.upload config_path, GCS_PATH
end

#update_app(value, key, sub_key = nil) ⇒ Object

Updates the app configuration file.

Parameters:

  • value (String)

    New value of the key.

  • key (String)

    Name of the key that will be updated.

  • sub_key (String) (defaults to: nil)

    Name of the sub key that will be updated.



252
253
254
255
256
257
258
259
# File 'lib/google/cloud/gemserver/configuration.rb', line 252

def update_app value, key, sub_key = nil
  if sub_key
    @app[key][sub_key] = value
  else
    @app[key] = value
  end
  write_app
end

#update_config(value, key, sub_key = nil) ⇒ Object

Updates the configuration file.

Parameters:

  • value (String)

    New value of the key.

  • key (String)

    Name of the key that will be updated.

  • sub_key (String) (defaults to: nil)

    Name of the sub key that will be updated.



239
240
241
242
243
244
245
246
# File 'lib/google/cloud/gemserver/configuration.rb', line 239

def update_config value, key, sub_key = nil
  if sub_key
    @config[key][sub_key] = value
  else
    @config[key] = value
  end
  write_config
end