exercism-config 0.33.0 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b9e8cca313d6d01dfe39b0882911c1b7f2cb84cbf4a0808bff22f5233f35648
4
- data.tar.gz: 8b4c36afd9237e51db22d8dd7f4699a4bb9187c164ba8a265e8d7a506ddc8457
3
+ metadata.gz: d53a8ce7ad6afe4b50df38aecc7af7708bb1a761749ac35ece53a0615da3f82b
4
+ data.tar.gz: 481ca893d9488040b2a7ae2ec842c922aaf8e6eae43e84cbb05933253fabf15c
5
5
  SHA512:
6
- metadata.gz: 795386b3214b418f01e6945662e1496d5a1ca4ffe8fef3d3e614da19e1f20a34c11ddb2bf7f5fa23623b2d4fd6017b5013225e7089965281e77e3e517ef6a631
7
- data.tar.gz: c1161d4fe4594278563dcea81dd5c6d09d13ee421855e12d74b5ea75b710f61e87f0344f7e90a0312a40c12ba39b0fe5b32c59e1819afc1e8b06cb7125735db9
6
+ metadata.gz: 19e81f83e28fbe70e72b9f65df2802ca0dfa83e14abc69b62166df590464e6b6c5b66cd39897b35b4073f3a111de68a566b0b90a33581faaa0169f901c6fefb9
7
+ data.tar.gz: c88d61bec133716c6af5a4308dd883b1a1786a85ba3d3f9b1f4bd302b1ed983181f6a450293a6b467d3f110f634d2da96e806eea5dbb128ae5423a6035b3c9aa
data/.gitignore CHANGED
@@ -9,4 +9,4 @@
9
9
  node_modules/
10
10
  Gemfile.lock
11
11
 
12
- exercism_config-*.gem
12
+ exercism-config-*.gem
@@ -74,6 +74,10 @@ Style/ZeroLengthPredicate:
74
74
  Style/ClassAndModuleChildren:
75
75
  Enabled: false
76
76
 
77
+ Naming/FileName:
78
+ Exclude:
79
+ - "lib/exercism-config.rb"
80
+
77
81
  Naming/VariableNumber:
78
82
  EnforcedStyle: snake_case
79
83
 
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ![Tests](https://github.com/exercism/config/workflows/Tests/badge.svg)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/513edbd6599a2de3218d/maintainability)](https://codeclimate.com/github/exercism/config/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/513edbd6599a2de3218d/test_coverage)](https://codeclimate.com/github/exercism/config/test_coverage)
6
- [![Gem Version](https://badge.fury.io/rb/exercism_config.svg)](https://badge.fury.io/rb/exercism_config)
6
+ [![Gem Version](https://badge.fury.io/rb/exercism-config.svg)](https://badge.fury.io/rb/exercism-config)
7
7
 
8
8
  When terraform creates Exercism's infrastructure, it writes endpoints and DNS entries to DynamoDB.
9
9
  This gem allows you to trivially retrieve that data.
@@ -17,10 +17,9 @@ Simply include this gem in your Gemfile, require it, and then refer to the objec
17
17
 
18
18
  ```ruby
19
19
  # Gemfile
20
- gem 'exercism_config'
20
+ gem 'exercism-config'
21
21
 
22
22
  # Your code
23
- require 'exercism_config'
23
+ require 'exercism-config'
24
24
  ExercismConfig.config.webservers_alb_dns_name
25
25
  ```
26
-
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
- require 'exercism_config'
4
+ require 'exercism-config'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -1,4 +1,4 @@
1
1
  #!/bin/bash
2
2
 
3
- git diff --name-status --staged | grep '^[MA]' | grep -o '\\s\\+.*rb' | xargs bundle exec rubocop --except Metrics --auto-correct --format quiet --force-exclusion lib/exercism_config.rb && \
4
- git diff --name-status --staged | grep '^[MA]' | grep -o '\\s\\+.*rb' | xargs git add
3
+ git diff --name-status --staged | grep '^[MA]' | grep -o '\s\+.*rb' | xargs bundle exec rubocop --except Metrics --auto-correct --format quiet --force-exclusion lib/exercism-config.rb && \
4
+ git diff --name-status --staged | grep '^[MA]' | grep -o '\s\+.*rb' | xargs git add
@@ -1,12 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
- require 'exercism_config'
4
+ require 'exercism-config'
5
5
  require 'erb'
6
6
  require 'yaml'
7
7
 
8
- env = ExercismConfig::DetermineEnvironment.call
9
- if env == :production
8
+ if Exercism.env.production?
10
9
  puts 'Aborted! This script should not be run in production.'
11
10
  exit
12
11
  end
@@ -17,7 +16,7 @@ def create_table(client)
17
16
  attribute_definitions: [
18
17
  {
19
18
  attribute_name: 'id',
20
- attribute_type: 'S'
19
+ attribute_type: 'S'
21
20
  }
22
21
  ],
23
22
  key_schema: [
@@ -71,9 +70,9 @@ settings_file =
71
70
  elsif ENV['EXERCISM_DOCKER']
72
71
  File.expand_path('../settings/docker.yml', __dir__)
73
72
  elsif ENV['EXERCISM_CI']
74
- File.expand_path('../settings/test-ci.yml', __dir__)
73
+ File.expand_path('../settings/ci.yml', __dir__)
75
74
  else
76
- File.expand_path('../settings/development.yml', __dir__)
75
+ File.expand_path('../settings/local.yml', __dir__)
77
76
  end
78
77
 
79
78
  puts "Using settings file: #{settings_file}"
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "bundler/setup"
3
- require "exercism_config"
3
+ require "exercism-config"
4
4
 
5
5
  # Only allow this to run in development
6
- return unless Exercism.environment == :development
6
+ return if Exercism.env.production?
7
7
 
8
8
  puts "Create AWS/DynamoDB tables..."
9
9
 
@@ -15,7 +15,7 @@ Exercism.config.dynamodb_client = ExercismConfig::SetupDynamoDBClient.()
15
15
 
16
16
  # We don't need this running for CI atm as none of our
17
17
  # tests actually hit s3. Although we might choose to change this
18
- unless ENV["EXERCISM_CI"]
18
+ unless ENV["EXERCISM_CI"] || ENV["EXERCISM_SKIP_S3"]
19
19
  begin
20
20
  ExercismConfig::SetupS3Client.().create_bucket(bucket: Exercism.config.aws_iterations_bucket)
21
21
  rescue Seahorse::Client::NetworkingError => e
@@ -3,6 +3,7 @@ require 'mandate'
3
3
  require 'ostruct'
4
4
  require 'json'
5
5
 
6
+ require_relative 'exercism_config/environment'
6
7
  require_relative 'exercism_config/determine_environment'
7
8
  require_relative 'exercism_config/generate_aws_settings'
8
9
  require_relative 'exercism_config/setup_dynamodb_client'
@@ -14,11 +15,15 @@ require_relative 'exercism_config/version'
14
15
  require_relative 'exercism/config'
15
16
 
16
17
  module Exercism
17
- class ConfigError < RuntimeError
18
+ class ConfigError < RuntimeError; end
19
+
20
+ def self.env
21
+ @env ||= ExercismConfig::DetermineEnvironment.()
18
22
  end
19
23
 
20
24
  def self.environment
21
- @environment ||= ExercismConfig::DetermineEnvironment.()
25
+ puts "Exercism.environment is deprecated. Use Exercism.env"
26
+ env
22
27
  end
23
28
 
24
29
  def self.config
@@ -1,12 +1,26 @@
1
1
  module Exercism
2
2
  class Config < OpenStruct
3
+ PROPS_WITH_TEST_SUFFIX = %i[
4
+ dynamodb_tooling_jobs_table
5
+ ].freeze
6
+
3
7
  def initialize(data, aws_settings)
4
8
  super(data)
5
9
  self.aws_settings = aws_settings
6
10
  end
7
11
 
12
+ PROPS_WITH_TEST_SUFFIX.each do |prop|
13
+ define_method prop do
14
+ Exercism.env.test? ? "#{super()}-test" : super()
15
+ end
16
+ end
17
+
8
18
  def to_json(*_args)
9
- to_h.to_json
19
+ hash = to_h
20
+ PROPS_WITH_TEST_SUFFIX.each do |prop|
21
+ hash[prop] = send(prop)
22
+ end
23
+ hash.to_json
10
24
  end
11
25
  end
12
26
  end
@@ -6,11 +6,7 @@ module ExercismConfig
6
6
  env = ENV['EXERCISM_ENV'] || ENV['RAILS_ENV'] || ENV['APP_ENV']
7
7
  raise Exercism::ConfigError, 'No environment set - set one of EXERCISM_ENV, RAILS_ENV or APP_ENV' unless env
8
8
 
9
- unless %w[development test production].include?(env)
10
- raise Exercism::ConfigError, "environment must be one of development, test or production. Got #{env}."
11
- end
12
-
13
- env.to_sym
9
+ Environment.new(env)
14
10
  end
15
11
  end
16
12
  end
@@ -0,0 +1,49 @@
1
+ module ExercismConfig
2
+ class Environment
3
+ ALLOWED_ENVS = %{development test production}
4
+ private_constant :ALLOWED_ENVS
5
+
6
+ def initialize(raw_env)
7
+ @env = raw_env.to_s
8
+
9
+ unless ALLOWED_ENVS.include?(env)
10
+ raise Exercism::ConfigError, "environment must be one of development, test or production. Got #{env}."
11
+ end
12
+ end
13
+
14
+ def ==(other)
15
+ env == other.to_s
16
+ end
17
+
18
+ def eql?(other)
19
+ env == other.to_s
20
+ end
21
+
22
+ def hash
23
+ env.hash
24
+ end
25
+
26
+ def to_s
27
+ env
28
+ end
29
+
30
+ def inspect
31
+ env
32
+ end
33
+
34
+ def development?
35
+ env == "development"
36
+ end
37
+
38
+ def test?
39
+ env == "test"
40
+ end
41
+
42
+ def production?
43
+ env == "production"
44
+ end
45
+
46
+ private
47
+ attr_reader :env
48
+ end
49
+ end
@@ -13,26 +13,17 @@ module ExercismConfig
13
13
 
14
14
  memoize
15
15
  def aws_access_key_id
16
- case Exercism.environment
17
- when :development, :test
18
- 'FAKE'
19
- end
16
+ Exercism.env.production? ? nil : 'FAKE'
20
17
  end
21
18
 
22
19
  memoize
23
20
  def aws_secret_access_key
24
- case Exercism.environment
25
- when :development, :test
26
- 'FAKE'
27
- end
21
+ Exercism.env.production? ? nil : 'FAKE'
28
22
  end
29
23
 
30
24
  memoize
31
25
  def profile
32
- case Exercism.environment
33
- when :production
34
- 'exercism_staging'
35
- end
26
+ Exercism.env.production? ? nil : 'exercism_staging'
36
27
  end
37
28
  end
38
29
  end
@@ -3,7 +3,7 @@ module ExercismConfig
3
3
  include Mandate
4
4
 
5
5
  def call
6
- return generate_mock if Exercism.environment == :test
6
+ return generate_mock if Exercism.env.test?
7
7
 
8
8
  retrieve_from_dynamodb
9
9
  end
@@ -14,11 +14,11 @@ module ExercismConfig
14
14
  require 'yaml'
15
15
 
16
16
  filename = if ENV["EXERCISM_CI"]
17
- 'test-ci'
17
+ 'ci'
18
18
  elsif ENV["EXERCISM_DOCKER"]
19
- 'test-docker'
19
+ 'docker'
20
20
  else
21
- 'test-local'
21
+ 'local'
22
22
  end
23
23
 
24
24
  settings_file = File.expand_path("../../../settings/#{filename}.yml", __FILE__)
@@ -36,13 +36,6 @@ module ExercismConfig
36
36
  h[item['id']] = item['value']
37
37
  end
38
38
 
39
- # Tweak things for dynamodb when we're running in test mode
40
- if Exercism.environment == :test
41
- %w[dynamodb_tooling_jobs_table].each do |key|
42
- data[key] = "#{data[key]}-test"
43
- end
44
- end
45
-
46
39
  aws_settings = GenerateAwsSettings.()
47
40
  Exercism::Config.new(data, aws_settings)
48
41
  rescue Exercism::ConfigError
@@ -15,14 +15,11 @@ module ExercismConfig
15
15
  end
16
16
 
17
17
  private
18
- attr_reader :environment
19
18
 
20
19
  memoize
21
20
  def config_endpoint
22
- return nil unless %i[development test].include?(Exercism.environment)
23
- if Exercism.environment == :test && ENV['EXERCISM_CI']
24
- return "http://127.0.0.1:#{ENV['DYNAMODB_PORT']}"
25
- end
21
+ return nil if Exercism.env.production?
22
+ return "http://127.0.0.1:#{ENV['DYNAMODB_PORT']}" if Exercism.env.test? && ENV['EXERCISM_CI']
26
23
 
27
24
  host = ENV['EXERCISM_DOCKER'] ? 'dynamodb:8000' : 'localhost:3040'
28
25
  "http://#{host}"
@@ -18,11 +18,10 @@ module ExercismConfig
18
18
  end
19
19
 
20
20
  private
21
- attr_reader :environment
22
21
 
23
22
  memoize
24
23
  def config_endpoint
25
- return nil unless %i[development test].include?(Exercism.environment)
24
+ return nil if Exercism.env.production?
26
25
  return "http://127.0.0.1:#{ENV['S3_PORT']}" if ENV['EXERCISM_CI']
27
26
 
28
27
  host = ENV['EXERCISM_DOCKER'] ? 's3:9090' : 'localhost:3041'
@@ -1,3 +1,3 @@
1
1
  module ExercismConfig
2
- VERSION = '0.33.0'.freeze
2
+ VERSION = '0.38.0'.freeze
3
3
  end
File without changes
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exercism-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.33.0
4
+ version: 0.38.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-06 00:00:00.000000000 Z
11
+ date: 2020-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb
@@ -147,20 +147,19 @@ files:
147
147
  - bin/setup_exercism_config
148
148
  - bin/setup_exercism_local_aws
149
149
  - exercism_config.gemspec
150
+ - lib/exercism-config.rb
150
151
  - lib/exercism/config.rb
151
- - lib/exercism_config.rb
152
152
  - lib/exercism_config/determine_environment.rb
153
+ - lib/exercism_config/environment.rb
153
154
  - lib/exercism_config/generate_aws_settings.rb
154
155
  - lib/exercism_config/retrieve.rb
155
156
  - lib/exercism_config/setup_dynamodb_client.rb
156
157
  - lib/exercism_config/setup_s3_client.rb
157
158
  - lib/exercism_config/version.rb
158
159
  - package.json
159
- - settings/development.yml
160
+ - settings/ci.yml
160
161
  - settings/docker.yml
161
- - settings/test-ci.yml
162
- - settings/test-docker.yml
163
- - settings/test-local.yml
162
+ - settings/local.yml
164
163
  - yarn.lock
165
164
  homepage: https://exercism.io
166
165
  licenses: []
@@ -1,9 +0,0 @@
1
- anycable_redis_url: redis://some_anycable_redis_url:1234/9
2
- anycable_rpc_host: 1.2.3.4:9876543
3
- aws_iterations_bucket: some-iterations-bucket
4
- dynamodb_tooling_jobs_table: some_tooling_table
5
- spi_url: http://some_url:1234
6
- tooling_orchestrator_url: http://some_orchestrator_url:1234
7
-
8
- mysql_master_endpoint: mysql
9
- mysql_port: 3306
@@ -1,9 +0,0 @@
1
- anycable_redis_url: redis://some_anycable_redis_url:1234/9
2
- anycable_rpc_host: 1.2.3.4:9876543
3
- aws_iterations_bucket: some-iterations-bucket
4
- dynamodb_tooling_jobs_table: some_tooling_table
5
- spi_url: http://some_url:1234
6
- tooling_orchestrator_url: http://some_orchestrator_url:1234
7
-
8
- mysql_master_endpoint: localhost
9
- mysql_socket: /tmp/mysql.sock