exercism_config 0.3.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ec5ba69e2df0cd02184e3d20f1cd63ba802757cc487156309b98034a1b4ba38
4
- data.tar.gz: 3bc8a60971c4044173b505973280d07406a1f7b4e29cc6f8c837f3fa840eb501
3
+ metadata.gz: 71a5de3c08bfc4ab61bdb04d5485cd053390f6d1818435a175f29da692e42a66
4
+ data.tar.gz: 852681840f57d2ad6a794467cbb2668d1db56033f0237ac6f550caf56d749285
5
5
  SHA512:
6
- metadata.gz: 0db5ab28e34abeaee6198d4cc9e05f7123add3aff3fbab05e940f5acefecd98fbf8de0ce8c84b69543539702585a33a4cbf655dd051233b0de563e19408abe89
7
- data.tar.gz: e102862c3978879c87769bc4d60c63d528a5375b207a17b08905787c9f0592d7ed0b6689839fcc198572dce20974f33dcc76123a39552d40072b58ab7a35db06
6
+ metadata.gz: bb70e7d39140ba7667d098c048e08e2a8cc0c4a576315bc6411dd9b1238a31b2841954964d6b4fa177b4fb37b2875919c02152058292f87574b3a33c8d92c0b2
7
+ data.tar.gz: 551dc4256d3655a466f853178a9c94453229445ae5704df5f7f34ce6a61cf2a60fa90c6eaf35f60d4b9d74ee418fbc4f86aa35d2da12e01b03938b1c1bbc5b6d
data/Gemfile CHANGED
@@ -4,4 +4,3 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
- gem "minitest", "~> 5.0"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- exercism_config (0.2.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.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)
@@ -24,8 +24,9 @@ GEM
24
24
  jmespath (1.4.0)
25
25
  mandate (0.3.0)
26
26
  minitest (5.14.1)
27
+ mocha (1.11.2)
27
28
  rake (12.3.3)
28
- zeitwerk (2.3.0)
29
+ zeitwerk (2.4.0)
29
30
 
30
31
  PLATFORMS
31
32
  ruby
@@ -34,6 +35,7 @@ DEPENDENCIES
34
35
  bundler (~> 2.1)
35
36
  exercism_config!
36
37
  minitest (~> 5.0)
38
+ mocha
37
39
  rake (~> 12.0)
38
40
 
39
41
  BUNDLED WITH
data/README.md CHANGED
@@ -1,15 +1,16 @@
1
1
  # Exercism Config
2
2
 
3
- When terraform creates Exercism's infrastructure, it writes endpoints and DNS entries to DynamoDB.
3
+ When terraform creates Exercism's infrastructure, it writes endpoints and DNS entries to DynamoDB.
4
4
  This gem allows you to trivially retrieve that data.
5
5
 
6
- When running on AWS, simply ensure the machine has read-access to the relevant table (currently hardcoded to `config`).
6
+ When running on AWS, simply ensure the machine has read-access to the relevant table (currently hardcoded to `config`).
7
7
  On a local machine specify the AWS_PROFILE environment variable with the relevant profile stored in your `.aws/credentials`.
8
8
 
9
- ## Usage
9
+ ## Usage
10
10
 
11
11
  Simply include this gem in your Gemfile, require it, and then refer to the object:
12
- ```
12
+
13
+ ```ruby
13
14
  # Gemfile
14
15
  gem 'exercism_config'
15
16
 
@@ -19,6 +20,7 @@ ExercismConfig.config.webservers_alb_dns_name
19
20
  ```
20
21
 
21
22
  To print out all the config from the command-line, you can run:
22
- ```
23
+
24
+ ```bash
23
25
  AWS_PROFILE=exercism_terraform ./bin/run
24
26
  ```
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "bundler", "~> 2.1"
30
30
  spec.add_development_dependency "rake", "~> 12.3"
31
31
  spec.add_development_dependency "minitest", "~> 5.0"
32
+ spec.add_development_dependency "mocha"
32
33
  end
@@ -0,0 +1,12 @@
1
+ module Exercism
2
+ class Config < OpenStruct
3
+ def initialize(data, aws_settings)
4
+ super(data)
5
+ self.aws_settings = aws_settings
6
+ end
7
+
8
+ def to_json
9
+ to_h.to_json
10
+ end
11
+ end
12
+ end
@@ -1,15 +1,21 @@
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
- require "zeitwerk"
8
- loader = Zeitwerk::Loader.for_gem
9
- loader.setup
6
+ require 'exercism_config/generate_aws_settings'
7
+ require 'exercism_config/setup_dynamodb_client.rb'
8
+ require 'exercism_config/retrieve'
9
+ require 'exercism_config/generate_aws_settings'
10
+ require "exercism_config/version"
11
+
12
+ require 'exercism/config'
13
+
14
+ module Exercism
15
+ class ConfigError < RuntimeError
16
+ end
10
17
 
11
- module ExercismConfig
12
18
  def self.config
13
- @config ||= Retrieve.()
19
+ @config ||= ExercismConfig::Retrieve.()
14
20
  end
15
21
  end
@@ -2,22 +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
+ 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
- Config.new(data)
18
+ aws_settings = GenerateAwsSettings.(environment)
19
+ Exercism::Config.new(data, aws_settings)
20
+ rescue Exercism::ConfigError
21
+ raise
22
+ rescue => e
23
+ raise Exercism::ConfigError, "Exercism Config could not be loaded: #{e.message}"
13
24
  end
14
25
 
26
+ private
15
27
  memoize
16
28
  def aws_client
17
- config = {region: 'eu-west-2'}
18
- 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
+
19
37
  Aws::DynamoDB::Client.new(config)
20
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
21
53
  end
22
54
  end
23
55
 
@@ -1,3 +1,3 @@
1
1
  module ExercismConfig
2
- VERSION = "0.3.0"
2
+ VERSION = "0.9.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.3.0
4
+ version: 0.9.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
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '5.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description:
98
112
  email:
99
113
  - jez.walker@gmail.com
@@ -111,8 +125,8 @@ files:
111
125
  - bin/run
112
126
  - bin/setup
113
127
  - exercism_config.gemspec
128
+ - lib/exercism/config.rb
114
129
  - lib/exercism_config.rb
115
- - lib/exercism_config/config.rb
116
130
  - lib/exercism_config/retrieve.rb
117
131
  - lib/exercism_config/version.rb
118
132
  homepage: https://exercism.io
@@ -1,7 +0,0 @@
1
- module ExercismConfig
2
- class Config < OpenStruct
3
- def to_json
4
- to_h.to_json
5
- end
6
- end
7
- end