dotenv-sync 0.0.1

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
+ SHA1:
3
+ metadata.gz: b02e9462d0390c20b7d34aa33ba5c049f102bf84
4
+ data.tar.gz: c9ae0ea8edc992bbde2148bc0b346ac12cb860c3
5
+ SHA512:
6
+ metadata.gz: f129ee0b0592460be1fb71e1cee694282ce3ae341ebba56c267679c999c9ed8414c7b9988cff4a691f712a733a2d866aaa19d247e788a869fd3142526e8f6188
7
+ data.tar.gz: 9091c22e319a27bcad226a379ae700e0945c2a5a01f6ad3ec0f81c0ab2ba7de2526728a3b5610d40ad6ffc169f89bfb08036d496bdb0ec1348bc3206fa788cfd
data/.env-encrypted ADDED
@@ -0,0 +1 @@
1
+ qppvDjgQC3+fAiUeqcNP7T4+Pj48PDw8oHMN1LvCdZGAvGAKjqh7jA==
data/.gitignore ADDED
@@ -0,0 +1,123 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
11
+ # Dotenv syncing
12
+ .env.local
13
+ .env-key
14
+ # Dotenv syncing
15
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23180-82z6zs
16
+ # Dotenv syncing
17
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23180-1269mb7
18
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23180-b21itr
19
+ # Dotenv syncing
20
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23180-195mw9n
21
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23180-2djdwt
22
+ # Dotenv syncing
23
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23180-die8xx
24
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23180-kmqk34
25
+ # Dotenv syncing
26
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23210-1s0erd2
27
+ # Dotenv syncing
28
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23210-hyb5av
29
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23210-10vew49
30
+ # Dotenv syncing
31
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23210-199llgf
32
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23210-238ahe
33
+ # Dotenv syncing
34
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23210-144x04r
35
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23210-1t0v1sm
36
+ # Dotenv syncing
37
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23271-jjm3oc
38
+ # Dotenv syncing
39
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23271-1y4chh9
40
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23271-1cd9rwt
41
+ # Dotenv syncing
42
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23271-1m1rnmp
43
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23271-y4rr58
44
+ # Dotenv syncing
45
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23271-1nyyk1y
46
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23271-143a4u4
47
+ # Dotenv syncing
48
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23300-xuxepe
49
+ # Dotenv syncing
50
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23300-1pey2ca
51
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23300-a6efj1
52
+ # Dotenv syncing
53
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23300-1idh0yr
54
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23300-w3gz12
55
+ # Dotenv syncing
56
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23300-w1m084
57
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23300-1bvzoyw
58
+ # Dotenv syncing
59
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23334-a0eubf
60
+ # Dotenv syncing
61
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23334-1j3yaaw
62
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23334-1peqp69
63
+ # Dotenv syncing
64
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23334-118yu0m
65
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23334-1x5kxr1
66
+ # Dotenv syncing
67
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23334-1586qtn
68
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23334-mv2ktz
69
+ # Dotenv syncing
70
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23385-1o8vqnn
71
+ # Dotenv syncing
72
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23385-1mkzcvg
73
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23385-1kc85v8
74
+ # Dotenv syncing
75
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23385-tf97r5
76
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23385-sydwf1
77
+ # Dotenv syncing
78
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23385-15ae2l0
79
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23385-uvafyo
80
+ # Dotenv syncing
81
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23444-p1e69t
82
+ # Dotenv syncing
83
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23444-1qqj22l
84
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23444-1m5dg75
85
+ # Dotenv syncing
86
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23444-1n8c5i3
87
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23444-10qtxse
88
+ # Dotenv syncing
89
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23444-yq07r1
90
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23444-cur2k7
91
+ # Dotenv syncing
92
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23488-1882khe
93
+ # Dotenv syncing
94
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23488-1jqmxvd
95
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23488-1u1ayes
96
+ # Dotenv syncing
97
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23488-e28n4r
98
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23488-1vnfa3v
99
+ # Dotenv syncing
100
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23488-1wjefm
101
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23488-5qnn94
102
+ # Dotenv syncing
103
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23518-1giplp5
104
+ # Dotenv syncing
105
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23518-1pa7xdf
106
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23518-zlbcx6
107
+ # Dotenv syncing
108
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23518-cbl47m
109
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23518-g1abmw
110
+ # Dotenv syncing
111
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23518-2akndz
112
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23518-7uzqxk
113
+ # Dotenv syncing
114
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23542-1vhm8gi
115
+ # Dotenv syncing
116
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23542-7pfxk6
117
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23542-1d5qu6q
118
+ # Dotenv syncing
119
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23542-wqf353
120
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23542-x5q8i
121
+ # Dotenv syncing
122
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23542-pxcwjq
123
+ /var/folders/gt/k34d1gd555vcr5x0wtz5gf_r0000gn/T/20160704-23542-jexlno
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at Lighthawky@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dotenv-sync.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 yon
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.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # Dotenv::Sync
2
+
3
+ Dotenv-sync is a small utility that lets you sync `.env` secrets in your repo.
4
+
5
+ This assumes you use [dotenv](https://github.com/bkeepers/dotenv) to manage and load your environment variables locally and relies on the fact that _dotenv_ supports environment specific dotenv files.
6
+
7
+ ## How it works
8
+ dotenv-sync assumes you have two seperate files:
9
+
10
+ ```
11
+ .env - containts all non-secret env variables and shared on git
12
+ .env.local - contatins only the secrets and is not shared on git directly
13
+ ```
14
+
15
+ This gem then uses a shared secret keyfile which can be managed in any way __important to not commit this file__,
16
+ to encrypt and decrypt the `.env.local` file and share it in the repo as `.env-encrypted`.
17
+
18
+ You can use _1Password for teams_ or _Vault_ for sharing your secret key file.
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ ```ruby
25
+ gem 'dotenv-sync'
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install dotenv-sync
35
+
36
+ ## Usage
37
+
38
+ Dotenv-sync provides a command line file with several commands to run.
39
+
40
+ ```
41
+ dotenv-sync [command] # Runs the command while loading the env variables from .env (based on the dotenv gem)
42
+ dotenv-sync generate_key # Generate a new key file
43
+ dotenv-sync pull # Update your .env.local file from the encrypted version
44
+ dotenv-sync push # Update the encrypted file from your version of .env.local
45
+ dotenv-sync sort [DOTENV_FILE=.env] # Sorts your .env file
46
+ dotenv-sync help [COMMAND] # Describe available commands or one specific command
47
+ ```
48
+
49
+ ### First use
50
+ When initializing a new project you need to run `dotenv-sync generate_key` followed by `dotenv-sync push` to create the key which should be securely shared and the `.env-encrypted` file which can be commited.
51
+
52
+ ### Subsequent uses
53
+ If you're updating `.env.local` and want to share a change run `dotenv-sync push` and commit the change `.env-encrypted` file.
54
+
55
+ If you're pulling a change from git and see that `.env-encypted` changed run `dotenv-sync pull` to update your local `.env.local`
56
+
57
+ ## Development
58
+
59
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
60
+
61
+ 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).
62
+
63
+ ## Contributing
64
+
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yonbergman/dotenv-sync. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
66
+
67
+ ## License
68
+
69
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
70
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "thor"
5
+ require "dotenv/sync"
6
+ require "dotenv/sync/command_line"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require "irb"
16
+ IRB.start
data/bin/dotenv-sync ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dotenv/sync/command_line"
5
+ Dotenv::Sync::CommandLine.start(ARGV)
6
+
7
+
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,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dotenv/sync/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dotenv-sync"
8
+ spec.version = Dotenv::Sync::VERSION
9
+ spec.authors = ["yonbergman"]
10
+ spec.email = ["yonbergman@gmail.com"]
11
+
12
+ spec.summary = %q{This gem let's you sync dotenv files through encrypted file}
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.executables = ["dotenv-sync"]
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency 'rspec'
20
+ spec.add_development_dependency "bundler", "~> 1.12"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_runtime_dependency "thor"
23
+ end
@@ -0,0 +1,8 @@
1
+ require "dotenv/sync/version"
2
+ require "dotenv/sync/syncer"
3
+ require "dotenv/sync/errors"
4
+
5
+ module Dotenv
6
+ module Sync
7
+ end
8
+ end
@@ -0,0 +1,61 @@
1
+ require 'thor'
2
+ require_relative './syncer'
3
+ require_relative './errors'
4
+
5
+ module Dotenv
6
+ module Sync
7
+ class CommandLine < Thor
8
+
9
+ def self.start(args)
10
+ begin
11
+ super(args)
12
+ rescue Dotenv::Sync::CommandNotFound => e
13
+ begin
14
+ require "dotenv/cli"
15
+ Dotenv::CLI.new(ARGV).run
16
+ rescue Exception
17
+ puts "dotenv gem not installed, falling back to dotenv-sync"
18
+ super(["--help"])
19
+ end
20
+ end
21
+ end
22
+
23
+ desc "[command]", "Runs the command while loading the env variables from .env (based on the dotenv gem)"
24
+ def any()
25
+ raise NotImplementedError.new
26
+ end
27
+
28
+ desc "sort [DOTENV_FILE=.env]", "Sorts your .env file"
29
+ def sort(filename = Dotenv::Sync::Syncer::DEFAULT_SORT_FILE)
30
+ Syncer.new.sort(filename)
31
+ end
32
+
33
+ option :key, desc: "The keyfile", default: Syncer::DEFAULT_KEY_FILE, aliases: :k
34
+ option :encrypted, desc: "The shared encrypted file", default: Syncer::DEFAULT_ENCRYPTED_FILE, aliases: :e
35
+ option :secret, desc: "The private secret file", default: Syncer::DEFAULT_SECRET_FILE, aliases: :s
36
+ desc "pull", "Update your .env.local file from the encrypted version"
37
+ def pull
38
+ Syncer.new(options).pull
39
+ end
40
+
41
+ option :key, desc: "The keyfile", default: Syncer::DEFAULT_KEY_FILE, aliases: :k
42
+ option :encrypted, desc: "The shared encrypted file", default: Syncer::DEFAULT_ENCRYPTED_FILE, aliases: :e
43
+ option :secret, desc: "The private secret file", default: Syncer::DEFAULT_SECRET_FILE, aliases: :s
44
+ desc "push", "Update the encrypted file from your version of .env.local"
45
+ def push
46
+ Syncer.new(options).push
47
+ end
48
+
49
+ option :key, desc: "The keyfile", default: Syncer::DEFAULT_KEY_FILE, aliases: :k
50
+ desc "generate_key", "Generate a new key file"
51
+ def generate_key
52
+ Syncer.new(options).generate_key
53
+ end
54
+
55
+ def self.handle_no_command_error(command)
56
+ raise CommandNotFound.new
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,26 @@
1
+ require 'thor'
2
+
3
+ module Dotenv
4
+ module Sync
5
+ class FilePresenceError < Thor::Error
6
+ def initialize(filename)
7
+ super("File doesn't exist #{filename}")
8
+ end
9
+ end
10
+
11
+ class MissingKeyFile < Thor::Error
12
+ def initialize(filename)
13
+ super("Missing keyfile: #{filename} - either generate or download the file")
14
+ end
15
+ end
16
+
17
+ class NotImplementedError < Thor::Error
18
+ def initialize
19
+ super("Can't run any() command")
20
+ end
21
+ end
22
+
23
+ class CommandNotFound < StandardError
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,125 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+ require_relative './errors'
4
+
5
+ module Dotenv
6
+ module Sync
7
+ class Syncer
8
+
9
+ GITIGNORE = '.gitignore'
10
+ DEFAULT_SORT_FILE = '.env'
11
+ DEFAULT_SECRET_FILE = '.env.local'
12
+ DEFAULT_ENCRYPTED_FILE = '.env-encrypted'
13
+ DEFAULT_KEY_FILE = '.env-key'
14
+ DEFAULT_CONFIG_FILE = '.env-config'
15
+ SEPARATOR = ">>>><<<<"
16
+
17
+ def initialize(options = {})
18
+ @key_filename = options[:key] || DEFAULT_KEY_FILE
19
+ @secret_filename = options[:secret] || DEFAULT_SECRET_FILE
20
+ @encrypted_filename = options[:encrypted] || DEFAULT_ENCRYPTED_FILE
21
+ validate_gitignore
22
+ end
23
+
24
+ def generate_key
25
+ key = cipher.random_key
26
+ write_64(@key_filename, key)
27
+ end
28
+
29
+ def push
30
+ validate_file! @secret_filename
31
+ key = read_key!
32
+ data = read(@secret_filename)
33
+ data = sort_lines(data.lines)
34
+ cipher.encrypt
35
+ cipher.key = key
36
+ random_iv = cipher.random_iv
37
+ cipher.iv = random_iv
38
+ encrypted = cipher.update(data) + cipher.final
39
+ encrypted = random_iv + SEPARATOR + encrypted
40
+ write_64 @encrypted_filename, encrypted
41
+ puts "Successfully encrypted #{@secret_filename}"
42
+ data
43
+ end
44
+
45
+ def pull
46
+ validate_file! @encrypted_filename
47
+ key = read_key!
48
+ data = read_64 @encrypted_filename
49
+ iv, encrypted = data.split(SEPARATOR)
50
+ cipher.decrypt
51
+ cipher.iv = iv
52
+ cipher.key = key
53
+ data = cipher.update(encrypted) + cipher.final
54
+ write(@secret_filename, data)
55
+ puts "Successfully decrypted #{@secret_filename}"
56
+ data
57
+ end
58
+
59
+ def sort(filename)
60
+ validate_file!(filename)
61
+ lines = open(filename).readlines()
62
+ output = sort_lines(lines)
63
+ write(filename, output)
64
+ puts "Done sorting"
65
+ end
66
+
67
+ private
68
+
69
+ def validate_gitignore
70
+ gitignore_file = open(GITIGNORE,'a+')
71
+ lines = gitignore_file.readlines
72
+ additions = [@secret_filename, @key_filename].reject do |secret_file|
73
+ lines.map(&:strip).include? secret_file
74
+ end
75
+ unless additions.empty?
76
+ output = "\n# Dotenv syncing\n" + additions.join("\n")
77
+ gitignore_file.write(output)
78
+ end
79
+
80
+ gitignore_file.close
81
+ end
82
+
83
+ def write(file, data)
84
+ open(file, 'w') do |f|
85
+ f.write(data)
86
+ end
87
+ end
88
+
89
+ def write_64(file, data)
90
+ write(file, Base64.encode64(data))
91
+ end
92
+
93
+ def read(file)
94
+ open(file).read
95
+ end
96
+
97
+ def read_64(file)
98
+ Base64.decode64(read(file))
99
+ end
100
+
101
+ def read_key!
102
+ read_64 @key_filename
103
+ rescue Exception => e
104
+ raise MissingKeyFile.new(@key_filename)
105
+ end
106
+
107
+ def sort_lines(lines)
108
+ lines.map!(&:strip)
109
+ env_lines = lines.reject { |line| line.start_with?("#") }
110
+ comments = lines - env_lines
111
+ env_lines = env_lines.reject { |line| line.strip.empty? }.sort
112
+ (comments + env_lines).join("\n")
113
+ end
114
+
115
+ def cipher
116
+ @cipher ||= OpenSSL::Cipher::AES256.new(:CBC)
117
+ end
118
+
119
+ def validate_file!(filename)
120
+ raise FilePresenceError.new(filename) unless File.exists? filename
121
+ end
122
+
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,5 @@
1
+ module Dotenv
2
+ module Sync
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dotenv-sync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - yonbergman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
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: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - yonbergman@gmail.com
72
+ executables:
73
+ - dotenv-sync
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".env-encrypted"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/dotenv-sync
87
+ - bin/setup
88
+ - dotenv-sync.gemspec
89
+ - lib/dotenv/sync.rb
90
+ - lib/dotenv/sync/command_line.rb
91
+ - lib/dotenv/sync/errors.rb
92
+ - lib/dotenv/sync/syncer.rb
93
+ - lib/dotenv/sync/version.rb
94
+ homepage:
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.5.1
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: This gem let's you sync dotenv files through encrypted file
118
+ test_files: []