doppler 0.2.0 → 1.0.1

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: 81538ad7d067d1717e14ad49885bdbc7f059a64b
4
- data.tar.gz: 90ddb9cfaecb4f9985d7ddfeb224804d69a254e1
3
+ metadata.gz: b02a59489c478d737e5969eab8cf3afecb217c49
4
+ data.tar.gz: a2335a4f35579d0f3023d5bc3558568562ba2a3b
5
5
  SHA512:
6
- metadata.gz: cf98ba4bcbb81edce4bde1e3c63c56d9a3f057e028085ad2a2c41182bc920db948f14f870c9915aa1427728c68c340c3f884eab5c1d11ca0e32eb6cbd0c3304b
7
- data.tar.gz: dff21398b8d3b1f40a5876d9d3418f972b060c460d27ffad48572efb99cfb4da44a05707cd1dcafbb23b8d226bb70cb9b922a556449c0bb3f4d31a6e1194b560
6
+ metadata.gz: 3113831876da0c9fe14815642e4e87aa1e41ec5e0b2250b7765068df9d2b1cf0357b5170a7c11f20c7e27784fc4d95db8307c49bbcafa16880fce56c2259bc93
7
+ data.tar.gz: 4bab5c34a684a22e225fa9bbcd0ccd4d3dbc2d7d7efa263f70204f5f46c62bc978a7f3d2f58db92bdfd066c39fcfaf8d57a71a35ce18803b1564c9d2803c042a
data/.gitignore CHANGED
@@ -12,6 +12,7 @@
12
12
 
13
13
  # Used by dotenv library to load environment variables.
14
14
  # .env
15
+ backup.env
15
16
 
16
17
  ## Specific to RubyMotion:
17
18
  .dat*
data/README.md CHANGED
@@ -17,120 +17,71 @@ gem install doppler
17
17
 
18
18
  The package needs to be configured with your account's api key which is available in your [Doppler account](https://doppler.com/workplace/api_key), pipeline identifier and the environment name:
19
19
 
20
- ``` ruby
21
- require "doppler"
22
-
23
- Doppler.configure do |config|
24
- config.api_key = "api-key"
25
- config.pipeline = "31"
26
- config.environment = "development_ruby"
27
- config.priority = Doppler::PRIORITY_REMOTE
28
- end
29
20
 
21
+ ### Environment Variables Required
22
+ Please add these environment variables to your `.env` file or infra provider.
30
23
 
31
- doppler = Doppler::Client.new()
32
-
33
- # Rest of Application
34
24
  ```
35
-
36
- ## Key Best Practices
37
-
38
- So if Doppler stores my environment keys, where should I keep my Doppler API keys?
39
-
40
- That is a great question! We recommend storing your `API_KEY`, `PIPELINE_ID`, and `ENVIRONMENT_NAME`
41
- in local environment. That means the only keys you should be storing in your local environment are the Doppler keys. All other keys should be be fetched by the Doppler client.
42
-
43
- ### Fetch Environment Keys
44
-
45
- You can fetch your environment keys from Doppler by calling the `get(name)` method.
46
-
47
- ``` ruby
48
- doppler.get(KEY_NAME)
25
+ DOPPLER_API_KEY = <API Key>
26
+ DOPPLER_PIPELINE = <Pipeline ID>
27
+ DOPPLER_ENVIRONMENT = <Environment Name>
49
28
  ```
50
29
 
51
- Here is an example:
30
+ ### Simple Install
31
+ This installation method will expect the `DOPPLER_API_KEY`, `DOPPLER_PIPELINE`, `DOPPLER_ENVIRONMENT` as environment variables.
52
32
 
53
33
  ``` ruby
54
- config = {
55
- "segment_key" => doppler.get("SEGMENT_API_KEY"),
56
- "algolia_key" => doppler.get("ALGOLIA_API_KEY")
57
- }
34
+ require "doppler"
35
+ Doppler::Client.new()
58
36
 
37
+ # Rest of Application
59
38
  ```
60
39
 
61
- If there are differences between the values your local environment sets and the ones on Doppler, the client will use the ones provided by Doppler. You can override this behavior by passing in a second argument to the `get(key_name, priority)` method that sets the priority to favor your local environment.
62
-
63
- For example:
40
+ ### Install with Arguments
41
+ This installation method will expect the `api_key`, `pipeline`, `environment` as arguments.
64
42
 
65
43
  ``` ruby
66
- # Local Enviroment
67
- os.environ["MAGICAL_KEY"] = "123"
68
-
69
- # Doppler
70
- MAGICAL_KEY = "456"
71
-
72
-
73
- # Default Behavior
74
- doppler.get("MAGICAL_KEY") # => "456"
75
-
76
- # Override to Local
77
- doppler.get("MAGICAL_KEY", Doppler::Priority.local) # => "123"
78
- ```
79
-
80
- You can also set the priority globally on initialization:
44
+ require "doppler"
81
45
 
82
- ``` ruby
83
46
  Doppler.configure do |config|
84
- # ...
85
- config.priority = Doppler::PRIORITY_LOCAL
47
+ config.api_key = ENV["DOPPLER_API_KEY"]
48
+ config.pipeline = ENV["DOPPLER_PIPELINE"]
49
+ config.environment = ENV["DOPPLER_ENVIRONMENT"]
86
50
  end
87
- ```
88
51
 
89
- ## Rails integration
90
52
 
91
- Configure `Doppler` with keys and environments, and then you should be all good.
92
- Please use the following snippet in initializer folder.
53
+ Doppler::Client.new()
93
54
 
94
- ```rb
95
- Doppler.configure do |config|
96
- config.api_key = "api-key"
97
- config.pipeline = "31"
98
- config.environment = "development_ruby"
99
- config.priority = Doppler::PRIORITY_REMOTE
100
- end
55
+ # Rest of Application
101
56
  ```
102
57
 
103
- Example repo found [here](https://github.com/DopplerHQ/rails-sample).
58
+ ## Key Best Practices
59
+
60
+ So if Doppler stores my environment variables, where should I keep my Doppler API keys?
104
61
 
105
- ## Local Key Privacy
62
+ That is a great question! We recommend storing your `DOPPLER_API_KEY`, `DOPPLER_PIPELINE`, and `DOPPLER_ENVIRONMENT`
63
+ in a `.env` file or with your infra provider. That means the only variables you should be storing in your local environment are the Doppler keys. All other variables should be be fetched by the Doppler client.
106
64
 
107
- By default the Doppler client will only track the local environment keys that are used during `doppler.get()`.
108
- Collecting only those local keys helps us automatically setup your pipelines
109
- for immediate use. After setup we also use your keys to detect when your keys locally have
110
- changed from what is on Doppler. We then provide a way for you to adopt or reject those changes
111
- through our dashboard. This can help help when debugging silent bugs or build failures.
112
65
 
113
- ### Track Additional Keys
114
- The Doppler client can also track additional keys by providing an array of keys to the `track_keys` field.
66
+ ## Ignoring Specific Variables
67
+
68
+ In the case you would want to ignore specific variables from Doppler, say a port set by Heroku, you can add it the `ignore_variables` field.
115
69
 
116
70
  ``` ruby
117
71
  Doppler.configure do |config|
118
- # ...
119
- config.track_keys = [
120
- "KEY_TO_TRACK"
121
- ]
72
+ config.ignore_variables = ["PORT"]
122
73
  end
123
74
  ```
124
75
 
125
- ### Ignoring Specific Keys
126
- Inversely, you can also ignore specific local keys by adding them to the `ignore_keys` array.
76
+ ## Fallback to Backup
77
+
78
+ The Doppler client accepts a `backup_filepath` on init. If provided the client will write
79
+ the Doppler variables to a backup file. If the Doppler client fails to connect to our API
80
+ endpoint (very unlikely), the client will fallback to the variables provided in the backup file.
127
81
 
128
82
  ``` ruby
129
83
  Doppler.configure do |config|
130
- # ...
131
- config.ignore_keys = [
132
- "SUPER_SECRET_KEY"
133
- ]
84
+ config.backup_filepath = "./backup.env"
134
85
  end
135
86
  ```
136
87
 
@@ -11,7 +11,7 @@ module Doppler
11
11
  end
12
12
 
13
13
  # configure api key
14
- @@api_key = "sample-api-key"
14
+ @@api_key = ENV["DOPPLER_API_KEY"]
15
15
  def self.api_key=(api_key)
16
16
  @@api_key = api_key
17
17
  end
@@ -20,7 +20,7 @@ module Doppler
20
20
  end
21
21
 
22
22
  # configure pipeline
23
- @@pipeline = "sample-pipeline"
23
+ @@pipeline = ENV["DOPPLER_PIPELINE"]
24
24
  def self.pipeline=(pipeline)
25
25
  @@pipeline = pipeline
26
26
  end
@@ -29,7 +29,7 @@ module Doppler
29
29
  end
30
30
 
31
31
  # configure environment
32
- @@environment = "development_ruby"
32
+ @@environment = ENV["DOPPLER_ENVIRONMENT"]
33
33
  def self.environment=(environment)
34
34
  @@environment = environment
35
35
  end
@@ -37,56 +37,27 @@ module Doppler
37
37
  @@environment
38
38
  end
39
39
 
40
- # configure priority
41
- PRIORITY_REMOTE = 0
42
- PRIORITY_LOCAL = 1
43
- @@priority = PRIORITY_REMOTE
44
- def self.priority=(priority)
45
- @@priority = priority
40
+ # configure ignore variables
41
+ @@ignore_variables = []
42
+ def self.ignore_variables=(ignore_variables)
43
+ @@ignore_variables = ignore_variables
46
44
  end
47
- def self.priority
48
- @@priority
45
+ def self.ignore_variables
46
+ @@ignore_variables
49
47
  end
50
-
51
- # configure track keys
52
- @@track_keys = []
53
- def self.track_keys=(track_keys)
54
- @@track_keys = track_keys
55
- end
56
- def self.track_keys
57
- @@track_keys
58
- end
59
-
60
- # configure ignore keys
61
- @@ignore_keys = []
62
- def self.ignore_keys=(ignore_keys)
63
- @@ignore_keys = ignore_keys
64
- end
65
- def self.ignore_keys
66
- @@ignore_keys
67
- end
68
-
69
- # configure service to be mocked so that no screenshots are
70
- # taken, and uploaded to service.
71
- @@enable_service = false
72
- def self.enable_service=(enable)
73
- @@enable_service = enable
74
- end
75
- def self.enable_service
76
- @@enable_service
77
- end
78
-
79
- # configure logger, which will be used to log issues if any
80
- @@logger = Logger.new(STDOUT)
81
- def self.logger=(new_logger)
82
- @@logger = new_logger
48
+
49
+ # configure backup file
50
+ @@backup_filepath = nil
51
+ def self.backup_filepath=(backup_filepath)
52
+ @@backup_filepath = backup_filepath
83
53
  end
84
- def self.logger
85
- @@logger
54
+ def self.backup_filepath
55
+ @@backup_filepath
86
56
  end
87
57
 
88
58
  # helper to configure above variables.
89
59
  def self.configure
90
60
  yield(self)
91
61
  end
62
+
92
63
  end
@@ -1,6 +1,5 @@
1
1
  require 'net/https'
2
2
  require 'json'
3
- require 'set'
4
3
  require 'doppler/version'
5
4
 
6
5
  module Doppler
@@ -9,50 +8,57 @@ module Doppler
9
8
  ENVIRONMENT_SEGMENT = '/environments/'
10
9
 
11
10
  def initialize()
11
+ if Doppler.api_key.nil?
12
+ raise "Please provide a api key"
13
+ end
14
+
15
+ if Doppler.pipeline.nil?
16
+ raise "Please provide a pipeline"
17
+ end
18
+
19
+
20
+ if Doppler.environment.nil?
21
+ raise "Please provide a environment"
22
+ end
23
+
12
24
  startup()
13
25
  end
14
26
 
15
27
  def startup
16
- local_keys = ENV.to_hash
17
- keys_to_send = local_keys.select { |k, _| Doppler.track_keys.include?(k) }
18
-
19
- resp = self._request('/fetch_keys', {
20
- 'local_keys' => keys_to_send
21
- })
22
-
23
- @remote_keys = resp['keys']
28
+ resp = self._request('/fetch_keys', {})
29
+ @remote_keys = resp.fetch("keys")
30
+
31
+ overwrite_env()
32
+ write_to_backup()
24
33
  end
25
-
26
- def get(key_name, priority = Doppler.priority)
27
- value =
28
- if priority == Doppler::PRIORITY_LOCAL
29
- ENV[key_name] || @remote_keys[key_name]
30
- else
31
- @remote_keys[key_name] || ENV[key_name]
34
+
35
+
36
+ def overwrite_env
37
+ if @remote_keys.nil?
38
+ return
39
+ end
40
+
41
+ @remote_keys.each do |key, value|
42
+ unless Doppler.ignore_variables.include?(key)
43
+ ENV[key] = value
32
44
  end
33
-
34
- unless Doppler.ignore_keys.include?(key_name)
35
- # TODO: Move this to a background job or thread once we get more customers!
36
- upload_key_to_server(key_name, value)
37
45
  end
38
-
39
- value
40
46
  end
41
-
42
- def upload_key_to_server(key_name, value)
43
- if value
44
- if ENV[key_name] != @remote_keys[key_name]
45
- _request('/track_key', {
46
- 'local_keys' => {key_name: ENV[key_name]}
47
- })
47
+
48
+
49
+ def write_to_backup
50
+ unless Doppler.backup_filepath.nil?
51
+ file = File.open(Doppler.backup_filepath, "w")
52
+
53
+ @remote_keys.each do |key, value|
54
+ file.puts key + "=" + value
48
55
  end
49
- else
50
- _request('/missing_key', {
51
- 'key_name' => key_name
52
- })
56
+
57
+ file.close
53
58
  end
54
59
  end
55
60
 
61
+
56
62
  def _request(endpoint, body, retry_count=0)
57
63
  raise ArgumentError, 'endpoint not string' unless endpoint.is_a? String
58
64
 
@@ -75,11 +81,30 @@ module Doppler
75
81
  if response_data['success'] == false
76
82
  raise RuntimeError, response_data["messages"].join(". ")
77
83
  end
84
+
78
85
  rescue => e
79
86
  retry_count += 1
80
87
 
81
88
  if retry_count > MAX_RETRIES
82
- raise e
89
+ if Doppler.backup_filepath.nil? or !File.file?(Doppler.backup_filepath)
90
+ raise e
91
+ end
92
+
93
+ keys = {}
94
+ File.open(Doppler.backup_filepath, "r") do |file|
95
+ file.each do |line|
96
+ parts = line.strip!.split("=")
97
+
98
+ if parts.length == 2
99
+ keys[parts[0]] = parts[1]
100
+ end
101
+ end
102
+ end
103
+
104
+ data = {}
105
+ data["keys"] = keys
106
+ return data
107
+
83
108
  else
84
109
  return _request(endpoint, body, retry_count)
85
110
  end
@@ -1,3 +1,3 @@
1
1
  module Doppler
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "1.0.1".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: 0.2.0
4
+ version: 1.0.1
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-02-03 00:00:00.000000000 Z
11
+ date: 2019-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler