Skip to content

Commit dd4b619

Browse files
committed
Basic Systems Manager support.
0 parents  commit dd4b619

18 files changed

+546
-0
lines changed

.byebug_history

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
quit
2+
settings
3+
q
4+
settings
5+
q
6+
settings
7+
quit
8+
settings.class.eql?(Array)
9+
settings.class.eql? Array
10+
settings.class

.github/workflows/main.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Ruby
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
name: Ruby ${{ matrix.ruby }}
14+
strategy:
15+
matrix:
16+
ruby:
17+
- '2.7.0'
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
- name: Set up Ruby
22+
uses: ruby/setup-ruby@v1
23+
with:
24+
ruby-version: ${{ matrix.ruby }}
25+
bundler-cache: true
26+
- name: Run the default task
27+
run: bundle exec rake

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/

Gemfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
# Specify your gem's dependencies in aws-app-settings.gemspec
6+
gemspec
7+
8+
gem "rake", "~> 13.0"
9+
10+
gem "test-unit", "~> 3.0"

Gemfile.lock

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
PATH
2+
remote: .
3+
specs:
4+
aws-app-settings (0.1.0)
5+
awesome_print (~> 2.0.0.pre2)
6+
byebug (~> 11.1, >= 11.1.3)
7+
pry (~> 0.14.1)
8+
vcr (~> 6.1)
9+
10+
GEM
11+
remote: https://rubygems.org/
12+
specs:
13+
awesome_print (2.0.0.pre2)
14+
byebug (11.1.3)
15+
coderay (1.1.3)
16+
method_source (1.0.0)
17+
power_assert (2.0.1)
18+
pry (0.14.1)
19+
coderay (~> 1.1)
20+
method_source (~> 1.0)
21+
rake (13.0.6)
22+
test-unit (3.5.3)
23+
power_assert
24+
vcr (6.1.0)
25+
26+
PLATFORMS
27+
x86_64-linux
28+
29+
DEPENDENCIES
30+
aws-app-settings!
31+
rake (~> 13.0)
32+
test-unit (~> 3.0)
33+
34+
BUNDLED WITH
35+
2.3.19

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022 Ryan Alyn Porter
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# aws-app-settings
2+
3+
A Ruby gem for cloud applications to use for managing configuration settings and secrets with AWS Secrets Manager and AWS Systems Manager.
4+
5+
This gem provides a caching mechanism with a configurable time-to-live, enabling you to rotate your application secrets or change your configuration settings without re-deploying your app.
6+
7+
It will create and retrieve settings using a pattern that includes the application and environment names, for enabling the separation of environments.
8+
9+
## Installation
10+
11+
Install the gem and add to the application's Gemfile by executing:
12+
13+
$ bundle add aws-app-settings
14+
15+
If bundler is not being used to manage dependencies, install the gem by executing:
16+
17+
$ gem install aws-app-settings
18+
19+
## Usage
20+
21+
To get a setting from the cloud, explicitly specifying the name:
22+
23+
Aws::App::Settings.get_list([
24+
{
25+
name: 'testapp-testenvironment-testsetting'
26+
}
27+
])
28+
29+
Returns:
30+
31+
{
32+
'testapp-testenvironment-testsetting' => 'test value'
33+
}
34+
35+
To get a setting from the cloud using a naming convention that includes the application name and the environment name, enabling separation of environments:
36+
37+
Aws::App::Settings.get_list([
38+
{
39+
application: 'testapp',
40+
environment: 'testenvironment',
41+
name: 'testsetting'
42+
}
43+
])
44+
45+
This gets the same secret as the first example, but it encapsulates the logic for computing the name of the setting.
46+
47+
## Development
48+
49+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test-unit` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50+
51+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52+
53+
## Contributing
54+
55+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aws-app-settings.
56+
57+
## License
58+
59+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

Rakefile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler/gem_tasks"
4+
require "rake/testtask"
5+
6+
Rake::TestTask.new(:test) do |t|
7+
t.libs << "test"
8+
t.libs << "lib"
9+
t.test_files = FileList["test/**/*_test.rb"]
10+
end
11+
12+
task default: :test

aws-app-settings.gemspec

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "lib/aws/app/settings/version"
4+
5+
Gem::Specification.new do |spec|
6+
spec.name = "aws-app-settings"
7+
spec.version = Aws::App::Setting::VERSION
8+
spec.authors = ["Ryan Alyn Porter"]
9+
spec.email = ["[email protected]"]
10+
11+
spec.summary =
12+
'A Ruby gem for cloud applications to use for managing configuration ' +
13+
'settings and secrets with AWS Secrets Manager and AWS Systems Manager.'
14+
spec.description = <<-DESC
15+
This gem provides a caching mechanism with a configurable time-to-live, enabling
16+
you to rotate your application secrets or change your configuration settings
17+
without re-deploying your app.
18+
19+
It will create and retrieve settings using a pattern that includes the
20+
application and environment names, for enabling the separation of environments.
21+
DESC
22+
spec.homepage = "https://github.com/VenueDriver/aws-app-settings"
23+
spec.license = "MIT"
24+
spec.required_ruby_version = ">= 2.6.0"
25+
26+
spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
27+
28+
spec.metadata["homepage_uri"] = spec.homepage
29+
spec.metadata["source_code_uri"] = "https://github.com/VenueDriver/aws-app-settings"
30+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
31+
32+
# Specify which files should be added to the gem when it is released.
33+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
34+
spec.files = Dir.chdir(__dir__) do
35+
`git ls-files -z`.split("\x0").reject do |f|
36+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
37+
end
38+
end
39+
spec.bindir = "exe"
40+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
41+
spec.require_paths = ["lib"]
42+
43+
# Uncomment to register a new dependency of your gem
44+
spec.add_dependency 'pry', '~> 0.14.1'
45+
spec.add_dependency 'vcr', '~> 6.1'
46+
spec.add_dependency 'byebug', '~> 11.1', '>= 11.1.3'
47+
spec.add_dependency 'awesome_print', '~> 2.0.0.pre2'
48+
49+
# For more information and examples about making a new gem, check out our
50+
# guide at: https://bundler.io/guides/creating_gem.html
51+
end

bin/console

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "bundler/setup"
5+
require "aws/app/settings"
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
# (If you use this, don't forget to add pry to your Gemfile!)
11+
# require "pry"
12+
# Pry.start
13+
14+
require "irb"
15+
IRB.start(__FILE__)

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

lib/aws/app/settings.rb

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# frozen_string_literal: true
2+
require 'aws-sdk-ssm'
3+
4+
require_relative "settings/version"
5+
6+
module Aws
7+
module App
8+
module Settings
9+
class Error < StandardError; end
10+
11+
def initialize(name:, secret:false, rotate:false)
12+
end
13+
14+
def set(name:)
15+
end
16+
17+
def self.get_list(settings)
18+
raise Error.new 'This method requires a list of settings.' unless
19+
settings.class.eql?(Array)
20+
raise Error.new 'Each setting in the list must be a hash with a name.' unless
21+
settings.all?{|setting| setting.class.eql?(Hash) and
22+
setting[:name] }
23+
24+
settings = settings.map do |setting|
25+
{ name: get_setting_name(setting) }
26+
end
27+
28+
Aws::SSM::Client.new.get_parameters(
29+
names: settings.map{|setting| setting[:name] },
30+
with_decryption: true,
31+
)['parameters'].to_h {
32+
|parameter| [parameter.name, parameter.value] }.tap do |secrets|
33+
if secrets.empty?
34+
raise Error.new 'Could not get settings from AWS SSM. ' +
35+
'Are you authenticated to the correct account?'
36+
end
37+
end
38+
end
39+
40+
def self.get_setting_name(setting)
41+
if setting[:application] and setting[:environment]
42+
[
43+
setting[:application],
44+
setting[:environment],
45+
setting[:name]
46+
].join('-')
47+
elsif setting[:application] or setting[:environment]
48+
raise Error.new 'The application and the environment for ' +
49+
'an application setting must both be specified together.'
50+
else
51+
setting[:name]
52+
end
53+
end
54+
55+
end
56+
end
57+
end

lib/aws/app/settings/version.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
module Aws
4+
module App
5+
module Setting
6+
VERSION = "0.1.0"
7+
end
8+
end
9+
end

sig/aws/app/settings.rbs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Aws
2+
module App
3+
module Settings
4+
VERSION: String
5+
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
6+
end
7+
end
8+
end

0 commit comments

Comments
 (0)