aws2-ssm-env 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +7 -0
- data/LICENSE +201 -0
- data/README.md +358 -0
- data/lib/aws-ssm-env.rb +160 -0
- data/lib/aws-ssm-env/fetcher.rb +120 -0
- data/lib/aws-ssm-env/fetchers/begins_with.rb +84 -0
- data/lib/aws-ssm-env/fetchers/factory.rb +67 -0
- data/lib/aws-ssm-env/fetchers/path.rb +75 -0
- data/lib/aws-ssm-env/loader.rb +67 -0
- data/lib/aws-ssm-env/naming_strategies/basename.rb +19 -0
- data/lib/aws-ssm-env/naming_strategies/factory.rb +68 -0
- data/lib/aws-ssm-env/naming_strategies/snakecase.rb +58 -0
- data/lib/aws-ssm-env/naming_strategy.rb +23 -0
- data/lib/aws-ssm-env/version.rb +3 -0
- data/spec/aws-ssm-env/fetcher_spec.rb +158 -0
- data/spec/aws-ssm-env/fetchers/begins_with_spec.rb +106 -0
- data/spec/aws-ssm-env/fetchers/factory_spec.rb +65 -0
- data/spec/aws-ssm-env/fetchers/path_spec.rb +100 -0
- data/spec/aws-ssm-env/loader_spec.rb +84 -0
- data/spec/aws-ssm-env/naming_strategies/basename_spec.rb +14 -0
- data/spec/aws-ssm-env/naming_strategies/factory_spec.rb +57 -0
- data/spec/aws-ssm-env/naming_strategies/snakecase_spec.rb +78 -0
- data/spec/aws-ssm-env/naming_strategy_spec.rb +11 -0
- data/spec/aws-ssm-env/parameter.rb +7 -0
- data/spec/aws-ssm-env_spec.rb +128 -0
- data/spec/spec_helper.rb +22 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 51224408bb0ae5ed576ec9fa757644160da865e0386189a115494fa0b147b70e
|
4
|
+
data.tar.gz: 0bab660c3ab54f5e39312076db5f6287f1166e0d9e6591b47ad181960f8c8418
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a3effb4ce3f54856596b05881610db4ac415b8f0fb5446295373a3d1b35ffeb230829a90d1562cf238bce4696c3cd8ebad658d30e32617c19fd0f69e6de22c1
|
7
|
+
data.tar.gz: 2a62b708b5ece704e46ca2362b6ceaf5e2c9826f2c6608f671472799161d7434e32cfdd5cd5c2329e97a2c21dde0ca02874b644df87ac82a22a909be690da906
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,358 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/sonodar/aws-ssm-env-ruby.svg?branch=master)](https://travis-ci.org/sonodar/aws-ssm-env-ruby)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/github/sonodar/aws-ssm-env-ruby/badge.svg?branch=master)](https://coveralls.io/github/sonodar/aws-ssm-env-ruby?branch=master)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/aws-ssm-env.svg)](https://badge.fury.io/rb/aws-ssm-env)
|
4
|
+
|
5
|
+
# aws2-ssm-env
|
6
|
+
|
7
|
+
This is a fork of aws-ssm-env that supports aws-sdk v2
|
8
|
+
|
9
|
+
This tool sets parameters acquired from `AWS EC2 Parameter Store` as environment variables.
|
10
|
+
|
11
|
+
By default, the last hierarchy of the parameter name is
|
12
|
+
set as the environment variable name.
|
13
|
+
|
14
|
+
For example, if the parameter name is `/staging/secure/DB_PASSWORD`,
|
15
|
+
the parameter value is set to `ENV['DB_PASSWORD']`.
|
16
|
+
The naming of environment variables is optional and can be customized.
|
17
|
+
(described later)
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
This gem has been tested with ruby version 2.2 to 2.5.
|
22
|
+
|
23
|
+
```
|
24
|
+
gem install aws-ssm-env
|
25
|
+
```
|
26
|
+
|
27
|
+
### Rails
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# Gemfile
|
31
|
+
gem 'aws2-ssm-env', require: 'aws-ssm-env'
|
32
|
+
```
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
# config/application.rb
|
36
|
+
if defined?(AwsSsmEnv)
|
37
|
+
AwsSsmEnv.load(path: "/myapp/#{ENV['RAILS_ENV']}", recursive: true)
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
### Other ruby program
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
require 'aws-ssm-env'
|
45
|
+
AwsSsmEnv.load!(begins_with: "myapp.#{ENV['RACK_ENV']}.")
|
46
|
+
```
|
47
|
+
|
48
|
+
## Quick Start
|
49
|
+
|
50
|
+
First of all, register the parameters in `AWS EC2 Parameter Store`.
|
51
|
+
|
52
|
+
```shell
|
53
|
+
# ex) register /myservice/staging/RDS_PASSWORD with SecureString
|
54
|
+
aws ssm --region ap-northeast-1 put-parameter \
|
55
|
+
--name /myservice/staging/RDS_PASSWORD \
|
56
|
+
--type SecureString --value <secret value>
|
57
|
+
```
|
58
|
+
|
59
|
+
Then, set authentication information of AWS.
|
60
|
+
For example, you can use environment variables as follows,
|
61
|
+
|
62
|
+
```shell
|
63
|
+
export AWS_ACCESS_KEY_ID=YOURACCESSKEYID
|
64
|
+
export AWS_SECRET_ACCESS_KEY=YOURSECRETKEY
|
65
|
+
bundle exec rails start
|
66
|
+
```
|
67
|
+
|
68
|
+
Or, you can pass `ssm_client_args` as the argument for `AwsSsmEnv#load`:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
AwsSsmEnv.load(
|
72
|
+
fetch: "/myservice/#{ENV['RAILS_ENV']}",
|
73
|
+
ssm_client_args: {
|
74
|
+
access_key_id: 'ACCESS_KEY_ID',
|
75
|
+
secret_access_key: 'SECRET_ACCESS_KEY',
|
76
|
+
region: 'ap-northeast-1',
|
77
|
+
}
|
78
|
+
)
|
79
|
+
```
|
80
|
+
|
81
|
+
You can also use `Aws.config`.
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
|
85
|
+
if defined?(AwsSsmEnv)
|
86
|
+
AWS.config({
|
87
|
+
access_key_id: 'ACCESS_KEY_ID',
|
88
|
+
secret_access_key: 'SECRET_ACCESS_KEY',
|
89
|
+
region: 'ap-northeast-1',
|
90
|
+
})
|
91
|
+
AwsSsmEnv.load(path: "/myservice/#{ENV['RAILS_ENV']}")
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
For details, refer to the document of aws-sdk.
|
96
|
+
|
97
|
+
## Develop
|
98
|
+
|
99
|
+
### Unit test
|
100
|
+
|
101
|
+
```shell
|
102
|
+
bundle exec rspec
|
103
|
+
bundle exec rubocop
|
104
|
+
```
|
105
|
+
|
106
|
+
### Integration test
|
107
|
+
|
108
|
+
```shell
|
109
|
+
export AWS_ACCESS_KEY_ID=xxxx
|
110
|
+
export AWS_SECRET_ACCESS_KEY=xxxx
|
111
|
+
export AWS_REGION=xxxx
|
112
|
+
bundle exec rspec --tag integration
|
113
|
+
```
|
114
|
+
|
115
|
+
IAM users who run tests need the following authorization policy:
|
116
|
+
|
117
|
+
```json
|
118
|
+
{
|
119
|
+
"Version": "2012-10-17",
|
120
|
+
"Statement": [
|
121
|
+
{
|
122
|
+
"Sid": "",
|
123
|
+
"Effect": "Allow",
|
124
|
+
"Action": [
|
125
|
+
"ssm:PutParameter",
|
126
|
+
"ssm:DeleteParameters",
|
127
|
+
"ssm:DescribeParameters",
|
128
|
+
"ssm:GetParameters*"
|
129
|
+
],
|
130
|
+
"Resource": "*"
|
131
|
+
}
|
132
|
+
]
|
133
|
+
}
|
134
|
+
```
|
135
|
+
|
136
|
+
|
137
|
+
## Usage
|
138
|
+
|
139
|
+
Here are descriptions of the options passed to `AwsSsmEnv#load`.
|
140
|
+
|
141
|
+
### decryption: [Boolean]
|
142
|
+
|
143
|
+
Flag indicating whether to decrypt SecureString parameters.
|
144
|
+
If `true` is specified, the value of the acquired SecureString parameter is decrypted.
|
145
|
+
In case of `false` it is set as encrypted and environment variable value.
|
146
|
+
Since it is a gem for this, the default is `true` (decrypt).
|
147
|
+
|
148
|
+
### overwrite: [Boolean]
|
149
|
+
|
150
|
+
Specify whether to overwrite an already set environment variable.
|
151
|
+
If `true` is specified, even if the environment variable is set,
|
152
|
+
it overwrites it with the acquired parameter value.
|
153
|
+
If `false` is specified, do not overwrite already set environment variables.
|
154
|
+
The default is `false` (do not overwrite).
|
155
|
+
If you invoke `AwsSsmEnv#load!`, This flag will automatically be set to `true`.
|
156
|
+
|
157
|
+
### client: [Aws::SSM::Client]
|
158
|
+
|
159
|
+
Specify an instance of `Aws::SSM::Client`.
|
160
|
+
An option to set it if there are already created instances.
|
161
|
+
If there are no instances created, use `ssm_client_args` instead.
|
162
|
+
|
163
|
+
### ssm_client_args: [Hash]
|
164
|
+
|
165
|
+
Specify a hash to pass to the constructor of `Aws::SSM::Client`.
|
166
|
+
If not specified, `Aws::SSM::Client#new` is called with an empty argument.
|
167
|
+
It is unnecessary when using environment variable
|
168
|
+
or authentication information by `EC2 InstanceProfile`.
|
169
|
+
|
170
|
+
### fetch: [Symbol, AwsSsmEnv::Fetcher, Object]
|
171
|
+
|
172
|
+
Specify parameter fetch strategy.
|
173
|
+
Possible values are `:path`,`:begins_with`
|
174
|
+
or an instance of a class that implements `AwsSsmEnv::Fetcher`,
|
175
|
+
or an instance of a class with a `each` method.
|
176
|
+
If nothing is specified, it is treated as `:path`.
|
177
|
+
But when `begins_with` (which is described later) is specified,
|
178
|
+
it will automatically be `:begins_with`.
|
179
|
+
|
180
|
+
#### `:fetch => :path` or default
|
181
|
+
|
182
|
+
When `:path` is specified, `AwsSsmEnv::PathFetcher` which fetches
|
183
|
+
parameter hierarchy by path specification is used.
|
184
|
+
In this case, the `path` argument described below is required.
|
185
|
+
Also, the `recursive` argument (described later) is used.
|
186
|
+
When acquiring parameters in this way, you need `ssm:GetParametersByPath` authority
|
187
|
+
for the specified path.
|
188
|
+
An example of the IAM policy is shown below.
|
189
|
+
|
190
|
+
```json
|
191
|
+
{
|
192
|
+
"Version": "2012-10-17",
|
193
|
+
"Statement": [
|
194
|
+
{
|
195
|
+
"Sid": "",
|
196
|
+
"Effect": "Allow",
|
197
|
+
"Action": "ssm:GetParametersByPath",
|
198
|
+
"Resource": "arn:aws:ssm:YOUR_REGION:YOUR_ACCOUNT_ID:parameter/YOUR_PATH"
|
199
|
+
}
|
200
|
+
]
|
201
|
+
}
|
202
|
+
```
|
203
|
+
|
204
|
+
#### `:fetch => :begins_with`
|
205
|
+
|
206
|
+
If `:begins_with` is specified, `AwsSsmEnv::BeginsWithFetcher` is used to fetch
|
207
|
+
parameters starting from the character string specified by the parameter name.
|
208
|
+
In this case, the `begins_with` argument described below is required.
|
209
|
+
When acquiring parameters in this way,
|
210
|
+
you need the authority of `ssm:DescribeParameters` and `ssm:GetParameters`
|
211
|
+
for the specified path.
|
212
|
+
An example of the IAM policy is shown below.
|
213
|
+
|
214
|
+
```json
|
215
|
+
{
|
216
|
+
"Version": "2012-10-17",
|
217
|
+
"Statement": [
|
218
|
+
{
|
219
|
+
"Sid": "",
|
220
|
+
"Effect": "Allow",
|
221
|
+
"Action": "ssm:DescribeParameters",
|
222
|
+
"Resource": "arn:aws:ssm:YOUR_REGION:YOUR_ACCOUNT_ID:parameter"
|
223
|
+
},
|
224
|
+
{
|
225
|
+
"Sid": "",
|
226
|
+
"Effect": "Allow",
|
227
|
+
"Action": "ssm:GetParameters",
|
228
|
+
"Resource": "arn:aws:ssm:YOUR_REGION:YOUR_ACCOUNT_ID:parameter/YOUR_PREFIX*"
|
229
|
+
}
|
230
|
+
]
|
231
|
+
}
|
232
|
+
```
|
233
|
+
|
234
|
+
#### other
|
235
|
+
|
236
|
+
If you specify an instance of a class that implements `AwsSsmEnv::Fetcher` in` fetch`,
|
237
|
+
or an instance with a `each` method, that instance will be used as is.
|
238
|
+
|
239
|
+
### naming: [Symbol, AwsSsmEnv::NamingStrategy, Object]
|
240
|
+
|
241
|
+
Specify the naming strategy for the environment variable name.
|
242
|
+
Possible values are `:basename`,`:snakecase`
|
243
|
+
or an instance of a class that implements `AwsSsmEnv::NamingStrategy`,
|
244
|
+
or an instance of a class with a `parse_name` method.
|
245
|
+
If nothing is specified, it is treated as `:basename`.
|
246
|
+
|
247
|
+
#### `:naming => :basename` or default
|
248
|
+
|
249
|
+
If `naming` is not specified or `:basename` is specified,
|
250
|
+
`AwsSsmEnv::BasenameNamingStrategy` whose variable name is
|
251
|
+
the last hierarchy of the parameter hierarchy is used.
|
252
|
+
In this case, for example, if the parameter name is `/myapp/production/DB_PASSWORD`,
|
253
|
+
the parameter value is set to `ENV['DB_PASSWORD']`.
|
254
|
+
|
255
|
+
#### `:naming => :snakecase`
|
256
|
+
|
257
|
+
When `:snakecase` is specified, `AwsSsmEnv::SnakeCaseNamingStrategy` which uses
|
258
|
+
the underscore delimiter of the parameter name's slash delimiter and converts
|
259
|
+
it to uppercase letters as the environment variable name is used.
|
260
|
+
In this case, for example, if the parameter name is `/myapp/production/DB_PASSWORD`,
|
261
|
+
the parameter value is set to `ENV['MYAPP_PRODUCTION_DB_PASSWORD']`.
|
262
|
+
You can specify first part of string to exclude with
|
263
|
+
the `removed_prefix` argument described below.
|
264
|
+
In addition, you can specify characters to be converted to
|
265
|
+
underscores with the `delimiter` option described below.
|
266
|
+
In the following example, the parameter `/myapp/production/db.password` is
|
267
|
+
set to `ENV['DB_PASSWORD']`.
|
268
|
+
|
269
|
+
```ruby
|
270
|
+
AwsSsmEnv.load!(
|
271
|
+
naming: :snakecase,
|
272
|
+
removed_prefix: '/myapp/production',
|
273
|
+
delimiter: /[\/.]/
|
274
|
+
)
|
275
|
+
```
|
276
|
+
|
277
|
+
#### other
|
278
|
+
|
279
|
+
If you specify an instance of a class that implements `AwsSsmEnv::NamingStrategy` in` fetch`,
|
280
|
+
or an instance with a `parse_name` method, that instance is used as is.
|
281
|
+
|
282
|
+
|
283
|
+
### path: [String]
|
284
|
+
|
285
|
+
Required if nothing is specified for `fetch` or if `:path` is specified.
|
286
|
+
This option specifies the path hierarchy for acquiring parameters from `Parameter Store`.
|
287
|
+
In the example below, the parameter immediately under `/myapp/web/production` is acquired.
|
288
|
+
|
289
|
+
```ruby
|
290
|
+
AwsSsmEnv.load(path: '/myapp/web/production')
|
291
|
+
```
|
292
|
+
|
293
|
+
#### recursive: [Boolean]
|
294
|
+
|
295
|
+
Used when no parameter is specified for `fetch` option or when `:path` is specified.
|
296
|
+
If true is specified, acquires all parameters below the specified path hierarchy.
|
297
|
+
If nothing is specified this parameter, it is treated as `false`(one level).
|
298
|
+
In the following example, all parameters below `/myapp/web/production` are acquired.
|
299
|
+
|
300
|
+
```ruby
|
301
|
+
AwsSsmEnv.load(path: '/myapp/web/production', recursive: true)
|
302
|
+
```
|
303
|
+
|
304
|
+
### begins_with: [String, Array<String>]
|
305
|
+
|
306
|
+
Required if `:begins_with` is specified in `fetch`.
|
307
|
+
You can specify the prefix of the parameter name to be acquired by this option.
|
308
|
+
It is also possible to specify more than one in an array (OR condition).
|
309
|
+
In the example below, parameters with names starting with `myapp.web.production` are acquired.
|
310
|
+
|
311
|
+
```ruby
|
312
|
+
AwsSsmEnv.load(path: 'myapp.web.production')
|
313
|
+
```
|
314
|
+
|
315
|
+
### removed_prefix: [String]
|
316
|
+
|
317
|
+
Used when `:snakecase` is specified in `naming`.
|
318
|
+
By this option, you can specify the prefix of the parameter name to exclude
|
319
|
+
from the environment variable name.
|
320
|
+
If `:removed_ prefix` is not specified, and `:begins_with` or `:path` is specified, that will be used.
|
321
|
+
|
322
|
+
### delimiter: [String, Regexp]
|
323
|
+
|
324
|
+
Used when `:snakecase` is specified in `naming`.
|
325
|
+
By this option, you can specify a string or a regular expression to be converted to an underscore.
|
326
|
+
The default is a slash (`/`).
|
327
|
+
|
328
|
+
### fetch_size: [Integer]
|
329
|
+
|
330
|
+
Specify the number of parameters to be acquired with one execution of AWS API.
|
331
|
+
If `:path` is specified, the maximum value is `10` and the default is `10`.
|
332
|
+
If `:begins_with` is specified, the maximum value is `50` and the default is `50`.
|
333
|
+
Usually this parameter is never specified.
|
334
|
+
|
335
|
+
## Security
|
336
|
+
|
337
|
+
Because you must grant authority to acquire secret information,
|
338
|
+
careful attention is required for security operation.
|
339
|
+
|
340
|
+
|
341
|
+
When the `EC2 InstanceProfile` is set, the parameters can be seen by any account on EC2,
|
342
|
+
It is necessary to improve the security level by preparing an IAM User separately
|
343
|
+
from the `EC2 InstanceProfile`.
|
344
|
+
|
345
|
+
If it is only the administrator that you can log in to EC2,
|
346
|
+
it is not much different from having it in a file.
|
347
|
+
|
348
|
+
Since `AWS Fargate` makes it difficult to execute commands on containers,
|
349
|
+
this risk is mitigated.
|
350
|
+
|
351
|
+
## License
|
352
|
+
|
353
|
+
Apache License 2.0
|
354
|
+
|
355
|
+
## Contributors
|
356
|
+
|
357
|
+
- Ryohei Sonoda <[sonodar](https://github.com/sonodar)>
|
358
|
+
- Carl Allen <[carlallen](https://github.com/carlallen)>
|