From 2b32b66ade3b62a678fe2b2f008c3240685c8c9a Mon Sep 17 00:00:00 2001 From: Chavez Date: Thu, 24 May 2018 14:06:17 -0400 Subject: [PATCH 1/3] feat: Add Yard Doc for gem - Document gem usage and methods --- Gemfile.lock | 12 ++++++++---- Rakefile | 6 ++++++ lib/sekreto.rb | 30 +++++++++++++++++++++++++++++- lib/sekreto/config.rb | 7 +++++++ lib/sekreto/railtie.rb | 4 ++++ lib/sekreto/version.rb | 2 +- sekreto.gemspec | 1 + 7 files changed, 56 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index c6e7104..626e876 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - sekreto (0.1.3) + sekreto (0.2.0) aws-sdk-secretsmanager multi_json @@ -12,12 +12,14 @@ GEM autocop (0.1.4) rubocop (>= 0.52.1) rubocop-rspec (>= 1.22.1) - aws-partitions (1.86.0) - aws-sdk-core (3.20.2) + aws-eventstream (1.0.0) + aws-partitions (1.87.0) + aws-sdk-core (3.21.2) + aws-eventstream (~> 1.0) aws-partitions (~> 1.0) aws-sigv4 (~> 1.0) jmespath (~> 1.0) - aws-sdk-secretsmanager (1.4.0) + aws-sdk-secretsmanager (1.5.0) aws-sdk-core (~> 3) aws-sigv4 (~> 1.0) aws-sigv4 (1.0.2) @@ -61,6 +63,7 @@ GEM stub_env (1.0.4) rspec (>= 2.0, < 4.0) unicode-display_width (1.3.2) + yard (0.9.12) PLATFORMS ruby @@ -74,6 +77,7 @@ DEPENDENCIES rspec-mocks (~> 3.0) sekreto! stub_env (~> 1.0) + yard (~> 0.9.11) BUNDLED WITH 1.16.1 diff --git a/Rakefile b/Rakefile index cf90d46..2b31614 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,7 @@ require 'bundler' require 'bundler/gem_tasks' require 'rspec/core/rake_task' require 'rubocop/rake_task' +require 'yard' Bundler::GemHelper.install_tasks @@ -19,3 +20,8 @@ desc 'Run specs' RSpec::Core::RakeTask.new('spec') do |task| task.pattern = 'spec/**/*_spec.rb' end + +YARD::Rake::YardocTask.new(:doc) do |task| + task.files = %w[lib/**/*.rb - README.md] + task.options = %w[no-private] +end diff --git a/lib/sekreto.rb b/lib/sekreto.rb index c216712..1b5950d 100644 --- a/lib/sekreto.rb +++ b/lib/sekreto.rb @@ -6,13 +6,30 @@ require 'sekreto/railtie' if defined?(Rails) -# Sekreto holds configuration and interface for getting secrets +# Sekreto allows you to interact with the AWS Secrets Manager to +# retrieve your secrets from Ruby. This exposes a thin wrapper around +# the AWS SecretsManager SDK. module Sekreto class << self + ## + # Set up the Sekreto gem configuration + # + # @yieldreturn [Sekreto::Config] + # + # @example Configuring Sekreto + # Sekreto.setup do |setup| + # setup.prefix = 'app-prefix' + # end def setup yield config if block_given? end + ## + # + # Get the value given a secret + # + # @param secret_id [String] - The secret ID to get the value for + # @return [String] - The value of the stored secret def get_value(secret_id) fail 'Not allowed env' unless config.is_allowed_env.call response = secrets_manager.get_secret_value(secret_id: secret_name(secret_id)) @@ -22,11 +39,22 @@ def get_value(secret_id) config.fallback_lookup.call(secret_id) end + ## + # + # Get the JSON value of a secret + # + # @param secret_id [String] - The secret ID to get the value for + # @return [Hash] - The parsed JSON value of the secret def get_json_value(secret_id) response = get_value(secret_id) MultiJson.load(response) end + ## + # + # Get the configuration for Sekreto + # + # @return [Sekreto::Config] - The configuration def config @config ||= Config.new end diff --git a/lib/sekreto/config.rb b/lib/sekreto/config.rb index f9c8d74..7df7ff1 100644 --- a/lib/sekreto/config.rb +++ b/lib/sekreto/config.rb @@ -1,6 +1,8 @@ require 'logger' module Sekreto + ## + # Config class for setting up Sekreto for usage class Config attr_accessor :prefix attr_accessor :is_allowed_env @@ -8,6 +10,11 @@ class Config attr_accessor :secrets_manager attr_accessor :logger + ## + # + # Initialize a new Config + # + # @return [Sekreto::Config] def initialize @prefix = 'secrets' @is_allowed_env = -> { true } diff --git a/lib/sekreto/railtie.rb b/lib/sekreto/railtie.rb index 2811bed..984a8ec 100644 --- a/lib/sekreto/railtie.rb +++ b/lib/sekreto/railtie.rb @@ -1,5 +1,9 @@ module Sekreto # Rails Railtie to set up the Sekreto configuration + # + # Defaults the secrets Manager to Aws::SecretsManager::Client.new + # Defaults the prefix to Rails app name and Rails.env e.g. foo-staging + # Defaults allowed envs to check Rails.env is production or staging class Railtie < ::Rails::Railtie config.after_initialize do app_name = ::Rails.application.class.to_s.split('::').first.downcase diff --git a/lib/sekreto/version.rb b/lib/sekreto/version.rb index 60afda7..bf1903e 100644 --- a/lib/sekreto/version.rb +++ b/lib/sekreto/version.rb @@ -1,3 +1,3 @@ module Sekreto - VERSION = '0.1.3'.freeze + VERSION = '0.2.0'.freeze end diff --git a/sekreto.gemspec b/sekreto.gemspec index 272c191..a8d4edd 100644 --- a/sekreto.gemspec +++ b/sekreto.gemspec @@ -28,4 +28,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rspec', '~> 3.0' spec.add_development_dependency 'rspec-mocks', '~> 3.0' spec.add_development_dependency 'stub_env', '~> 1.0' + spec.add_development_dependency 'yard', '~> 0.9.11' end From f05511713801a0058483cd9f7421edb48a6668f8 Mon Sep 17 00:00:00 2001 From: Chavez Date: Thu, 24 May 2018 14:06:59 -0400 Subject: [PATCH 2/3] feat: Use before_initialization instead of after --- lib/sekreto/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sekreto/railtie.rb b/lib/sekreto/railtie.rb index 984a8ec..fdf1fe5 100644 --- a/lib/sekreto/railtie.rb +++ b/lib/sekreto/railtie.rb @@ -5,7 +5,7 @@ module Sekreto # Defaults the prefix to Rails app name and Rails.env e.g. foo-staging # Defaults allowed envs to check Rails.env is production or staging class Railtie < ::Rails::Railtie - config.after_initialize do + config.before_initialize do app_name = ::Rails.application.class.to_s.split('::').first.downcase Sekreto.setup do |setup| From cec0c8ff869c52c0770f330aff13465d951ad154 Mon Sep 17 00:00:00 2001 From: Chavez Date: Thu, 24 May 2018 14:09:58 -0400 Subject: [PATCH 3/3] chore: Update CHANGELOG --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index defcf65..4adc34b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v0.2.0 (2018-05-24) + +- Remove dependency on Rails [pr #5][pr5] +- Add Yard Documentation +- Use `before_initialize` for railtie + ## v0.1.3 (2018-05-01) - Capture exceptions and use fallback when getting secrets values @@ -5,3 +11,5 @@ ## v0.1.1 (2018-04-27) - Initial release of gem + +[pr5]: https://github.com/autolist/sekreto/pull/5