biscuit 0.0.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 67a2dd92f873d5ac7e7ca2b8464fcd8e6b49d6b0
4
- data.tar.gz: 135d6b22c9cbb9ae526df66a6a539c52f5740e5f
2
+ SHA256:
3
+ metadata.gz: c0ae8dd43c9d7b9cf11433ec6f56f8417d9df0a237396162f85a9a54eecb14af
4
+ data.tar.gz: ade9a35a78ea2e62c0ae1786b98a1f1c41f4e02186b6a4ccb9a246ffecc60ae4
5
5
  SHA512:
6
- metadata.gz: 51479480b630c1f95bd73a52ba0cc0ca0e7dd20c1e0f168ee6878f116301163b14c9ec608e5583ade08aa5eb9a6b97a281db0c271f4e9572fbe2c67a57cb3e46
7
- data.tar.gz: 60e4c3c4ea99e3e8e7248ad927581754077b4baa1cac138cfe7b9388d1c4d82750d480aed153c99e8c6e295fb72ba961dcac16b666bc43f40b3b30f0f1b32281
6
+ metadata.gz: 6a50e6cb9da879f6537aa10768bd2821d69771df478ec86ece1e88a918a54bc2e9ad0f06055f6cb9a4bfbfb4cfc03689d82925c80ef7245ad0778541ae04ab1a
7
+ data.tar.gz: 6ba191f9c910089ca2a92f6545a3cd46149d2d9e3071cc0fb0166831808eb855aaac1b9cb09a09e9086595fd1c05b871445d6c915b632bfe17e9d6416a9430e7
@@ -0,0 +1,17 @@
1
+ name: Publish Gem
2
+
3
+ on:
4
+ release:
5
+ types:
6
+ - published
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v1
13
+ - name: Release Gem
14
+ uses: cadwallion/publish-rubygems-action@master
15
+ env:
16
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17
+ RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
@@ -0,0 +1,21 @@
1
+ name: Ruby CI
2
+
3
+ on: [push, pull_request]
4
+ jobs:
5
+ build:
6
+ name: build (${{ matrix.ruby }} / ${{ matrix.os }})
7
+ strategy:
8
+ matrix:
9
+ ruby: [ "3.0", "2.7", "2.6", "2.5", "2.4", "2.3", head ]
10
+ os: [ ubuntu-latest ]
11
+ runs-on: ${{ matrix.os }}
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ - name: Install dependencies
19
+ run: bundle install
20
+ - name: Run test
21
+ run: bundle exec rspec spec
data/.gitignore CHANGED
@@ -3,7 +3,9 @@
3
3
  /Gemfile.lock
4
4
  /_yardoc/
5
5
  /coverage/
6
- /doc/
7
6
  /pkg/
8
7
  /spec/reports/
9
8
  /tmp/
9
+
10
+ # This is downloaded when the gem is installed:
11
+ bin/_biscuit
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,21 @@
1
+ # 0.2.0
2
+ - [FIX] Resolve File.exists? deprecation removal in latest Ruby.
3
+ - Bump upstream biscuit binary dependency to latest 0.1.4 release.
4
+ - Adds diagnostic logging to install task.
5
+
6
+ # 0.1.4
7
+ - [FIX] `open()` is deprecated for URIs. Uses `URI.open()`
8
+ - Bumps bundler version
9
+ - Bumps rake gem version
10
+
11
+ # 0.1.3
12
+ - No changes - apparently there was already a yanked 0.1.2 out there somewhere
13
+
14
+ # 0.1.2
15
+
16
+ - [FIX] Revert to using `YAML.load` to load the secrets
17
+ - [FIX] Don't split values containing `:` into broken pieces
18
+ - Relax `rake` dependency
19
+ - [DOC] Fill out README
20
+ - Set up CI
21
+ - Gitignore the actual `biscuit` binary
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in biscuit.gemspec
4
4
  gemspec
5
+
6
+ gem "rspec"
7
+ gem "coveralls", require: false
data/LICENSE CHANGED
@@ -1,5 +1,5 @@
1
1
  The MIT License (MIT)
2
- Copyright (c) 2016 User Testing, Inc.
2
+ Copyright (c) 2019 User Testing, Inc.
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5
5
  and associated documentation files (the "Software"), to deal in the Software without restriction,
data/README.md CHANGED
@@ -1,28 +1,108 @@
1
1
  # Biscuit
2
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/biscuit`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Travis](https://img.shields.io/travis/usertesting/biscuit?style=for-the-badge)](https://travis-ci.org/usertesting/biscuit) [![Coveralls github](https://img.shields.io/coveralls/github/usertesting/biscuit?style=for-the-badge)](https://coveralls.io/github/usertesting/biscuit) [![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/usertesting/biscuit?style=for-the-badge)](https://codeclimate.com/github/usertesting/biscuit)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+
6
+ This gem is a Ruby wrapper around `@dcoker`'s [biscuit library](https://github.com/dcoker/biscuit), a multi-region HA key-value store for your AWS infrastructure secrets.
7
+
8
+ By using this Ruby library, it is easy to integrate into a Ruby/Rails stack.
6
9
 
7
10
  ## Installation
8
11
 
9
- Add this line to your application's Gemfile:
12
+ - Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'biscuit'
16
+ ```
17
+
18
+ - And then run `bundle`.
19
+
20
+ - `touch` a yaml file (or multiple for different environments).
21
+
22
+ ## Usage
23
+
24
+ ### Loading K/V pairs into a hash
10
25
 
11
26
  ```ruby
12
- gem 'biscuit'
27
+ secrets_file = "some_yaml_file.yaml"
28
+ SECRETS = Biscuit::SecretsDecrypter.new(secrets_file).load
29
+
30
+ puts SECRETS["some_password"]
31
+ # => "decrypted password"
13
32
  ```
14
33
 
15
- And then execute:
34
+ ### Loading into ENV Vars
16
35
 
17
- $ bundle
36
+ If you store config in ENV vars as suggested by the [12 Factor App](https://12factor.net/config), you can load your AWS encrypted secrets into ENV vars like this:
18
37
 
19
- Or install it yourself as:
38
+ ```ruby
39
+ secrets_file = "some_yaml_file.yaml"
40
+ Biscuit::SecretsDecrypter.new(secrets_file).load do |key, value|
41
+ ENV[key] = value
42
+ end
43
+ ```
20
44
 
21
- $ gem install biscuit
45
+ This approach pairs with [dotenv](https://github.com/bkeepers/dotenv) really well - dotenv for test/development, and biscuit for staging/production environments.
22
46
 
23
- ## Usage
47
+ #### With Rails
48
+
49
+ Load your secrets in `application.rb`, between loading Rails/bundler, before the Application config starts:
50
+
51
+ ```ruby
52
+ require "rails/all"
53
+
54
+ ...
55
+
56
+ Bundler.require(*Rails.groups)
57
+
58
+ ...
59
+
60
+ # Add in your biscuit loading here:
61
+ secrets_file = "#{__dir__}/secrets/#{Rails.env}.yml"
62
+ if File.exist?(secrets_file) # You can also check things like if Rails.env.production?
63
+ Biscuit::SecretsDecrypter.new(secrets_file).load do |key, value|
64
+ ENV[key] = value
65
+ end
66
+ end
67
+
68
+ ...
69
+
70
+ module MyApp
71
+ class Application < Rails::Application
72
+ ....
73
+ ```
74
+
75
+ #### Adding a new key
76
+
77
+ From the application root, run `biscuit put -f`, followed by the path to the yaml you want to encrypt in, followed by the key, followed by the example.
78
+
79
+ ```bash
80
+ $ biscuit put -f config/secrets/production.yml SECRET_KEY "sensitive value"
81
+ ```
82
+
83
+ #### Getting a key (CLI)
24
84
 
25
- TODO: Write usage instructions here
85
+ ```bash
86
+ $ biscuit export -f config/secrets/production.yml | grep "SECRET_KEY"
87
+ ```
88
+
89
+ #### A note on parsed values and quoting
90
+
91
+ Given this unencrypted YAML:
92
+
93
+ ```yaml
94
+ foo: 1,2,3,4,5
95
+ ```
96
+
97
+ You might think that `foo`'s value after being loaded would be `"1,2,3,4,5"`.
98
+ You'd be wrong... Ruby's YAML parser [strips out the commas](https://github.com/ruby/psych/issues/273), sees `12345`, and thinks "ah we have a number!"
99
+ Then the value is `12345`.
100
+
101
+ If you desire to keep the commas, you'll have to encode it quoted:
102
+
103
+ ```yaml
104
+ foo: "1,2,3,4,5"
105
+ ```
26
106
 
27
107
  ## Development
28
108
 
@@ -30,9 +110,22 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
30
110
 
31
111
  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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
112
 
113
+ ## Performing a release
114
+
115
+ First, go to `lib/biscuit/version.rb` and update the gem to the version you'd like. We follow semantic versioning, if you have questions about this please consult this [document](https://semver.org/).
116
+ After merging the change into the default branch you can go [here](https://github.com/usertesting/biscuit/releases/new) and publish a new release. Which will automatically push the new version to rubygems.org
117
+
118
+ ## License
119
+
120
+ [MIT](LICENSE).
121
+
122
+ Library created by [UserTesting](https://usertesting.com)
123
+
124
+ ![UserTesting](doc/UserTesting.png)
125
+
33
126
  ## Contributing
34
127
 
35
- 1. Fork it ( https://github.com/[my-github-username]/biscuit/fork )
128
+ 1. Fork it ( https://github.com/usertesting/biscuit/fork )
36
129
  2. Create your feature branch (`git checkout -b my-new-feature`)
37
130
  3. Commit your changes (`git commit -am 'Add some feature'`)
38
131
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1,30 +1,34 @@
1
1
  require 'open-uri'
2
+ require 'bundler/gem_tasks'
2
3
 
3
- UPSTREAM_VERSION = '0.1.3'
4
+ UPSTREAM_VERSION = '0.1.4'
4
5
 
5
6
  def fetch(release_url)
7
+ puts "Fetching native biscuit executable: #{release_url}"
6
8
  tgz_path = download_file(release_url)
7
9
 
8
10
  system("tar -xzf #{tgz_path} -C #{File.dirname(tgz_path)}") || raise
9
11
  system("mv #{File.dirname(tgz_path)}/biscuit #{__dir__}/bin/_biscuit") || raise
12
+ puts "Successfully fetched native biscuit executable"
10
13
  end
11
14
 
12
15
  def download_file(url)
13
16
  filename = URI(url).path.split('/').last
14
17
 
15
- IO.copy_stream(open(url), "/tmp/#{filename}")
18
+ IO.copy_stream(URI.open(url), "/tmp/#{filename}")
16
19
 
17
20
  "/tmp/#{filename}"
18
21
  end
19
22
 
20
23
  task :default do
21
24
  platform = Gem::Platform.local
22
- base_release_url = "https://github.com/dcoker/biscuit/releases/download/v#{UPSTREAM_VERSION}/biscuit"
25
+ base_release_url =
26
+ "https://github.com/dcoker/biscuit/releases/download/v#{UPSTREAM_VERSION}/biscuit_#{UPSTREAM_VERSION}_"
23
27
 
24
- if platform.os == 'darwin' && platform.cpu == 'x86_64'
25
- fetch("#{base_release_url}-darwin_amd64.tgz")
28
+ if platform.os == 'darwin'
29
+ fetch("#{base_release_url}MacOS-all.tar.gz")
26
30
  elsif platform.os == 'linux' && platform.cpu == 'x86_64'
27
- fetch("#{base_release_url}-linux_amd64.tgz")
31
+ fetch("#{base_release_url}Linux-64bit.tar.gz")
28
32
  else
29
33
  puts "Unsupported platform #{platform}"
30
34
  end
data/biscuit.gemspec CHANGED
@@ -6,29 +6,22 @@ require 'biscuit/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "biscuit"
8
8
  spec.version = Biscuit::VERSION
9
- spec.authors = ["Suan-Aik Yeo"]
10
- spec.email = ["yeosuanaik@gmail.com"]
9
+ spec.authors = ["Suan-Aik Yeo", "Justin Aiken"]
10
+ spec.email = ["yeosuanaik@gmail.com", "60tonangel@gmail.com"]
11
11
 
12
12
  spec.summary = %q{Ruby wrapper for biscuit (https://github.com/dcoker/biscuit).}
13
13
  spec.description = %q{Ruby wrapper for biscuit (https://github.com/dcoker/biscuit).}
14
14
  spec.homepage = "https://github.com/usertesting/biscuit"
15
+ spec.license = "MIT"
15
16
 
16
- # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
- # delete this section to allow pushing this gem to any host.
18
- if spec.respond_to?(:metadata)
19
- spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
- else
21
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
- end
23
-
24
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|doc)/}) }
25
18
  spec.bindir = "bin"
26
19
  spec.executables = 'biscuit'
27
20
  spec.require_paths = ["lib"]
28
21
  spec.extensions = ["Rakefile"]
29
22
 
30
- spec.add_development_dependency "bundler", "~> 1.9"
31
- spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "bundler", "~> 2.1"
24
+ spec.add_development_dependency "rake", "~> 13.0"
32
25
 
33
- spec.add_runtime_dependency "rake", "~> 10.0"
26
+ spec.add_runtime_dependency "rake"
34
27
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Biscuit
4
+ class ExecutionError < StandardError
5
+ def initialize(stderr, stdout=nil)
6
+ @stdout = stdout
7
+ @stderr = stderr
8
+ super(message)
9
+ end
10
+
11
+ def message
12
+ messages = []
13
+ messages << "std_out: #{truncate(@stdout)}" if @stdout
14
+ messages << "std_err: #{truncate(@stderr)}" if @stderr
15
+ messages.join(" ")
16
+ end
17
+
18
+ private
19
+
20
+ def truncate(message)
21
+ message.slice(0, 200)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Biscuit
4
+ class SecretsDecrypter
5
+ attr_reader :secrets_file
6
+
7
+ def initialize(secrets_file)
8
+ fail "#{secrets_file} is not found" unless File.exist? secrets_file
9
+
10
+ @secrets_file = secrets_file
11
+ end
12
+
13
+ def load(&block)
14
+ if block_given?
15
+ secrets.each{ |key, value|
16
+ block.call(key, value)
17
+ }
18
+ else
19
+ secrets
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def secrets
26
+ @_secrets ||= YAML.load(exported)
27
+ end
28
+
29
+ def exported
30
+ @_exported ||= Biscuit.run!("export -f '#{secrets_file}'")
31
+ end
32
+
33
+ def secret_lines
34
+ @_secret_lines ||= exported.split("\n").select { |line| line =~ /\S/ }
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module Biscuit
2
- VERSION = "0.0.7"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/biscuit.rb CHANGED
@@ -1,9 +1,14 @@
1
1
  require "biscuit/version"
2
+ require "biscuit/secrets_decrypter"
3
+ require "biscuit/execution_error"
4
+
5
+ require "open3"
6
+ require "yaml"
2
7
 
3
8
  module Biscuit
4
9
  def self.run!(command)
5
- result = `#{__dir__}/../bin/_biscuit #{command}`
6
- raise(result.slice(0, 200)) unless $?.success?
7
- result
10
+ stdout, stderr, status = Open3.capture3("#{__dir__}/../bin/_biscuit #{command}")
11
+ raise Biscuit::ExecutionError.new(stderr, stdout) unless status == 0
12
+ stdout
8
13
  end
9
14
  end
metadata CHANGED
@@ -1,67 +1,73 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biscuit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Suan-Aik Yeo
8
+ - Justin Aiken
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-11-16 00:00:00.000000000 Z
12
+ date: 2022-06-14 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - ~>
18
+ - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: '1.9'
20
+ version: '2.1'
20
21
  type: :development
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - ~>
25
+ - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: '1.9'
27
+ version: '2.1'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: rake
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ~>
32
+ - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: '10.0'
34
+ version: '13.0'
34
35
  type: :development
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - ~>
39
+ - - "~>"
39
40
  - !ruby/object:Gem::Version
40
- version: '10.0'
41
+ version: '13.0'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: rake
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - ~>
46
+ - - ">="
46
47
  - !ruby/object:Gem::Version
47
- version: '10.0'
48
+ version: '0'
48
49
  type: :runtime
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - ~>
53
+ - - ">="
53
54
  - !ruby/object:Gem::Version
54
- version: '10.0'
55
+ version: '0'
55
56
  description: Ruby wrapper for biscuit (https://github.com/dcoker/biscuit).
56
57
  email:
57
58
  - yeosuanaik@gmail.com
59
+ - 60tonangel@gmail.com
58
60
  executables:
59
61
  - biscuit
60
62
  extensions:
61
63
  - Rakefile
62
64
  extra_rdoc_files: []
63
65
  files:
64
- - .gitignore
66
+ - ".github/workflows/publish_gem.yml"
67
+ - ".github/workflows/ruby.yml"
68
+ - ".gitignore"
69
+ - ".rspec"
70
+ - CHANGELOG.markdown
65
71
  - Gemfile
66
72
  - LICENSE
67
73
  - README.md
@@ -71,30 +77,30 @@ files:
71
77
  - bin/setup
72
78
  - biscuit.gemspec
73
79
  - lib/biscuit.rb
80
+ - lib/biscuit/execution_error.rb
81
+ - lib/biscuit/secrets_decrypter.rb
74
82
  - lib/biscuit/version.rb
75
83
  homepage: https://github.com/usertesting/biscuit
76
- licenses: []
77
- metadata:
78
- allowed_push_host: 'TODO: Set to ''http://mygemserver.com'''
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
79
87
  post_install_message:
80
88
  rdoc_options: []
81
89
  require_paths:
82
90
  - lib
83
91
  required_ruby_version: !ruby/object:Gem::Requirement
84
92
  requirements:
85
- - - '>='
93
+ - - ">="
86
94
  - !ruby/object:Gem::Version
87
95
  version: '0'
88
96
  required_rubygems_version: !ruby/object:Gem::Requirement
89
97
  requirements:
90
- - - '>='
98
+ - - ">="
91
99
  - !ruby/object:Gem::Version
92
100
  version: '0'
93
101
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.0.14
102
+ rubygems_version: 3.3.7
96
103
  signing_key:
97
104
  specification_version: 4
98
105
  summary: Ruby wrapper for biscuit (https://github.com/dcoker/biscuit).
99
106
  test_files: []
100
- has_rdoc: