encrypted-environment 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 487148e2ff834cf95e636cab49e5b28a6d7ffb2e2f7b646445edd785d44e8a94
4
+ data.tar.gz: 7927fade6cefd9af5e77281f463ea8d88d9a9cdd9618a4f55920f9b97376cee1
5
+ SHA512:
6
+ metadata.gz: 5157ed09233aa078a2150e9b24f5cbb15b2aa855dd0ef5490af5c74c4303c9a341cdc135ccdf5843651a565c3f8f3a4151433c0d42ef675fe351f664b3c441cf
7
+ data.tar.gz: '05235139b06ca41ceaf35ff37ae3092c012a6814617f154ea09207c43b902a8113eea5bb82c62381e6442a8aa454ce964dd05e7aa914a94e3e0b89a2653ed60e'
@@ -0,0 +1,34 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.4.1-node-browsers
6
+ working_directory: ~/repo
7
+
8
+ steps:
9
+ - checkout
10
+
11
+ - restore_cache:
12
+ keys:
13
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
14
+ - v1-dependencies-
15
+
16
+ - run:
17
+ name: Install dependencies
18
+ command: |
19
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
20
+
21
+ - save_cache:
22
+ paths:
23
+ - ./vendor/bundle
24
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
25
+
26
+ - run:
27
+ name: Run tests
28
+ command: |
29
+ bundle exec rake test
30
+
31
+ - run:
32
+ name: Run linter
33
+ command: |
34
+ bundle exec rubocop
@@ -0,0 +1,11 @@
1
+ ## Context 🕵️‍♀️
2
+
3
+ > Provide information that helps with understanding your issue. For example your use case that the project doesn't cover, what you were doing when you found the bug... You can also provide the version that you were using, how you integrated it with your project, the platform version...
4
+
5
+ ## What 🌱
6
+
7
+ > Describe here your issue, a bug you found, an idea that you had, something that you think can be improved...
8
+
9
+ ## Proposal 🎉
10
+
11
+ > Attach your own proposal _(if you have it)_. We'll discuss in on the issue to find the best one that fits into the library.
@@ -0,0 +1,16 @@
1
+ Resolves https://github.com/pepibumur/encrypted-environment/issues/YYY
2
+
3
+ ### Short description 📝
4
+
5
+ > Describe here the purpose of your PR.
6
+
7
+ ### Solution 📦
8
+
9
+ > Describe the solution you came up with and the reasons that led you to that solution. If you thought about other solutions don't forget about mentioning them.
10
+
11
+ ### Implementation 👩‍💻👨‍💻
12
+
13
+ > Detail in a checklist the steps that you took to implement the PR.
14
+
15
+ - [ ] Step 1
16
+ - [ ] Step 2
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml
10
+ .byebug_history
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ inherit_from:
2
+ - http://shopify.github.io/ruby-style-guide/rubocop.yml
3
+
4
+ Rails:
5
+ Enabled: false
6
+
7
+ Style/ClassAndModuleChildren:
8
+ Enabled: false
9
+
10
+ AllCops:
11
+ TargetRubyVersion: 2.5
12
+ DisplayCopNames: true
13
+ DisplayStyleGuide: true
14
+ Exclude:
15
+ - vendor/**/*
16
+ - bin/*
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.3
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.6
@@ -0,0 +1,3 @@
1
+ {
2
+ "editor.formatOnSave": true
3
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/
4
+
5
+ ## Next version
6
+
7
+ ## 1.0.0
8
+
9
+ ### Added
10
+
11
+ - 🎉 The project was born!
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in encrypted-environment.gemspec
8
+ gemspec
9
+
10
+ gem 'codecov', require: false, group: :test
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ encrypted-environment (0.1.0)
5
+ ejson (~> 1.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ansi (1.5.0)
11
+ ast (2.4.0)
12
+ builder (3.2.3)
13
+ byebug (10.0.2)
14
+ codecov (0.1.14)
15
+ json
16
+ simplecov
17
+ url
18
+ docile (1.3.1)
19
+ ejson (1.2.0)
20
+ jaro_winkler (1.5.1)
21
+ json (2.1.0)
22
+ metaclass (0.0.4)
23
+ minitest (5.11.3)
24
+ minitest-reporters (1.3.5)
25
+ ansi
26
+ builder
27
+ minitest (>= 5.0)
28
+ ruby-progressbar
29
+ mocha (1.7.0)
30
+ metaclass (~> 0.0.1)
31
+ parallel (1.12.1)
32
+ parser (2.5.3.0)
33
+ ast (~> 2.4.0)
34
+ powerpack (0.1.2)
35
+ rainbow (3.0.0)
36
+ rake (10.5.0)
37
+ rubocop (0.60.0)
38
+ jaro_winkler (~> 1.5.1)
39
+ parallel (~> 1.10)
40
+ parser (>= 2.5, != 2.5.1.1)
41
+ powerpack (~> 0.1)
42
+ rainbow (>= 2.2.2, < 4.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (~> 1.4.0)
45
+ ruby-progressbar (1.10.0)
46
+ simplecov (0.16.1)
47
+ docile (~> 1.1)
48
+ json (>= 1.8, < 3)
49
+ simplecov-html (~> 0.10.0)
50
+ simplecov-html (0.10.2)
51
+ unicode-display_width (1.4.0)
52
+ url (0.3.2)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ bundler (~> 1.16)
59
+ byebug (~> 10.0)
60
+ codecov
61
+ encrypted-environment!
62
+ minitest (~> 5.0)
63
+ minitest-reporters (~> 1.3)
64
+ mocha (~> 1.7)
65
+ rake (~> 10.0)
66
+ rubocop (~> 0.60.0)
67
+
68
+ BUNDLED WITH
69
+ 1.17.1
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) from 2019 Pedro Piñera Buendía
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Encrypted enironment
2
+
3
+ [![CircleCI](https://circleci.com/gh/pepibumur/encrypted-environment.svg?style=svg)](https://circleci.com/gh/pepibumur/encrypted-environment)
4
+ [![codecov](https://codecov.io/gh/pepibumur/encrypted-environment/branch/master/graph/badge.svg)](https://codecov.io/gh/pepibumur/encrypted-environment)
5
+
6
+ Ruby utility to load encrypted variables into the environment
7
+
8
+ ## Install
9
+
10
+ 1. Add the following line to the Gemfile:
11
+
12
+ ```
13
+ gem "encrypted-environment", git: "git@github.com:pepibumur/encrypted-environment.git"
14
+ ```
15
+ 2. Run `bundle install`
16
+
17
+
18
+ ## Usage
19
+
20
+ ```ruby
21
+ require "encrypted/environment"
22
+
23
+ Encrypted::Environment.load_from_ejson(
24
+ "path/to/env.ejson",
25
+ secrets_path: "secrets",
26
+ private_key: "key"
27
+ )
28
+
29
+ Encrypted::Environment.encrypt_ejson(
30
+ "path/to/env.ejson",
31
+ secrets_path: "secrets",
32
+ private_key: "key"
33
+ )
34
+ ```
data/Rakefile ADDED
@@ -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)
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "encrypted/environment"
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(__FILE__)
data/bin/setup ADDED
@@ -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
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "encrypted/environment/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "encrypted-environment"
9
+ spec.version = Encrypted::Environment::VERSION
10
+ spec.authors = ["Pedro Piñera"]
11
+ spec.email = ["pedro@ppinera.es"]
12
+ spec.summary = 'Load encrypted variables into the environment'
13
+
14
+ # Specify which files should be added to the gem when it is released.
15
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = %w(lib)
22
+
23
+ spec.add_dependency("ejson", "~> 1.2")
24
+
25
+ spec.add_development_dependency("bundler", "~> 1.16")
26
+ spec.add_development_dependency("rake", "~> 10.0")
27
+ spec.add_development_dependency("minitest", "~> 5.0")
28
+ spec.add_development_dependency("rubocop", "~> 0.60.0")
29
+ spec.add_development_dependency("byebug", "~> 10.0")
30
+ spec.add_development_dependency("minitest-reporters", "~> 1.3")
31
+ spec.add_development_dependency("mocha", "~> 1.7")
32
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Encrypted
4
+ module Environment
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "encrypted/environment/version"
4
+ require 'json'
5
+ require 'tmpdir'
6
+ require 'fileutils'
7
+
8
+ module Encrypted
9
+ module Environment
10
+ EnvironmentError = Class.new(StandardError)
11
+ MissingEjson = Class.new(EnvironmentError)
12
+ MissingSecret = Class.new(EnvironmentError)
13
+
14
+ def self.load_from_ejson(ejson_path, secrets_path: nil, private_key: nil)
15
+ decrypt_environment(
16
+ ejson_path: ejson_path,
17
+ secrets_path: secrets_path,
18
+ private_key: private_key
19
+ ).each do |key, value|
20
+ ENV[key] = value if key != "_public_key"
21
+ end
22
+ end
23
+
24
+ def self.encrypt_ejson(ejson_path, secrets_path: nil, private_key: nil)
25
+ with_secrets(ejson_path: ejson_path, secrets_path: secrets_path, private_key: private_key) do |path|
26
+ %x(EJSON_KEYDIR=#{path} bundle exec ejson encrypt #{ejson_path})
27
+ end
28
+ end
29
+
30
+ class << self
31
+ private
32
+
33
+ def decrypt_environment(ejson_path:, secrets_path: nil, private_key: nil)
34
+ with_secrets(ejson_path: ejson_path, secrets_path: secrets_path, private_key: private_key) do |path|
35
+ output = %x(EJSON_KEYDIR=#{path} bundle exec ejson decrypt #{ejson_path})
36
+ JSON.parse(output)
37
+ end
38
+ end
39
+
40
+ def with_secrets(ejson_path:, secrets_path: nil, private_key: nil)
41
+ raise MissingEjson unless File.exist?(ejson_path)
42
+
43
+ content = File.read(ejson_path)
44
+ ejson = JSON.parse(content)
45
+ public_key = ejson["_public_key"]
46
+ should_delete = false
47
+
48
+ if !secrets_path.nil? && File.exist?(secrets_path)
49
+ # Do nothing
50
+ elsif !private_key.nil?
51
+ secrets_path = Dir.mktmpdir
52
+ should_delete = true
53
+ File.write(File.join(secrets_path, public_key), private_key)
54
+ else
55
+ raise MissingSecret
56
+ end
57
+
58
+ yield(secrets_path)
59
+ ensure
60
+ FileUtils.remove_dir(secrets_path, true) if should_delete
61
+ end
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: encrypted-environment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Piñera
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ejson
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.60.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.60.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest-reporters
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: mocha
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.7'
125
+ description:
126
+ email:
127
+ - pedro@ppinera.es
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".circleci/config.yml"
133
+ - ".github/ISSUE_TEMPLATE.md"
134
+ - ".github/PULL_REQUEST_TEMPLATE.md"
135
+ - ".gitignore"
136
+ - ".rubocop.yml"
137
+ - ".ruby-version"
138
+ - ".travis.yml"
139
+ - ".vscode/settings.json"
140
+ - CHANGELOG.md
141
+ - Gemfile
142
+ - Gemfile.lock
143
+ - LICENSE.md
144
+ - README.md
145
+ - Rakefile
146
+ - bin/console
147
+ - bin/setup
148
+ - encrypted-environment.gemspec
149
+ - lib/encrypted/environment.rb
150
+ - lib/encrypted/environment/version.rb
151
+ homepage:
152
+ licenses: []
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.7.6
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Load encrypted variables into the environment
174
+ test_files: []