env_setup 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +133 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +76 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/env_setup +35 -0
- data/bin/setup +8 -0
- data/docs/README.md +56 -0
- data/docs/pull_request_template.md +16 -0
- data/env_setup.gemspec +28 -0
- data/lib/env_setup.rb +20 -0
- data/lib/env_setup/builder/base.rb +14 -0
- data/lib/env_setup/builder/generator.rb +24 -0
- data/lib/env_setup/builder/input.rb +25 -0
- data/lib/env_setup/builder/nested_value.rb +13 -0
- data/lib/env_setup/builder/pattern.rb +29 -0
- data/lib/env_setup/configuration.rb +12 -0
- data/lib/env_setup/env_builder.rb +69 -0
- data/lib/env_setup/version.rb +5 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a240cc9e78f87a6c91ad9fc36d47ee3505dee43963dffd78c2683881c5fe072f
|
4
|
+
data.tar.gz: 890c36f37359a7148789a7b17db747f9d10a5fa8188d1958912736e8add80984
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba6f0b467ccbb05a95e1106f43e820550ef265d9aabd8c93e2ead5a218f50583656b7747579b472e8fb253488bf5e654614944e9edbb1e258133df7e7814ae73
|
7
|
+
data.tar.gz: 84c3e6f5cc6f516e34d11973e1c9cf6b6e04c7570576ed824e9d7e7f892bb52a933150227734a07e92279a3516425efe75445e31bc38d403fafdaf1c38c0da62
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
Layout/LineLength:
|
4
|
+
Max: 120
|
5
|
+
Style/Documentation:
|
6
|
+
Enabled: false
|
7
|
+
Metrics/ClassLength:
|
8
|
+
Enabled: false
|
9
|
+
Metrics/ModuleLength:
|
10
|
+
Enabled: false
|
11
|
+
Layout/MultilineMethodCallIndentation:
|
12
|
+
EnforcedStyle: indented_relative_to_receiver
|
13
|
+
Layout/ArgumentAlignment:
|
14
|
+
EnforcedStyle: with_fixed_indentation
|
15
|
+
# https://github.com/rubocop-hq/rubocop/issues/4222#issuecomment-290722962
|
16
|
+
Lint/AmbiguousBlockAssociation:
|
17
|
+
Exclude:
|
18
|
+
- spec/**/*
|
19
|
+
RSpec/AnyInstance:
|
20
|
+
Enabled: false
|
21
|
+
RSpec/NestedGroups:
|
22
|
+
Enabled: false
|
23
|
+
AllCops:
|
24
|
+
NewCops: enable
|
25
|
+
TargetRubyVersion: 2.6
|
26
|
+
Exclude:
|
27
|
+
- Gemfile
|
28
|
+
- bin/*
|
29
|
+
Metrics/BlockLength:
|
30
|
+
Exclude:
|
31
|
+
- spec/**/*
|
32
|
+
Layout/BeginEndAlignment: # (new in 0.91)
|
33
|
+
Enabled: true
|
34
|
+
Layout/EmptyLinesAroundAttributeAccessor: # (new in 0.83)
|
35
|
+
Enabled: true
|
36
|
+
Layout/SpaceAroundMethodCallOperator: # (new in 0.82)
|
37
|
+
Enabled: true
|
38
|
+
Lint/BinaryOperatorWithIdenticalOperands: # (new in 0.89)
|
39
|
+
Enabled: true
|
40
|
+
Lint/ConstantDefinitionInBlock: # (new in 0.91)
|
41
|
+
Enabled: true
|
42
|
+
Lint/DeprecatedOpenSSLConstant: # (new in 0.84)
|
43
|
+
Enabled: true
|
44
|
+
Lint/DuplicateElsifCondition: # (new in 0.88)
|
45
|
+
Enabled: true
|
46
|
+
Lint/DuplicateRequire: # (new in 0.90)
|
47
|
+
Enabled: true
|
48
|
+
Lint/DuplicateRescueException: # (new in 0.89)
|
49
|
+
Enabled: true
|
50
|
+
Lint/EmptyConditionalBody: # (new in 0.89)
|
51
|
+
Enabled: true
|
52
|
+
Lint/EmptyFile: # (new in 0.90)
|
53
|
+
Enabled: true
|
54
|
+
Lint/FloatComparison: # (new in 0.89)
|
55
|
+
Enabled: true
|
56
|
+
Lint/HashCompareByIdentity: # (new in 0.93)
|
57
|
+
Enabled: true
|
58
|
+
Lint/IdentityComparison: # (new in 0.91)
|
59
|
+
Enabled: true
|
60
|
+
Lint/MissingSuper: # (new in 0.89)
|
61
|
+
Enabled: true
|
62
|
+
Lint/MixedRegexpCaptureTypes: # (new in 0.85)
|
63
|
+
Enabled: true
|
64
|
+
Lint/OutOfRangeRegexpRef: # (new in 0.89)
|
65
|
+
Enabled: true
|
66
|
+
Lint/RaiseException: # (new in 0.81)
|
67
|
+
Enabled: true
|
68
|
+
Lint/RedundantSafeNavigation: # (new in 0.93)
|
69
|
+
Enabled: true
|
70
|
+
Lint/SelfAssignment: # (new in 0.89)
|
71
|
+
Enabled: true
|
72
|
+
Lint/StructNewOverride: # (new in 0.81)
|
73
|
+
Enabled: true
|
74
|
+
Lint/TopLevelReturnWithArgument: # (new in 0.89)
|
75
|
+
Enabled: true
|
76
|
+
Lint/TrailingCommaInAttributeDeclaration: # (new in 0.90)
|
77
|
+
Enabled: true
|
78
|
+
Lint/UnreachableLoop: # (new in 0.89)
|
79
|
+
Enabled: true
|
80
|
+
Lint/UselessMethodDefinition: # (new in 0.90)
|
81
|
+
Enabled: true
|
82
|
+
Lint/UselessTimes: # (new in 0.91)
|
83
|
+
Enabled: true
|
84
|
+
Style/AccessorGrouping: # (new in 0.87)
|
85
|
+
Enabled: true
|
86
|
+
Style/BisectedAttrAccessor: # (new in 0.87)
|
87
|
+
Enabled: true
|
88
|
+
Style/CaseLikeIf: # (new in 0.88)
|
89
|
+
Enabled: true
|
90
|
+
Style/ClassEqualityComparison: # (new in 0.93)
|
91
|
+
Enabled: true
|
92
|
+
Style/CombinableLoops: # (new in 0.90)
|
93
|
+
Enabled: true
|
94
|
+
Style/ExplicitBlockArgument: # (new in 0.89)
|
95
|
+
Enabled: true
|
96
|
+
Style/ExponentialNotation: # (new in 0.82)
|
97
|
+
Enabled: true
|
98
|
+
Style/GlobalStdStream: # (new in 0.89)
|
99
|
+
Enabled: true
|
100
|
+
Style/HashAsLastArrayItem: # (new in 0.88)
|
101
|
+
Enabled: true
|
102
|
+
Style/HashEachMethods: # (new in 0.80)
|
103
|
+
Enabled: true
|
104
|
+
Style/HashLikeCase: # (new in 0.88)
|
105
|
+
Enabled: true
|
106
|
+
Style/HashTransformKeys: # (new in 0.80)
|
107
|
+
Enabled: true
|
108
|
+
Style/HashTransformValues: # (new in 0.80)
|
109
|
+
Enabled: true
|
110
|
+
Style/KeywordParametersOrder: # (new in 0.90)
|
111
|
+
Enabled: true
|
112
|
+
Style/OptionalBooleanParameter: # (new in 0.89)
|
113
|
+
Enabled: true
|
114
|
+
Style/RedundantAssignment: # (new in 0.87)
|
115
|
+
Enabled: true
|
116
|
+
Style/RedundantFetchBlock: # (new in 0.86)
|
117
|
+
Enabled: true
|
118
|
+
Style/RedundantFileExtensionInRequire: # (new in 0.88)
|
119
|
+
Enabled: true
|
120
|
+
Style/RedundantRegexpCharacterClass: # (new in 0.85)
|
121
|
+
Enabled: true
|
122
|
+
Style/RedundantRegexpEscape: # (new in 0.85)
|
123
|
+
Enabled: true
|
124
|
+
Style/RedundantSelfAssignment: # (new in 0.90)
|
125
|
+
Enabled: true
|
126
|
+
Style/SingleArgumentDig: # (new in 0.89)
|
127
|
+
Enabled: true
|
128
|
+
Style/SlicingWithRange: # (new in 0.83)
|
129
|
+
Enabled: true
|
130
|
+
Style/SoleNestedConditional: # (new in 0.89)
|
131
|
+
Enabled: true
|
132
|
+
Style/StringConcatenation: # (new in 0.89)
|
133
|
+
Enabled: true
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
env_setup (0.1.0)
|
5
|
+
aws-sdk-secretsmanager (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
aws-eventstream (1.1.1)
|
12
|
+
aws-partitions (1.449.0)
|
13
|
+
aws-sdk-core (3.114.0)
|
14
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
15
|
+
aws-partitions (~> 1, >= 1.239.0)
|
16
|
+
aws-sigv4 (~> 1.1)
|
17
|
+
jmespath (~> 1.0)
|
18
|
+
aws-sdk-secretsmanager (1.46.0)
|
19
|
+
aws-sdk-core (~> 3, >= 3.112.0)
|
20
|
+
aws-sigv4 (~> 1.1)
|
21
|
+
aws-sigv4 (1.2.3)
|
22
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
23
|
+
diff-lcs (1.3)
|
24
|
+
jmespath (1.4.0)
|
25
|
+
parallel (1.20.1)
|
26
|
+
parser (3.0.1.0)
|
27
|
+
ast (~> 2.4.1)
|
28
|
+
rainbow (3.0.0)
|
29
|
+
rake (10.4.2)
|
30
|
+
regexp_parser (2.1.1)
|
31
|
+
rexml (3.2.5)
|
32
|
+
rspec (3.6.0)
|
33
|
+
rspec-core (~> 3.6.0)
|
34
|
+
rspec-expectations (~> 3.6.0)
|
35
|
+
rspec-mocks (~> 3.6.0)
|
36
|
+
rspec-core (3.6.0)
|
37
|
+
rspec-support (~> 3.6.0)
|
38
|
+
rspec-expectations (3.6.0)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.6.0)
|
41
|
+
rspec-mocks (3.6.0)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.6.0)
|
44
|
+
rspec-support (3.6.0)
|
45
|
+
rubocop (1.12.1)
|
46
|
+
parallel (~> 1.10)
|
47
|
+
parser (>= 3.0.0.0)
|
48
|
+
rainbow (>= 2.2.2, < 4.0)
|
49
|
+
regexp_parser (>= 1.8, < 3.0)
|
50
|
+
rexml
|
51
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
52
|
+
ruby-progressbar (~> 1.7)
|
53
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
54
|
+
rubocop-ast (1.4.1)
|
55
|
+
parser (>= 2.7.1.5)
|
56
|
+
rubocop-rspec (2.2.0)
|
57
|
+
rubocop (~> 1.0)
|
58
|
+
rubocop-ast (>= 1.1.0)
|
59
|
+
ruby-progressbar (1.11.0)
|
60
|
+
unicode-display_width (2.0.0)
|
61
|
+
|
62
|
+
PLATFORMS
|
63
|
+
ruby
|
64
|
+
|
65
|
+
DEPENDENCIES
|
66
|
+
bundler (~> 2.1)
|
67
|
+
env_setup!
|
68
|
+
rake (~> 10.0)
|
69
|
+
rspec (~> 3.0)
|
70
|
+
rubocop-rspec (~> 2.2)
|
71
|
+
|
72
|
+
RUBY VERSION
|
73
|
+
ruby 2.7.2p137
|
74
|
+
|
75
|
+
BUNDLED WITH
|
76
|
+
2.1.4
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# EnvSetup
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/env_setup`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'env_setup'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install env_setup
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/MindSciences/rails-env-setup.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mind_sciences/env_setup"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/env_setup
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'env_setup/env_builder'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
inputs = Hash[ARGV.flat_map { |s| s.scan(/--?([^=\s]+)(?:=(\S+))?/) }]
|
7
|
+
template_file = inputs.delete('TEMPLATE')
|
8
|
+
template = JSON.parse(File.read(template_file))
|
9
|
+
env_file = inputs.delete('ENV_FILE') || '.env'
|
10
|
+
aws_access_key = inputs.delete('AWS_ACCESS_KEY')
|
11
|
+
aws_secret_access_key = inputs.delete('AWS_SECRET_ACCESS_KEY')
|
12
|
+
aws_region = inputs.delete('AWS_REGION')
|
13
|
+
aws_secret_name = inputs.delete('AWS_SECRET_NAME')
|
14
|
+
generate_env_file = inputs.key?('GENERATE_ENV_FILE')
|
15
|
+
env_name = inputs.delete('ENV_NAME')
|
16
|
+
|
17
|
+
EnvSetup.configure do |config|
|
18
|
+
config.template = template
|
19
|
+
config.env_name = env_name
|
20
|
+
config.aws_access_key = aws_access_key
|
21
|
+
config.aws_secret_access_key = aws_secret_access_key
|
22
|
+
config.aws_region = aws_region
|
23
|
+
config.aws_secret_name = aws_secret_name
|
24
|
+
end
|
25
|
+
|
26
|
+
generator = EnvSetup::EnvBuilder.new(inputs)
|
27
|
+
json = generator.build_json
|
28
|
+
if generate_env_file
|
29
|
+
File.open(env_file, 'w') do |f|
|
30
|
+
json.each do |key, value|
|
31
|
+
f.puts("#{key}=#{value}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
puts json
|
data/bin/setup
ADDED
data/docs/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
This folder includes documentation about the current repo:
|
2
|
+
|
3
|
+
1. Coding Standards
|
4
|
+
2. Policies
|
5
|
+
3. Guidelines
|
6
|
+
4. Resources
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
# 1. Coding Standards
|
11
|
+
|
12
|
+
The repo includes `.rubocop.yml` that is used for formatting code.
|
13
|
+
|
14
|
+
# 2. Policies
|
15
|
+
|
16
|
+
## Pull Requests
|
17
|
+
|
18
|
+
Every change will go into a new branch and a PR will be created to merge. A template is available and will be automatically used when creating a PR. The following steps should be performed by each party:
|
19
|
+
|
20
|
+
### Developer
|
21
|
+
1. Update the `CHANGELOG.md` file and commit all changes to a new branch
|
22
|
+
2. Create a PR from new branch against `develop`
|
23
|
+
3. Fill in the PR template
|
24
|
+
4. Request a review from the designated reviewer
|
25
|
+
5. *OPTIONAL* Deploy branch to `development` environment
|
26
|
+
|
27
|
+
### Reviewer
|
28
|
+
|
29
|
+
1. Go through each step of the checklist
|
30
|
+
2. If all tasks are completed successfully, merge the PR into `develop`
|
31
|
+
3. Create a new PR against `production` or `master`
|
32
|
+
4. Assign PR to release manager
|
33
|
+
|
34
|
+
# 3. Guidelines
|
35
|
+
Any information on good pracitces and related can go here:
|
36
|
+
|
37
|
+
### Reviewing Pull Requests
|
38
|
+
- do once a day - morning or evening
|
39
|
+
- do setup a local env to easily test changes
|
40
|
+
- do check for consistency with existing code and good practices
|
41
|
+
- do ask questions or request comments when something's not clear or too complex
|
42
|
+
|
43
|
+
### Changelogs
|
44
|
+
The repo must include a `CHANGELOG.md` file to list all changes. The accepted chnages types are:
|
45
|
+
|
46
|
+
- **Added** for new features.
|
47
|
+
- **Changed** for changes in existing functionality.
|
48
|
+
- **Deprecated** for soon-to-be removed features.
|
49
|
+
- **Removed** for now removed features.
|
50
|
+
- **Fixed** for any bug fixes.
|
51
|
+
- **Security** in case of vulnerabilities.
|
52
|
+
|
53
|
+
# 4. Resources
|
54
|
+
Documentation can be uploaded to the `docs` folder. Any useful links should be listed below:
|
55
|
+
|
56
|
+
- Changelogs - https://keepachangelog.com/en/1.0.0/
|
@@ -0,0 +1,16 @@
|
|
1
|
+
## Pull Request
|
2
|
+
|
3
|
+
### 1. Task
|
4
|
+
_Ticket ID or task description_
|
5
|
+
|
6
|
+
### 2. Acceptance criteria
|
7
|
+
- [ ] _Rules defined in the ticket_
|
8
|
+
|
9
|
+
### 3. Notes (deployment, devices/platforms/os to test, etc.)
|
10
|
+
_None_
|
11
|
+
|
12
|
+
## Reviewer's Checklist
|
13
|
+
- [ ] PR summary included – task, acceptance criteria
|
14
|
+
- [ ] Code reviewed – changelog, unit tests, standards
|
15
|
+
- [ ] Review app deployed – Heroku review app or TeamCity deployment
|
16
|
+
- [ ] Acceptance Criteria tested – steps executed on review app
|
data/env_setup.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'env_setup/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'env_setup'
|
7
|
+
spec.version = EnvSetup::VERSION
|
8
|
+
spec.authors = ['Jonatas Daniel Hermann']
|
9
|
+
spec.email = ['jonatas@mindsciences.com']
|
10
|
+
|
11
|
+
spec.summary = %q{Gem to setup apps env}
|
12
|
+
spec.description = %q{Gem to setup apps env}
|
13
|
+
|
14
|
+
# Specify which files should be added to the gem when it is released.
|
15
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
16
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
end
|
19
|
+
spec.bindir = 'bin'
|
20
|
+
spec.executables = ['env_setup']
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.2'
|
27
|
+
spec.add_runtime_dependency 'aws-sdk-secretsmanager', '~> 1.0'
|
28
|
+
end
|
data/lib/env_setup.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'env_setup/version'
|
4
|
+
require 'env_setup/configuration'
|
5
|
+
|
6
|
+
module EnvSetup
|
7
|
+
class InvalidInput < StandardError; end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_writer :configuration
|
11
|
+
|
12
|
+
def configuration
|
13
|
+
@configuration ||= EnvSetup::Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def configure
|
17
|
+
yield(configuration)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'env_setup/builder/base'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
module EnvSetup
|
7
|
+
module Builder
|
8
|
+
class Generator < Base
|
9
|
+
def call
|
10
|
+
raise 'Generator not found' unless respond_to?(template['generator'])
|
11
|
+
|
12
|
+
send(template['generator'])
|
13
|
+
end
|
14
|
+
|
15
|
+
def secret
|
16
|
+
SecureRandom.hex
|
17
|
+
end
|
18
|
+
|
19
|
+
def salt
|
20
|
+
SecureRandom.hex(6)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'env_setup/builder/base'
|
4
|
+
|
5
|
+
module EnvSetup
|
6
|
+
module Builder
|
7
|
+
class Input < Base
|
8
|
+
def call
|
9
|
+
input_value = params[template['input']]
|
10
|
+
valid?(input_value) ? input_value : invalid_error!(template)
|
11
|
+
end
|
12
|
+
|
13
|
+
def invalid_error!(input_name)
|
14
|
+
raise EnvSetup::InvalidInput, "Required input #{input_name}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?(value)
|
18
|
+
return false if value.nil?
|
19
|
+
return false if value.is_a?(String) && value.strip.empty?
|
20
|
+
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'env_setup/builder/base'
|
4
|
+
|
5
|
+
module EnvSetup
|
6
|
+
module Builder
|
7
|
+
class Pattern < Base
|
8
|
+
def call
|
9
|
+
template['pattern'].gsub(regex, params.transform_keys { |key| "{{#{key}}}" })
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def regex
|
15
|
+
Regexp.new(replacements.keys.map { |x| Regexp.escape("{{#{x}}}") }.join('|'))
|
16
|
+
end
|
17
|
+
|
18
|
+
def replacements
|
19
|
+
occurrences.map do |oc|
|
20
|
+
[oc, params[oc]]
|
21
|
+
end.to_h
|
22
|
+
end
|
23
|
+
|
24
|
+
def occurrences
|
25
|
+
template['pattern'].scan(/\{\{([^}]+)\}}(?:\z|[^}])/).flatten
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EnvSetup
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :aws_access_key, :aws_secret_access_key, :aws_region, :aws_secret_name,
|
6
|
+
:template, :env_name
|
7
|
+
|
8
|
+
def aws_ready?
|
9
|
+
aws_secret_name && aws_access_key && aws_secret_access_key
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'env_setup'
|
4
|
+
require 'env_setup/builder/pattern'
|
5
|
+
require 'env_setup/builder/input'
|
6
|
+
require 'env_setup/builder/generator'
|
7
|
+
require 'env_setup/builder/nested_value'
|
8
|
+
require 'aws-sdk-secretsmanager'
|
9
|
+
|
10
|
+
module EnvSetup
|
11
|
+
class EnvBuilder
|
12
|
+
attr_accessor :inputs, :vars
|
13
|
+
|
14
|
+
def initialize(inputs)
|
15
|
+
@inputs = inputs
|
16
|
+
@vars = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def build_json
|
20
|
+
secrets = aws_secrets
|
21
|
+
configuration.template.merge(secrets).each do |key, var_template|
|
22
|
+
vars[key.to_s] = build_var(var_template)
|
23
|
+
end
|
24
|
+
vars
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_var(var_template)
|
28
|
+
return var_template unless var_template.is_a?(Hash)
|
29
|
+
|
30
|
+
var_builder(var_template).call
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def var_builder(var_template)
|
36
|
+
builder = [
|
37
|
+
{ builder: EnvSetup::Builder::Pattern, if: -> { var_template['pattern'] } },
|
38
|
+
{ builder: EnvSetup::Builder::NestedValue, if: -> { var_template['value'] } },
|
39
|
+
{ builder: EnvSetup::Builder::Input, if: -> { var_template['input'] } },
|
40
|
+
{ builder: EnvSetup::Builder::Generator, if: -> { var_template['generator'] } }
|
41
|
+
].find { |option| option[:if].call }
|
42
|
+
|
43
|
+
builder[:builder].new(var_template, vars.merge(inputs))
|
44
|
+
end
|
45
|
+
|
46
|
+
def configuration
|
47
|
+
EnvSetup.configuration
|
48
|
+
end
|
49
|
+
|
50
|
+
def aws_secrets
|
51
|
+
return {} unless configuration.aws_ready?
|
52
|
+
|
53
|
+
client = Aws::SecretsManager::Client.new(
|
54
|
+
access_key_id: configuration.aws_access_key,
|
55
|
+
secret_access_key: configuration.aws_secret_access_key,
|
56
|
+
region: configuration.aws_region
|
57
|
+
)
|
58
|
+
|
59
|
+
secret_string = client.get_secret_value(secret_id: configuration.aws_secret_name).secret_string
|
60
|
+
JSON.parse(secret_string).transform_values { |p| parse_aws_sm_value(p) }
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_aws_sm_value(value)
|
64
|
+
JSON.parse(value)
|
65
|
+
rescue JSON::ParserError
|
66
|
+
value
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: env_setup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonatas Daniel Hermann
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: aws-sdk-secretsmanager
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
description: Gem to setup apps env
|
84
|
+
email:
|
85
|
+
- jonatas@mindsciences.com
|
86
|
+
executables:
|
87
|
+
- env_setup
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".travis.yml"
|
95
|
+
- CHANGELOG.md
|
96
|
+
- Gemfile
|
97
|
+
- Gemfile.lock
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/env_setup
|
102
|
+
- bin/setup
|
103
|
+
- docs/README.md
|
104
|
+
- docs/pull_request_template.md
|
105
|
+
- env_setup.gemspec
|
106
|
+
- lib/env_setup.rb
|
107
|
+
- lib/env_setup/builder/base.rb
|
108
|
+
- lib/env_setup/builder/generator.rb
|
109
|
+
- lib/env_setup/builder/input.rb
|
110
|
+
- lib/env_setup/builder/nested_value.rb
|
111
|
+
- lib/env_setup/builder/pattern.rb
|
112
|
+
- lib/env_setup/configuration.rb
|
113
|
+
- lib/env_setup/env_builder.rb
|
114
|
+
- lib/env_setup/version.rb
|
115
|
+
homepage:
|
116
|
+
licenses: []
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubygems_version: 3.1.4
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Gem to setup apps env
|
137
|
+
test_files: []
|