constancy 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/bin/constancy +1 -1
- data/lib/constancy.rb +4 -4
- data/lib/constancy/cli.rb +6 -6
- data/lib/constancy/sync_target.rb +32 -8
- data/lib/constancy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7ada530fb88ee051c876720fd885e77cf72ca7fcd5428a1b67b2ee4af6a8783
|
4
|
+
data.tar.gz: 55258aafabeb7c9e59fa99761f09ed7840271f4a0c48e621fa46f4c5a62b4059
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dea0a26adaa5c4c7497ce11748353c4219549fdff1a4a0035d45ec7620cda19b013d7f85f4d97da4167e8940eebc03ede5717d0a1c04092c1525468721df3b0b
|
7
|
+
data.tar.gz: f59c3ae823a87ac7e8c47ccea89cbc035a6676025c65b1a42907eae2567d5efee5f3413a145d7a554b827cf6a49d669ccc702947226b5e404a87360f6d605b22
|
data/README.md
CHANGED
@@ -180,6 +180,9 @@ required. An example `constancy.yml` is below including explanatory comments:
|
|
180
180
|
# ignored. At this time there is no provision for specifying
|
181
181
|
# prefixes or patterns. Each key must be fully and explicitly
|
182
182
|
# specified.
|
183
|
+
# erb_enabled - Whether or not to run the local content through
|
184
|
+
# ERB parsing before attempting to sync to the remote. Defaults
|
185
|
+
# to `false`.
|
183
186
|
- name: myapp-config
|
184
187
|
prefix: config/myapp
|
185
188
|
datacenter: dc1
|
@@ -199,6 +202,7 @@ required. An example `constancy.yml` is below including explanatory comments:
|
|
199
202
|
datacenter: dc1
|
200
203
|
path: consul/yourapp.yml
|
201
204
|
delete: true
|
205
|
+
erb_enabled: true
|
202
206
|
|
203
207
|
You can run `constancy config` to get a summary of the defined configuration
|
204
208
|
and to double-check config syntax.
|
@@ -335,6 +339,12 @@ It's a good idea to sanity-check your ERB by running `constancy config` after
|
|
335
339
|
making any changes.
|
336
340
|
|
337
341
|
|
342
|
+
### Dynamic content
|
343
|
+
|
344
|
+
You can also choose to enable ERB parsing for local content as well, by setting
|
345
|
+
`erb_enabled: true` on any sync targets you wish to populate in this way.
|
346
|
+
|
347
|
+
|
338
348
|
### Environment configuration
|
339
349
|
|
340
350
|
Constancy may be partially configured using environment variables:
|
data/bin/constancy
CHANGED
data/lib/constancy.rb
CHANGED
@@ -6,10 +6,10 @@ require 'fileutils'
|
|
6
6
|
require 'ostruct'
|
7
7
|
require 'yaml'
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
require_relative 'constancy/version'
|
10
|
+
require_relative 'constancy/config'
|
11
|
+
require_relative 'constancy/diff'
|
12
|
+
require_relative 'constancy/sync_target'
|
13
13
|
|
14
14
|
class Constancy
|
15
15
|
class InternalError < RuntimeError; end
|
data/lib/constancy/cli.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# This software is public domain. No rights are reserved. See LICENSE for more information.
|
2
2
|
|
3
|
-
|
3
|
+
require_relative '../constancy'
|
4
4
|
require 'diffy'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
require_relative 'cli/check_command'
|
6
|
+
require_relative 'cli/push_command'
|
7
|
+
require_relative 'cli/pull_command'
|
8
|
+
require_relative 'cli/config_command'
|
9
|
+
require_relative 'cli/targets_command'
|
10
10
|
|
11
11
|
class Constancy
|
12
12
|
class CLI
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
class Constancy
|
4
4
|
class SyncTarget
|
5
|
-
VALID_CONFIG_KEYS = %w( name type datacenter prefix path exclude chomp delete )
|
6
|
-
attr_accessor :name, :type, :datacenter, :prefix, :path, :exclude, :consul
|
5
|
+
VALID_CONFIG_KEYS = %w( name type datacenter prefix path exclude chomp delete erb_enabled )
|
6
|
+
attr_accessor :name, :type, :datacenter, :prefix, :path, :exclude, :consul, :erb_enabled
|
7
7
|
|
8
8
|
REQUIRED_CONFIG_KEYS = %w( prefix )
|
9
9
|
VALID_TYPES = [ :dir, :file ]
|
@@ -47,6 +47,11 @@ class Constancy
|
|
47
47
|
end
|
48
48
|
|
49
49
|
self.consul = Imperium::KV.new(imperium_config)
|
50
|
+
self.erb_enabled = config['erb_enabled']
|
51
|
+
end
|
52
|
+
|
53
|
+
def erb_enabled?
|
54
|
+
@erb_enabled
|
50
55
|
end
|
51
56
|
|
52
57
|
def chomp?
|
@@ -89,22 +94,41 @@ class Constancy
|
|
89
94
|
when :dir
|
90
95
|
self.local_files.each do |local_file|
|
91
96
|
@local_items[local_file.sub(%r{^#{self.base_path}/?}, '')] =
|
92
|
-
|
93
|
-
File.read(local_file).chomp.force_encoding(Encoding::ASCII_8BIT)
|
94
|
-
else
|
95
|
-
File.read(local_file).force_encoding(Encoding::ASCII_8BIT)
|
96
|
-
end
|
97
|
+
load_local_file(local_file)
|
97
98
|
end
|
98
99
|
|
99
100
|
when :file
|
100
101
|
if File.exist?(self.base_path)
|
101
|
-
@local_items =
|
102
|
+
@local_items = local_items_from_file
|
102
103
|
end
|
103
104
|
end
|
104
105
|
|
105
106
|
@local_items
|
106
107
|
end
|
107
108
|
|
109
|
+
def local_items_from_file
|
110
|
+
if erb_enabled?
|
111
|
+
loaded_file = YAML.load(ERB.new(File.read(self.base_path)).result)
|
112
|
+
else
|
113
|
+
loaded_file = YAML.load_file(self.base_path)
|
114
|
+
end
|
115
|
+
|
116
|
+
flatten_hash(nil, loaded_file)
|
117
|
+
end
|
118
|
+
|
119
|
+
def load_local_file(local_file)
|
120
|
+
file = File.read(local_file)
|
121
|
+
|
122
|
+
if self.chomp?
|
123
|
+
encoded_file = file.chomp.force_encoding(Encoding::ASCII_8BIT)
|
124
|
+
else
|
125
|
+
encoded_file = file.force_encoding(Encoding::ASCII_8BIT)
|
126
|
+
end
|
127
|
+
|
128
|
+
return ERB.new(encoded_file).result if erb_enabled?
|
129
|
+
encoded_file
|
130
|
+
end
|
131
|
+
|
108
132
|
def remote_items
|
109
133
|
return @remote_items if not @remote_items.nil?
|
110
134
|
@remote_items = {}
|
data/lib/constancy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constancy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Adams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: imperium
|