doppler 1.0.2 → 1.0.3

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
  SHA1:
3
- metadata.gz: 69b112d5d1d5dbf328711c0f22f1c02be2f4afb8
4
- data.tar.gz: 89663dbd70d8c5afddebb2b98cfbbf3a19a64d34
3
+ metadata.gz: 5d303fcb3660df971db06bd9c2206d06c8a2e0e5
4
+ data.tar.gz: 876807ca51165604c8f5b2126febfd486616643c
5
5
  SHA512:
6
- metadata.gz: c532bc666dacd189406cf42b2c1ca580956667ea745cf7829cb1bef32180c75fd84f98986e6054210a58957fab48c6206fdd8866867e8873d0afaed1aa081de5
7
- data.tar.gz: 3ccf3ff1b647be6a1cc630764cdae2933fa1c6c101e17b2ab1cfd91505063adc4cac06d747c75b38025437f2f7257efc0e247e358bb84d42c687d1f7a50c342b
6
+ metadata.gz: 660925bf24c7e24c4cebf2d5d530ab4c8b42dee09bc62186e8868eb007801e72307ae17e11f7d2af34471f3435041d0dec750a607e6c7cf0a8556f4fd8a15b55
7
+ data.tar.gz: baf51f7cbb44c352a353797da9e4c2b23be4b13777fbb7300f371b079ceae220241c97b8cc47d4800b5733d091a24bc5d81e6a155f8040087e48b7c653f36f4d
data/README.md CHANGED
@@ -20,7 +20,7 @@ The package needs to be configured with your account's api key which is availabl
20
20
 
21
21
 
22
22
  ### Environment Variables Required
23
- Please add these environment variables to your `.env` file or infra provider.
23
+ Please add these environment variables to your `.env` file in the root directory or on your infra provider.
24
24
 
25
25
  ```
26
26
  DOPPLER_API_KEY = <API Key>
@@ -28,7 +28,15 @@ DOPPLER_PIPELINE = <Pipeline ID>
28
28
  DOPPLER_ENVIRONMENT = <Environment Name>
29
29
  ```
30
30
 
31
- ### Simple Install
31
+ ### Lookup Priority
32
+ Doppler will look for these variables in 3 places with the following priority:
33
+
34
+ 1. Passed in as initialization arguments
35
+ 2. Read from environment variables
36
+ 3. Read from `.env` file
37
+
38
+
39
+ ### Install with Environment Variables
32
40
  This installation method will expect the `DOPPLER_API_KEY`, `DOPPLER_PIPELINE`, `DOPPLER_ENVIRONMENT` as environment variables.
33
41
 
34
42
  ``` ruby
@@ -38,6 +46,22 @@ Doppler::Client.new()
38
46
  # Rest of Application
39
47
  ```
40
48
 
49
+ ### Install with ENV File
50
+ This installation method will expect the `DOPPLER_API_KEY`, `DOPPLER_PIPELINE`, `DOPPLER_ENVIRONMENT` in a `.env` file.
51
+
52
+ ``` ruby
53
+ require "doppler"
54
+
55
+ Doppler.configure do |config|
56
+ config.env_filepath = ".env" # Defaults to ".env"
57
+ end
58
+
59
+
60
+ Doppler::Client.new()
61
+
62
+ # Rest of Application
63
+ ```
64
+
41
65
  ### Install with Arguments
42
66
  This installation method will expect the `api_key`, `pipeline`, `environment` as arguments.
43
67
 
data/lib/doppler.rb CHANGED
@@ -54,10 +54,44 @@ module Doppler
54
54
  def self.backup_filepath
55
55
  @@backup_filepath
56
56
  end
57
+
58
+ # configure env file
59
+ @@env_filepath = ".env"
60
+ def self.env_filepath=(env_filepath)
61
+ @@env_filepath = env_filepath
62
+ end
63
+ def self.env_filepath
64
+ @@env_filepath
65
+ end
66
+
67
+ # read env file
68
+ def self.read_env(path)
69
+ if path.nil? or !File.file?(path)
70
+ return nil
71
+ end
72
+
73
+ keys = {}
74
+ File.open(path, "r") do |file|
75
+ file.each do |line|
76
+ parts = line.strip.split("=")
77
+
78
+ if parts.length == 2
79
+ keys[parts[0].strip] = parts[1].strip
80
+ end
81
+ end
82
+ end
83
+
84
+ return keys
85
+ end
57
86
 
58
87
  # helper to configure above variables.
59
88
  def self.configure
60
89
  yield(self)
90
+
91
+ env_file = self.read_env(self.env_filepath) || {}
92
+ self.api_key = self.api_key || env_file["DOPPLER_API_KEY"]
93
+ self.pipeline = self.pipeline || env_file["DOPPLER_PIPELINE"]
94
+ self.environment = self.environment || env_file["DOPPLER_ENVIRONMENT"]
61
95
  end
62
96
 
63
97
  end
@@ -87,23 +87,14 @@ module Doppler
87
87
  retry_count += 1
88
88
 
89
89
  if retry_count > MAX_RETRIES
90
- if Doppler.backup_filepath.nil? or !File.file?(Doppler.backup_filepath)
91
- raise e
92
- end
90
+ backup_env = Doppler.read_env(Doppler.backup_filepath)
93
91
 
94
- keys = {}
95
- File.open(Doppler.backup_filepath, "r") do |file|
96
- file.each do |line|
97
- parts = line.strip!.split("=")
98
-
99
- if parts.length == 2
100
- keys[parts[0]] = parts[1]
101
- end
102
- end
92
+ if backup_env.nil?
93
+ raise e
103
94
  end
104
95
 
105
96
  data = {}
106
- data["variables"] = keys
97
+ data["variables"] = backup_env
107
98
  return data
108
99
 
109
100
  else
@@ -1,3 +1,3 @@
1
1
  module Doppler
2
- VERSION = "1.0.2".freeze
2
+ VERSION = "1.0.3".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doppler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doppler Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-01 00:00:00.000000000 Z
11
+ date: 2019-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler