exercism_config 0.10.0 → 0.15.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35f4b596c7b39b71b98bcb4b7527c8e24123a1394cc4be0534e43327f687a424
|
4
|
+
data.tar.gz: 584ca75bfcce88f47f376fb0170a21fccaa7077d3267a98fc7476637a0d33993
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b2329c0819e6eed73f9a7aa07e3faf17c7dc2892bd232ce0557f527f920e76bd67143415646107c3503a9782d4ebd7afd6f7969cb448c97836ce4e56d2d4739
|
7
|
+
data.tar.gz: cc76afee5a592ff5d6867e0558eaae30c0be245701712ff3f386ef8ceeb5c6ffd8a759a001ab5dd850a60d4dd08e0c552ef86f19eb641aff636c8391ee70aafc
|
data/Gemfile.lock
CHANGED
data/lib/exercism_config.rb
CHANGED
@@ -3,8 +3,9 @@ require 'mandate'
|
|
3
3
|
require "ostruct"
|
4
4
|
require 'json'
|
5
5
|
|
6
|
+
require_relative 'exercism_config/determine_environment'
|
6
7
|
require_relative 'exercism_config/generate_aws_settings'
|
7
|
-
require_relative 'exercism_config/setup_dynamodb_client
|
8
|
+
require_relative 'exercism_config/setup_dynamodb_client'
|
8
9
|
require_relative 'exercism_config/retrieve'
|
9
10
|
require_relative 'exercism_config/generate_aws_settings'
|
10
11
|
require_relative "exercism_config/version"
|
@@ -15,6 +16,10 @@ module Exercism
|
|
15
16
|
class ConfigError < RuntimeError
|
16
17
|
end
|
17
18
|
|
19
|
+
def self.environment
|
20
|
+
@environment ||= ExercismConfig::DetermineEnvironment.()
|
21
|
+
end
|
22
|
+
|
18
23
|
def self.config
|
19
24
|
@config ||= ExercismConfig::Retrieve.()
|
20
25
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ExercismConfig
|
2
|
+
class GenerateAwsSettings
|
3
|
+
include Mandate
|
4
|
+
|
5
|
+
def call
|
6
|
+
{
|
7
|
+
region: 'eu-west-2',
|
8
|
+
profile: profile,
|
9
|
+
access_key_id: aws_access_key_id,
|
10
|
+
secret_access_key: aws_secret_access_key
|
11
|
+
}.select {|k,v|v}
|
12
|
+
end
|
13
|
+
|
14
|
+
memoize
|
15
|
+
def aws_access_key_id
|
16
|
+
case Exercism.environment
|
17
|
+
when :development, :test
|
18
|
+
"FAKE"
|
19
|
+
else
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
memoize
|
25
|
+
def aws_secret_access_key
|
26
|
+
case Exercism.environment
|
27
|
+
when :development, :test
|
28
|
+
"FAKE"
|
29
|
+
else
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
memoize
|
35
|
+
def profile
|
36
|
+
case Exercism.environment
|
37
|
+
when :production
|
38
|
+
"exercism_staging"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -2,12 +2,8 @@ module ExercismConfig
|
|
2
2
|
class Retrieve
|
3
3
|
include Mandate
|
4
4
|
|
5
|
-
def initialize(environment = nil)
|
6
|
-
@environment = environment
|
7
|
-
end
|
8
|
-
|
9
5
|
def call
|
10
|
-
client = SetupDynamodbClient.(
|
6
|
+
client = SetupDynamodbClient.()
|
11
7
|
|
12
8
|
resp = client.scan({table_name: "config"})
|
13
9
|
items = resp.to_h[:items]
|
@@ -15,7 +11,14 @@ module ExercismConfig
|
|
15
11
|
h[item['id']] = item['value']
|
16
12
|
end
|
17
13
|
|
18
|
-
|
14
|
+
# Tweak things for dynamodb when we're running in test mode
|
15
|
+
if Exercism.environment == :test
|
16
|
+
%w{dynamodb_tooling_jobs_table}.each do |key|
|
17
|
+
data[key] = "#{data[key]}-test"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
aws_settings = GenerateAwsSettings.()
|
19
22
|
Exercism::Config.new(data, aws_settings)
|
20
23
|
rescue Exercism::ConfigError
|
21
24
|
raise
|
@@ -36,20 +39,6 @@ module ExercismConfig
|
|
36
39
|
|
37
40
|
Aws::DynamoDB::Client.new(config)
|
38
41
|
end
|
39
|
-
|
40
|
-
memoize
|
41
|
-
def environment
|
42
|
-
return @environment.to_sym if @environment
|
43
|
-
|
44
|
-
env = ENV["EXERCISM_ENV"] || ENV["RAILS_ENV"] || ENV["APP_ENV"]
|
45
|
-
raise Exercism::ConfigError, "No environment set - set one of EXERCISM_ENV, RAILS_ENV or APP_ENV" unless env
|
46
|
-
|
47
|
-
unless %w[development test production].include?(env)
|
48
|
-
raise Exercism::ConfigError, "environments must be one of development test production. Got #{env}"
|
49
|
-
end
|
50
|
-
|
51
|
-
env.to_sym
|
52
|
-
end
|
53
42
|
end
|
54
43
|
end
|
55
44
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ExercismConfig
|
2
|
+
class SetupDynamodbClient
|
3
|
+
include Mandate
|
4
|
+
|
5
|
+
def call
|
6
|
+
aws_settings = GenerateAwsSettings.().merge(
|
7
|
+
endpoint: config_endpoint,
|
8
|
+
|
9
|
+
# We don't want a profile for this AWS service
|
10
|
+
# as we run it locally. But we do normally, so
|
11
|
+
# we locally override this here.
|
12
|
+
profile: nil
|
13
|
+
).select {|k,v|v}
|
14
|
+
Aws::DynamoDB::Client.new(aws_settings)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
attr_reader :environment
|
19
|
+
|
20
|
+
memoize
|
21
|
+
def config_endpoint
|
22
|
+
case Exercism.environment
|
23
|
+
when :development, :test
|
24
|
+
host = ENV["EXERCISM_DOCKER"] ? "dynamodb:8000" : "localhost:3039"
|
25
|
+
"http://#{host}"
|
26
|
+
else
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exercism_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
@@ -127,7 +127,9 @@ files:
|
|
127
127
|
- exercism_config.gemspec
|
128
128
|
- lib/exercism/config.rb
|
129
129
|
- lib/exercism_config.rb
|
130
|
+
- lib/exercism_config/generate_aws_settings.rb
|
130
131
|
- lib/exercism_config/retrieve.rb
|
132
|
+
- lib/exercism_config/setup_dynamodb_client.rb
|
131
133
|
- lib/exercism_config/version.rb
|
132
134
|
homepage: https://exercism.io
|
133
135
|
licenses: []
|