ssm_env 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 +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +5 -0
- data/README.md +57 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/ssm_env +38 -0
- data/lib/ssm_env.rb +42 -0
- data/lib/ssm_env/client.rb +7 -0
- data/lib/ssm_env/fetcher.rb +27 -0
- data/lib/ssm_env/version.rb +3 -0
- data/ssm_env.gemspec +25 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a11f9965fb726f83a85d662d6f1649a4ff2a3106
|
4
|
+
data.tar.gz: 86ac0e1d169704ed95aba6f29ab966cc56e2cc0e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed3922984296110875313c5c97a7221c052327cb2c9194ee18ebd69e3cf7ff217d96d5dfd54dba0c09659c746ff3bb1d7d31d871a37fcc6710853a7a64791020
|
7
|
+
data.tar.gz: 81294fdce45b857095b0485412153eda80bc4f424e15cc8a8611f63efdd85427bdd4220d858c1f1f4eb0672717d444ea1b311c11a2465015b025ed8a396b832e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# SsmEnv
|
2
|
+
|
3
|
+
This gem is meant to fetch string and encrypted string parameters from AWS SSM and store them either in a file or in the local environment.
|
4
|
+
## Pre Install
|
5
|
+
|
6
|
+
Ensure you have AWS access variables configured for use with the Ruby SDK, as defined in the V2 Ruby SDK Docs - http://docs.aws.amazon.com/sdkforruby/api/
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ssm_env'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ssm_env
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
####Use this from the command line like
|
26
|
+
|
27
|
+
**Output Values**
|
28
|
+
```
|
29
|
+
ssm_env show -i "[BRANCH_KEY, VACUUM_RATE]"
|
30
|
+
ssm_env show -i ssm_param_names.yml
|
31
|
+
```
|
32
|
+
|
33
|
+
**Synch your environment**
|
34
|
+
```
|
35
|
+
ssm_env sync -i "[BRANCH_KEY, VACUUM_RATE]"
|
36
|
+
ssm_env sync -i ssm_param_names.yml
|
37
|
+
```
|
38
|
+
|
39
|
+
####Use this in ruby like
|
40
|
+
```
|
41
|
+
ssm_env = SsmEnv.new.run(params_list: [BRANCH_KEY, VACUUM_LIMIT])
|
42
|
+
# Update the environment
|
43
|
+
ssm_env.to_env
|
44
|
+
# Store in a file
|
45
|
+
ssm_env.to_file('/tmp/my_vars.env')
|
46
|
+
```
|
47
|
+
|
48
|
+
## Development
|
49
|
+
|
50
|
+
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.
|
51
|
+
|
52
|
+
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).
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ssm_env.
|
57
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ssm_env"
|
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
|
data/bin/setup
ADDED
data/bin/ssm_env
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparser'
|
3
|
+
require 'ssm_env'
|
4
|
+
require 'thor'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
class SsmEnvCmd < Thor
|
8
|
+
include SsmEnv
|
9
|
+
desc 'show', 'show one or more variables'
|
10
|
+
method_option :input, aliases: '-i', required: true, banner: 'a string or filepath containing a list of params to pull from ssm'
|
11
|
+
def show
|
12
|
+
fetch_params_list
|
13
|
+
self.fetch(params_list: @params_list)
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'sync', 'store the environment in this process'
|
17
|
+
method_option :input, aliases: '-i', required: true, banner: 'a string or filepath containing a list of params to pull from ssm'
|
18
|
+
def sync
|
19
|
+
fetch_params_list
|
20
|
+
self.fetch(params_list: @params_list)
|
21
|
+
self.ssm_params.each do |name, attributes|
|
22
|
+
system({name => attributes[:value]})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def fetch_params_list
|
28
|
+
@params_list = []
|
29
|
+
p "Fetching parameters: #{@params_list}"
|
30
|
+
if File.exists?(options[:input])
|
31
|
+
@params_list = YAML.load(File.read(options[:input]))
|
32
|
+
elsif options[:input].is_a?(Array) || options[:input].is_a?(String)
|
33
|
+
@params_list = options[:input].to_s.split(',').to_a
|
34
|
+
else
|
35
|
+
raise ArgumentError.new("Invalid input provided #{options[:input]}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/ssm_env.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
$: << File.expand_path('./lib/ssm_env')
|
2
|
+
require 'ostruct'
|
3
|
+
require "ssm_env/version"
|
4
|
+
require "ssm_env/fetcher"
|
5
|
+
require "ssm_env/client"
|
6
|
+
|
7
|
+
module SsmEnv
|
8
|
+
include Fetcher
|
9
|
+
attr_reader :configured, :config
|
10
|
+
alias_method :configured?, :configured
|
11
|
+
|
12
|
+
# Configure the client using parameters or using a block provided
|
13
|
+
def configure(region: 'us-east-1', access_key_id: nil, secret_access_key: nil)
|
14
|
+
@config ||= OpenStruct.new(
|
15
|
+
region: (region || ENV['AWS_REGION']),
|
16
|
+
access_key_id: (access_key_id || ENV['AWS_ACCESS_KEY_ID']),
|
17
|
+
secret_access_key: (secret_access_key || ENV['AWS_SECRET_ACCESS_KEY']),
|
18
|
+
params_list: [] )
|
19
|
+
|
20
|
+
yield(@config) if block_given?
|
21
|
+
@configured = true
|
22
|
+
end
|
23
|
+
|
24
|
+
def run(params_list:nil)
|
25
|
+
configure unless self.configured?
|
26
|
+
@client = Client.get_client(region: @config.region,
|
27
|
+
access_key_id: @config.access_key_id,
|
28
|
+
secret_access_key: @config.secret_access_key)
|
29
|
+
self.fetch(client: @client, params_list: (params_list || config.params_list))
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_env
|
34
|
+
self.ssm_params.each { |name, attribs| ENV[name.to_s] = attribs[:value] }
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_file(path: '/etc/profile.d/ssm')
|
38
|
+
File.open(path, 'w') do |f|
|
39
|
+
self.ssm_parms.each { |name, attribs| f << "#{name}=#{attribs[:value]}\n"}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
module Fetcher
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.send :attr_accessor, :ssm_params
|
7
|
+
base.send :include, InstanceMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
def fetch(client:, params_list:)
|
12
|
+
raise ArgumentError.new("Client is incompatable type #{client.class}") unless client.is_a?(Aws::SSM::Client)
|
13
|
+
batch_size = 10
|
14
|
+
self.ssm_params ||= {}
|
15
|
+
params_list.each_slice(batch_size) do |params_slice|
|
16
|
+
response = client.get_parameters(names: params_slice, with_decryption: true)
|
17
|
+
# Transforms to { :name => { value: value, type: type } }
|
18
|
+
response_params = Hash[response.parameters.map { |item| [item.name.to_sym, {value: item.value, type: item.type}] }]
|
19
|
+
response_params.each do |name, attributes|
|
20
|
+
self.ssm_params[name] ||= {}
|
21
|
+
self.ssm_params[name][:value] = attributes[:value]
|
22
|
+
self.ssm_params[name][:type] = attributes[:type]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/ssm_env.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ssm_env/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ssm_env"
|
8
|
+
spec.version = SsmEnv::VERSION
|
9
|
+
spec.authors = ["Rob Lane"]
|
10
|
+
spec.email = ["rob@everlance.com"]
|
11
|
+
|
12
|
+
spec.summary = "Synchronize your AWS SSM parameters to your environment"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
15
|
+
spec.bindir = "exe"
|
16
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_runtime_dependency "aws-sdk", "~> 2.0"
|
20
|
+
spec.add_runtime_dependency "thor", "0.20"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ssm_env
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Lane
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.20'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.20'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- rob@everlance.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- bin/ssm_env
|
99
|
+
- lib/ssm_env.rb
|
100
|
+
- lib/ssm_env/client.rb
|
101
|
+
- lib/ssm_env/fetcher.rb
|
102
|
+
- lib/ssm_env/version.rb
|
103
|
+
- ssm_env.gemspec
|
104
|
+
homepage:
|
105
|
+
licenses: []
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.6.14
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Synchronize your AWS SSM parameters to your environment
|
127
|
+
test_files: []
|