exercism_config 0.6.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/lib/exercism/config.rb +5 -0
- data/lib/exercism_config.rb +10 -4
- data/lib/exercism_config/generate_aws_settings.rb +60 -0
- data/lib/exercism_config/retrieve.rb +35 -7
- data/lib/exercism_config/setup_dynamodb_client.rb +34 -0
- data/lib/exercism_config/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29923659114d2bf254bad2e019a321f070cb3ff299ed4ea8ce715e92b8fd316e
|
4
|
+
data.tar.gz: ab184837acd4f8df85259f8b92004a6b120232874d1b83cccdb7a4afcddaf8f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 893a4ffaa832a31aed0896a6191ce52e466a5cf1341a2f96674a55373cf0b011a815e51f3e832b38e4166616a95102cc4347ed63b549f3407f67efc7fb533947
|
7
|
+
data.tar.gz: 424ce4177752ef4da4d8745ff1d3766396ff9ccd7a872cf1697383b3d73eec13933bc149dcf36665496f6eb8d8b11c1eacd44f989d8882eb9e0ebcb888f77a52
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
exercism_config (0.
|
4
|
+
exercism_config (0.8.0)
|
5
5
|
aws-sdk-dynamodb (~> 1.0)
|
6
6
|
mandate
|
7
7
|
zeitwerk
|
@@ -10,8 +10,8 @@ GEM
|
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
12
|
aws-eventstream (1.1.0)
|
13
|
-
aws-partitions (1.
|
14
|
-
aws-sdk-core (3.104.
|
13
|
+
aws-partitions (1.345.0)
|
14
|
+
aws-sdk-core (3.104.3)
|
15
15
|
aws-eventstream (~> 1, >= 1.0.2)
|
16
16
|
aws-partitions (~> 1, >= 1.239.0)
|
17
17
|
aws-sigv4 (~> 1.1)
|
data/lib/exercism/config.rb
CHANGED
data/lib/exercism_config.rb
CHANGED
@@ -1,14 +1,20 @@
|
|
1
|
-
require "exercism_config/version"
|
2
1
|
require 'aws-sdk-dynamodb'
|
3
2
|
require 'mandate'
|
4
3
|
require "ostruct"
|
5
4
|
require 'json'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
require_relative 'exercism_config/generate_aws_settings'
|
7
|
+
require_relative 'exercism_config/setup_dynamodb_client.rb'
|
8
|
+
require_relative 'exercism_config/retrieve'
|
9
|
+
require_relative 'exercism_config/generate_aws_settings'
|
10
|
+
require_relative "exercism_config/version"
|
11
|
+
|
12
|
+
require_relative 'exercism/config'
|
10
13
|
|
11
14
|
module Exercism
|
15
|
+
class ConfigError < RuntimeError
|
16
|
+
end
|
17
|
+
|
12
18
|
def self.config
|
13
19
|
@config ||= ExercismConfig::Retrieve.()
|
14
20
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module ExercismConfig
|
2
|
+
class GenerateAwsSettings
|
3
|
+
include Mandate
|
4
|
+
|
5
|
+
def initialize(environment)
|
6
|
+
@environment = environment
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
{
|
11
|
+
region: 'eu-west-2',
|
12
|
+
profile: profile,
|
13
|
+
access_key_id: aws_access_key_id,
|
14
|
+
secret_access_key: aws_secret_access_key
|
15
|
+
}.select {|k,v|v}
|
16
|
+
end
|
17
|
+
|
18
|
+
memoize
|
19
|
+
def aws_access_key_id
|
20
|
+
case environment
|
21
|
+
when :development, :test
|
22
|
+
"FAKE"
|
23
|
+
else
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
memoize
|
29
|
+
def aws_secret_access_key
|
30
|
+
case environment
|
31
|
+
when :development, :test
|
32
|
+
"FAKE"
|
33
|
+
else
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
memoize
|
39
|
+
def profile
|
40
|
+
case environment
|
41
|
+
when :production
|
42
|
+
"exercism_staging"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
memoize
|
47
|
+
def environment
|
48
|
+
return @environment.to_sym if @environment
|
49
|
+
|
50
|
+
env = ENV["EXERCISM_ENV"] || ENV["RAILS_ENV"] || ENV["APP_ENV"]
|
51
|
+
raise Exercism::ConfigError, "No environment set - set one of EXERCISM_ENV, RAILS_ENV or APP_ENV" unless env
|
52
|
+
|
53
|
+
unless %w[development test production].include?(env)
|
54
|
+
raise Exercism::ConfigError, "environments must be one of development test production. Got #{env}"
|
55
|
+
end
|
56
|
+
|
57
|
+
env.to_sym
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -2,26 +2,54 @@ module ExercismConfig
|
|
2
2
|
class Retrieve
|
3
3
|
include Mandate
|
4
4
|
|
5
|
+
def initialize(environment = nil)
|
6
|
+
@environment = environment
|
7
|
+
end
|
8
|
+
|
5
9
|
def call
|
6
|
-
|
10
|
+
client = SetupDynamodbClient.(environment)
|
11
|
+
|
12
|
+
resp = client.scan({table_name: "config"})
|
7
13
|
items = resp.to_h[:items]
|
8
14
|
data = items.each_with_object({}) do |item, h|
|
9
15
|
h[item['id']] = item['value']
|
10
16
|
end
|
11
17
|
|
12
|
-
|
13
|
-
Exercism::Config.new(data)
|
18
|
+
aws_settings = GenerateAwsSettings.(environment)
|
19
|
+
Exercism::Config.new(data, aws_settings)
|
20
|
+
rescue Exercism::ConfigError
|
21
|
+
raise
|
14
22
|
rescue => e
|
15
|
-
|
16
|
-
Exercism::Config.new(retrieved: false)
|
23
|
+
raise Exercism::ConfigError, "Exercism Config could not be loaded: #{e.message}"
|
17
24
|
end
|
18
25
|
|
26
|
+
private
|
19
27
|
memoize
|
20
28
|
def aws_client
|
21
|
-
config = {
|
22
|
-
|
29
|
+
config = {
|
30
|
+
region: 'eu-west-2',
|
31
|
+
profile: profile,
|
32
|
+
endpoint: endpoint,
|
33
|
+
access_key_id: aws_access_key_id,
|
34
|
+
secret_access_key: aws_secret_access_key
|
35
|
+
}.select {|k,v|v}
|
36
|
+
|
23
37
|
Aws::DynamoDB::Client.new(config)
|
24
38
|
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
|
25
53
|
end
|
26
54
|
end
|
27
55
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ExercismConfig
|
2
|
+
class SetupDynamodbClient
|
3
|
+
include Mandate
|
4
|
+
|
5
|
+
def initialize(environment)
|
6
|
+
@environment = environment
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
aws_settings = GenerateAwsSettings.(environment).merge(
|
11
|
+
endpoint: config_endpoint,
|
12
|
+
|
13
|
+
# We don't want a profile for this AWS service
|
14
|
+
# as we run it locally. But we do normally, so
|
15
|
+
# we locally override this here.
|
16
|
+
profile: nil
|
17
|
+
).select {|k,v|v}
|
18
|
+
Aws::DynamoDB::Client.new(aws_settings)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
attr_reader :environment
|
23
|
+
|
24
|
+
memoize
|
25
|
+
def config_endpoint
|
26
|
+
case environment
|
27
|
+
when :development, :test
|
28
|
+
"http://localhost:3039"
|
29
|
+
else
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
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.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-dynamodb
|
@@ -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: []
|