dotenv-vault 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43532f3eb3ddc9a9b407131c2961446cf58664e34e5bcc763efc516d9b0143cb
4
- data.tar.gz: b0a76f6e83ddd50fd3525976fffe0c09c759a91286120266ca7396e3b636095c
3
+ metadata.gz: f07ef0e741df42c7269f9d949e3b279bc2e244f030b8d2abd3b1cfd49d707d4f
4
+ data.tar.gz: c5ebb287fbd0de6d76ba888aea9fab96763329bcb9db19c86444d2b1e9b6d4ed
5
5
  SHA512:
6
- metadata.gz: e01b952fbf0d9de42f8cb35a7ab622ba95bfb85bb53685712340500524c472895d01c42d3c22ff16796526b29b7c6584777b2170629b0f093fd3188ee907da25
7
- data.tar.gz: cdabb9c5af4aa7ecfdc3797fa91cc15452497b85184c25709fa3e853adcadc826c2a1aaf01526a8ff0c86a93d3576179e7f5fc7c37d4913647f7aef0e95c4fcb
6
+ metadata.gz: 62a9f140d67de2990e183616d6075dbcabddbef118a3a7b91e85e237d6673b02b0136af95661b0f239d62a3cf217956184c8b4532f04b1aeef60e02878860552
7
+ data.tar.gz: d904872c3b6c27e5dd71a8ed31703fbbe8765e8cf212ebdadba04932b5addf10672284d0d15a816cacdce1607c45d9048b7bdac1ee8e83a1402d7e03b8f3d26d
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dotenv-vault (0.4.0)
4
+ dotenv-vault (0.5.0)
5
5
  dotenv
6
6
  lockbox
7
- dotenv-vault-rails (0.4.0)
7
+ dotenv-vault-rails (0.5.0)
8
8
  dotenv-rails
9
- dotenv-vault (= 0.4.0)
9
+ dotenv-vault (= 0.5.0)
10
10
 
11
11
  GEM
12
12
  remote: https://rubygems.org/
@@ -1,3 +1,4 @@
1
+ require "dotenv-rails"
1
2
  require "dotenv-vault"
2
3
 
3
4
  # Fix for rake tasks loading in development
@@ -1,3 +1,3 @@
1
1
  module DotenvVault
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/dotenv-vault.rb CHANGED
@@ -105,9 +105,15 @@ module DotenvVault
105
105
  end
106
106
 
107
107
  def parse_vault(*filenames)
108
- # Warn the developer unless both are set
108
+ # DOTENV_KEY=development/key_1234
109
+ #
110
+ # Warn the developer unless formatted correctly
109
111
  raise NotFoundDotenvKey, "NOT_FOUND_DOTENV_KEY: Cannot find ENV['DOTENV_KEY']" unless present?(ENV["DOTENV_KEY"])
110
- raise NotFoundDotenvEnvironment, "NOT_FOUND_DOTENV_ENVIRONMENT: Cannot find ENV['DOTENV_ENVIRONMENT']" unless present?(ENV["DOTENV_ENVIRONMENT"])
112
+ split_dotenv_key = ENV["DOTENV_KEY"].split("/")
113
+ environment = split_dotenv_key[0]
114
+ raise InvalidDotenvKey, "INVALID_DOTENV_KEY: Missing environment part" unless present?(environment)
115
+ key = split_dotenv_key[1]
116
+ raise InvalidDotenvKey, "INVALID_DOTENV_KEY: Missing key part" unless present?(key)
111
117
 
112
118
  # Locate .env.vault
113
119
  vault_path = ".env.vault"
@@ -117,31 +123,29 @@ module DotenvVault
117
123
  parsed = Dotenv.parse(vault_path)
118
124
 
119
125
  # Get ciphertext
120
- environment_key = "DOTENV_VAULT_#{ENV["DOTENV_ENVIRONMENT"].upcase}"
126
+ environment_key = "DOTENV_VAULT_#{environment.upcase}"
121
127
  ciphertext = parsed[environment_key] # DOTENV_VAULT_PRODUCTION
122
128
  raise NotFoundDotenvEnvironment, "NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate #{environment_key} in .env.vault" unless ciphertext
123
129
 
124
130
  # Decrypt ciphertext
125
- decrypted = decrypt(ciphertext)
131
+ decrypted = decrypt(ciphertext, key)
126
132
 
127
133
  # Parse decrypted .env string
128
134
  Dotenv::Parser.call(decrypted, true)
129
135
  end
130
136
 
131
137
  def using_vault?
132
- present?(ENV["DOTENV_ENVIRONMENT"]) && present?(ENV["DOTENV_KEY"])
138
+ present?(ENV["DOTENV_KEY"])
133
139
  end
134
140
 
135
141
  def present?(str)
136
142
  !(str.nil? || str.empty?)
137
143
  end
138
144
 
139
- def decrypt(ciphertext)
140
- raise NotFoundDotenvKey, "NOT_FOUND_DOTENV_KEY: Cannot find ENV['DOTENV_KEY']" unless present?(ENV["DOTENV_KEY"])
141
-
142
- key = ENV["DOTENV_KEY"][-64..-1] # last 64 characters. allows for passing keys with preface like key_*****
145
+ def decrypt(ciphertext, key)
146
+ key = key[-64..-1] # last 64 characters. allows for passing keys with preface like key_*****
143
147
 
144
- raise InvalidDotenvKey, "INVALID_DOTENV_KEY: It must be 64 characters long (or more)" unless key.to_s.length == 64
148
+ raise InvalidDotenvKey, "INVALID_DOTENV_KEY: Key part must be 64 characters long (or more)" unless key.bytesize == 64
145
149
 
146
150
  lockbox = Lockbox.new(key: key, encode: true)
147
151
  begin
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotenv-vault
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - motdotla
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-16 00:00:00.000000000 Z
11
+ date: 2022-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv