rcloadenv 0.1.1 → 0.2.0.pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +19 -3
- data/lib/rcloadenv/cli.rb +10 -6
- data/lib/rcloadenv/loader.rb +37 -2
- data/lib/rcloadenv/version.rb +1 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1cc4bb306ab969ea6a63f15e5fc9075df593306293f766d660f23a2ec9087dd0
|
4
|
+
data.tar.gz: feb5de2a2e1a2de5c08a0ce42c54d88496cf8a4d478a37ecbe980dbfa4bd7f98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fdc21e25f7b66625cad77dbf9ad9872e1150728c07775e3d47b45ee2e57d9be83ade8f1fbe2d2c7d385e10ee4b1706e3fd398d9cc8cef32687a4f369f709ae0
|
7
|
+
data.tar.gz: a6aa807120a6ea3d0b449d7a6b9e2ae910324cabf5c1875076ec4fd484e867890d8f5f443a97cfb732dfa2cbbbbe44250a839a12cdb45455385a6a0dbef06e72
|
data/README.md
CHANGED
@@ -14,11 +14,27 @@ Install the gem using
|
|
14
14
|
Alternately, include "rcloadenv" in your application's Gemfile.
|
15
15
|
|
16
16
|
You may then invoke the "rcloadenv" binary. You must pass the name of the
|
17
|
-
runtime config resource, and then
|
18
|
-
|
17
|
+
runtime config resource, and then optionally a command to execute, delimited
|
18
|
+
by two dashes `--`.
|
19
|
+
|
20
|
+
If a command is provided, rcloadenv loads the configuration into environment
|
21
|
+
variables and runs the command. For example, if the gem is present in the
|
22
|
+
bundle for your Rails app, you can execute:
|
19
23
|
|
20
24
|
bundle exec rcloadenv my-config -- bin/rails s
|
21
25
|
|
26
|
+
to run Rails directly with the loaded environment.
|
27
|
+
|
28
|
+
If a command is _not_ provided_, rcloadenv loads the configuration and prints
|
29
|
+
it to stdout in dotenv-compatible format. For example, you can execute:
|
30
|
+
|
31
|
+
bundle exec rcloadenv my-config > .env
|
32
|
+
|
33
|
+
to create a `.env` file suitable for loading with the
|
34
|
+
[dotenv](https://github.com/bkeepers/dotenv/) gem.
|
35
|
+
|
36
|
+
### Accessing runtime config data
|
37
|
+
|
22
38
|
If `rcloadenv` is run on Google Cloud Platform hosting (such as Google Compute
|
23
39
|
Engine, Container Engine, or App Engine), then it infers the project name and
|
24
40
|
credentials from the hosting environment.
|
@@ -34,7 +50,7 @@ Run `rcloadenv --help` for more information on flags you can set.
|
|
34
50
|
When not running on GCP, credentials are obtained from
|
35
51
|
[Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials),
|
36
52
|
so you can set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable or
|
37
|
-
configure `gcloud auth`.
|
53
|
+
configure `gcloud auth application-default login`.
|
38
54
|
|
39
55
|
## Example: Loading the Rails SECRET_KEY_BASE in Google App Engine
|
40
56
|
|
data/lib/rcloadenv/cli.rb
CHANGED
@@ -35,7 +35,7 @@ module RCLoadEnv
|
|
35
35
|
@debug = false
|
36
36
|
|
37
37
|
@parser = OptionParser.new do |opts|
|
38
|
-
opts.banner = "Usage: rcloadenv [options] <config-name> -- <command>"
|
38
|
+
opts.banner = "Usage: rcloadenv [options] <config-name> [-- <command>]"
|
39
39
|
opts.on "-p name", "--project=name", "--projectId=name",
|
40
40
|
"Project to read runtime config from" do |p|
|
41
41
|
@project = p
|
@@ -66,7 +66,7 @@ module RCLoadEnv
|
|
66
66
|
end
|
67
67
|
|
68
68
|
separator_index = args.index "--"
|
69
|
-
@command_list = separator_index ? args[(separator_index+1)..-1] :
|
69
|
+
@command_list = separator_index ? args[(separator_index+1)..-1] : nil
|
70
70
|
|
71
71
|
args = args[0..separator_index] if separator_index
|
72
72
|
begin
|
@@ -82,8 +82,8 @@ module RCLoadEnv
|
|
82
82
|
usage_error "Extra arguments found: #{remaining_args.inspect}"
|
83
83
|
end
|
84
84
|
|
85
|
-
if @command_list.empty?
|
86
|
-
usage_error "
|
85
|
+
if @command_list && @command_list.empty?
|
86
|
+
usage_error "Command cannot be empty. To output dotenv format, omit `--`."
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -95,8 +95,12 @@ module RCLoadEnv
|
|
95
95
|
loader = RCLoadEnv::Loader.new @config_name,
|
96
96
|
exclude: @exclude, include: @include, override: @override,
|
97
97
|
project: @project, debug: @debug
|
98
|
-
|
99
|
-
|
98
|
+
if @command_list
|
99
|
+
loader.modify_env ENV
|
100
|
+
exec(*@command_list)
|
101
|
+
else
|
102
|
+
loader.write_dotenv
|
103
|
+
end
|
100
104
|
end
|
101
105
|
|
102
106
|
## @private
|
data/lib/rcloadenv/loader.rb
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
;
|
15
15
|
|
16
|
+
require "shellwords"
|
16
17
|
require "rcloadenv/api_client"
|
17
18
|
require "google/cloud/env"
|
18
19
|
|
@@ -72,7 +73,7 @@ module RCLoadEnv
|
|
72
73
|
debug "Skipping config variable #{k}"
|
73
74
|
else
|
74
75
|
debug "Found config variable #{k}"
|
75
|
-
key = k
|
76
|
+
key = make_env_key k
|
76
77
|
if !env.include?(key)
|
77
78
|
debug "Setting envvar: #{key}"
|
78
79
|
env[key] = v
|
@@ -88,7 +89,26 @@ module RCLoadEnv
|
|
88
89
|
end
|
89
90
|
|
90
91
|
##
|
91
|
-
#
|
92
|
+
# Modify the given environment with the configuration. The given hash
|
93
|
+
# is modified in place and returned. If no hash is provided, a new one is
|
94
|
+
# created and returned.
|
95
|
+
#
|
96
|
+
# @param [Hash<String,String>] env The environment to modify.
|
97
|
+
# @return the modified environment.
|
98
|
+
#
|
99
|
+
def write_dotenv io=STDOUT
|
100
|
+
raw_variables.each do |k, v|
|
101
|
+
key = make_env_key k
|
102
|
+
if key =~ /^[\w\.]+$/
|
103
|
+
io.puts "#{key}=\"#{escape_for_dotenv v}\""
|
104
|
+
else
|
105
|
+
error "Bad key: #{key}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# Returns the hash of variables retrieved from the runtime config.
|
92
112
|
# Variable names have the parent (project and config name) stripped.
|
93
113
|
# Values are all converted to strings.
|
94
114
|
#
|
@@ -149,10 +169,25 @@ module RCLoadEnv
|
|
149
169
|
s
|
150
170
|
end
|
151
171
|
|
172
|
+
## @private
|
173
|
+
def make_env_key key
|
174
|
+
key.split("/").last.upcase.gsub("-", "_")
|
175
|
+
end
|
176
|
+
|
177
|
+
## @private
|
178
|
+
def escape_for_dotenv value
|
179
|
+
value.gsub("\\", "\\\\\\\\").gsub("\n", "\\\\n").gsub("$", "\\\\$")
|
180
|
+
end
|
181
|
+
|
152
182
|
## @private
|
153
183
|
def debug str
|
154
184
|
STDERR.puts "RCLOADENV DEBUG: #{str}" if @debug
|
155
185
|
end
|
186
|
+
|
187
|
+
## @private
|
188
|
+
def error str
|
189
|
+
STDERR.puts "RCLOADENV ERROR: #{str}"
|
190
|
+
end
|
156
191
|
end
|
157
192
|
|
158
193
|
end
|
data/lib/rcloadenv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcloadenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.pre.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-api-client
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0.9'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: dotenv
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '2.2'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '2.2'
|
125
139
|
description: rcloadenv is a tool for loading configuration from the Google Runtime
|
126
140
|
Config API into environment variables. The rcloadenv ruby gem is a ruby implementation
|
127
141
|
of the tool that may be installed as a ruby gem or included in a ruby Gemfile.
|
@@ -161,12 +175,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
175
|
version: 2.0.0
|
162
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
177
|
requirements:
|
164
|
-
- - "
|
178
|
+
- - ">"
|
165
179
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
180
|
+
version: 1.3.1
|
167
181
|
requirements: []
|
168
182
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.6.
|
183
|
+
rubygems_version: 2.6.14
|
170
184
|
signing_key:
|
171
185
|
specification_version: 4
|
172
186
|
summary: Load Google Runtime Config data into environment variables
|