exercism_config 0.6.0 → 0.7.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: 7f5437331bdc9a30d28e75f8b2d52a83731a8b6325ad40427161c4edbeda3b2f
4
- data.tar.gz: 0ff95cfb22a9dd00729bac7ab623dcad09dcf6f8215c16d64361b76212877515
3
+ metadata.gz: 620afb9bb7623f6ed560ad3e6431b4466ad985379c4e0af174b8a635fc4b19df
4
+ data.tar.gz: ad2d2b64388d893da5099aa3d3827a706c5ec98de2e1ca5e0f2802d0e79d41a8
5
5
  SHA512:
6
- metadata.gz: d3e974bbc21351e74bb4daa8158092e5a68e14c6607dae3efe0c5b99e796d634210ec15bd79b23cefdeead02140679d123cb073c41823b73db7c3dabe6b7c89d
7
- data.tar.gz: 76dc94e414a665130976c1cf318b6ba150119895184f7a81e108491192b15b210f585802c3454db38a1c8da253e3489ca08ba8785184040c83d8cae83b521321
6
+ metadata.gz: 105e94188dbcd307eba148de2107912e1bb35431181f0ee1399b49553a1420d2db946ee467a0a12d81ad784138f68c785905b3ae349b63a9592f65e8cd5b5641
7
+ data.tar.gz: 9c2bb195adf603c26c9d0236f21b35c1bdef5b57ebbca7ccc3f91c8c0b4ec21d9cc28a379314ed04813c1f40a9b6f4cfc257b292a46330e924cdef58e477f962
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- exercism_config (0.5.0)
4
+ exercism_config (0.6.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.343.0)
14
- aws-sdk-core (3.104.1)
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)
@@ -1,5 +1,10 @@
1
1
  module Exercism
2
2
  class Config < OpenStruct
3
+ def initialize(data, aws_settings)
4
+ super(data)
5
+ self.aws_settings = aws_settings
6
+ end
7
+
3
8
  def to_json
4
9
  to_h.to_json
5
10
  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
- resp = aws_client.scan({table_name: "config"})
10
+ aws_settings = GenerateAwsSettings.(environment)
11
+ client = Aws::DynamoDB::Client.new(aws_settings)
12
+
13
+ resp = client.scan({table_name: "config"})
7
14
  items = resp.to_h[:items]
8
15
  data = items.each_with_object({}) do |item, h|
9
16
  h[item['id']] = item['value']
10
17
  end
11
18
 
12
- data[:retrieved] = true
13
- Exercism::Config.new(data)
19
+ Exercism::Config.new(data, aws_settings)
20
+ rescue Exercism::ConfigError
21
+ raise
14
22
  rescue => e
15
- p "No Exercism config retrieved"
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 = {region: 'eu-west-2'}
22
- config[:profile] = ENV["AWS_PROFILE"] if ENV["AWS_PROFILE"]
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
 
@@ -1,3 +1,3 @@
1
1
  module ExercismConfig
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  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.6.0
4
+ version: 0.7.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-22 00:00:00.000000000 Z
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