rsync_config 0.1.3 → 0.2.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
  SHA1:
3
- metadata.gz: 4cd270330ad8254f82aad7aac5675aa8f4307634
4
- data.tar.gz: df548daca589d99d58be213addb1fbb901e10496
3
+ metadata.gz: b29bfb0dc6303bd3346df954749f4bfb1d4efe23
4
+ data.tar.gz: 9f0fdb8d6d7e5c73be5661e9e44f4d99369a2309
5
5
  SHA512:
6
- metadata.gz: ed121211361350f2146251f007d5585499809817aed4c6b8ba2523f268010b50767fb85db35365e055797ee21029273c809d0f8ca6ea008be07bfc588438d928
7
- data.tar.gz: 268c974d7e770e068874b69dc665f3559c797fc9896ce80a48c33c29bdc39022866b0da47ada0731642e53775e219cb1c5f92d35a79db79c7fd683996639ebeb
6
+ metadata.gz: 8e8ff54c7e1a056eec4a465547dc2ab372aa8afd8ba222205737fcc2584c55dd0baab16736e2fd90ea81cdee00dc8fda2c593c5317e16b1bcc7d1184bd41ccce
7
+ data.tar.gz: fab92e104a5bab0288a1d8866af30342698d81b064afdb183f446898d345cf6094eb6f443c44bffa5b3b8978ed6969502f29badb4976181213ce102b75709761
data/README.md CHANGED
@@ -79,6 +79,25 @@ This method will automatically try to write the secrets files when defined.
79
79
  For a raw String output, just call `RsyncConfig::Config#to_config_file` instead.
80
80
  Note that this method will not return the content of the secrets file (not sure if this will be useful).
81
81
 
82
+ ### Secrets files
83
+
84
+ Starting with version 0.2.0, it is possible to create secrets files entries using the `RsyncConfig::SecretsFile` class.
85
+ It allows to generate a file in a specific location that actually does not match the content of the entry in the config file itself.
86
+ This is particularly useful in the case of symlinks.
87
+
88
+ ```ruby
89
+ config = RsyncConfig::Config.new
90
+ config.users = {'alice' => 'wonder'}
91
+ config['secrets file'] = RsyncConfig::SecretsFile(
92
+ '/myapplication/1.0/rsyncd.secrets',
93
+ value: '/etc/rsyncd.secrets'
94
+ )
95
+ ```
96
+
97
+ `RsyncConfig::SecretsFile` accepts the physical output path as first parameter.
98
+ The `value` parameter is optional (but most likely desired) and defines the value that
99
+ will be used to generate the config file.
100
+
82
101
  ### Limitations
83
102
 
84
103
  - currently the gem does not process the directives `&include` and `&merge`.
data/lib/rsync_config.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'polyglot'
2
2
  require 'treetop'
3
3
  require 'rsync_config/version'
4
+ require 'rsync_config/config_entry'
5
+ require 'rsync_config/secrets_file'
4
6
  require 'rsync_config/parser'
5
7
  require 'rsync_config/propertiable'
6
8
  require 'rsync_config/user_management'
@@ -0,0 +1,4 @@
1
+ module RsyncConfig
2
+ module ConfigEntry
3
+ end
4
+ end
@@ -48,13 +48,15 @@ module RsyncConfig
48
48
  key = sanitize_key(key)
49
49
  if value.nil?
50
50
  properties.delete key
51
+ elsif value.is_a? ConfigEntry
52
+ properties[key] = value
51
53
  else
52
- properties[key] = value.to_s unless value.nil?
54
+ properties[key] = value.to_s
53
55
  end
54
56
  end
55
57
 
56
58
  def properties_to_a
57
- properties.map { |key, value| "#{key} = #{value}" }
59
+ properties.map { |key, value| "#{key} = #{value.to_s}" }
58
60
  end
59
61
 
60
62
  private
@@ -0,0 +1,23 @@
1
+ module RsyncConfig
2
+ class SecretsFile
3
+
4
+ include ConfigEntry
5
+
6
+ attr_accessor :value, :output
7
+
8
+ def initialize(output, **options)
9
+ raise "output cannot be nil or empty" if output.nil? || output.empty?
10
+
11
+ self.output = output
12
+ self.value = options[:value] if options[:value]
13
+ end
14
+
15
+ def value
16
+ @value.nil? ? output : @value
17
+ end
18
+
19
+ def to_s
20
+ value
21
+ end
22
+ end
23
+ end
@@ -48,8 +48,11 @@ module RsyncConfig
48
48
  end
49
49
  end
50
50
 
51
- def write_secrets_file(file)
52
- return if file.nil?
51
+ def write_secrets_file(secrets_file)
52
+ return if secrets_file.nil?
53
+
54
+ file = secrets_file.respond_to?(:output) ? secrets_file.output : secrets_file.to_s
55
+
53
56
  raise "Cannot write secrets file #{file}" if File.exists?(file) && ! File.writable?(file)
54
57
  raise "Cannot create secrets file #{file}" if !File.exist?(file) && ! ( Dir.exists?(File.dirname(file)) && File.writable?(File.dirname(file)))
55
58
 
@@ -1,3 +1,3 @@
1
1
  module RsyncConfig
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/rsync_config.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "test-unit"
24
+ spec.add_development_dependency "debugger"
24
25
 
25
26
  spec.add_dependency 'treetop', '~>1.4.14'
26
27
  end
@@ -6,7 +6,6 @@ class RsyncConfigTest < Test::Unit::TestCase
6
6
  TEST_INPUT_FILE = File.join(__dir__, 'etc', 'rsyncd.conf')
7
7
 
8
8
  TEST_INPUT_FILE_WITH_SECRETS = File.join(__dir__, 'etc', 'rsyncd_with_secrets.conf')
9
-
10
9
  TEST_OUTPUT_FILE = File.join(__dir__, 'etc', 'out', 'rsyncd.conf')
11
10
 
12
11
  TEST_SECRETS_FILE = File.join(__dir__, 'etc', 'out', 'secrets.conf')
@@ -257,4 +256,23 @@ EOL
257
256
  RsyncConfig.parse content
258
257
  end
259
258
  end
259
+
260
+ def test_using_a_secrets_file_object_outputs_to_different_file
261
+ config = RsyncConfig::Config.new
262
+ config.users = {
263
+ 'john' => 'doe'
264
+ }
265
+ secrets_output_config = "#{TEST_SECRETS_FILE}.config_value"
266
+ config['secrets file'] = RsyncConfig::SecretsFile.new(
267
+ TEST_SECRETS_FILE,
268
+ value: secrets_output_config
269
+ )
270
+
271
+ config.write_to TEST_OUTPUT_FILE
272
+ assert File.exists? TEST_SECRETS_FILE
273
+ assert_false File.exists? secrets_output_config
274
+ assert_equal secrets_output_config, config['secrets file'].to_s
275
+
276
+ File.unlink secrets_output_config if File.exists? secrets_output_config
277
+ end
260
278
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsync_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Bodi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-21 00:00:00.000000000 Z
11
+ date: 2013-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: debugger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: treetop
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,12 +94,14 @@ files:
80
94
  - Rakefile
81
95
  - lib/rsync_config.rb
82
96
  - lib/rsync_config/config.rb
97
+ - lib/rsync_config/config_entry.rb
83
98
  - lib/rsync_config/module.rb
84
99
  - lib/rsync_config/parser.rb
85
100
  - lib/rsync_config/parser/config_file.treetop
86
101
  - lib/rsync_config/parser/node_extension.rb
87
102
  - lib/rsync_config/parser/secrets_file.treetop
88
103
  - lib/rsync_config/propertiable.rb
104
+ - lib/rsync_config/secrets_file.rb
89
105
  - lib/rsync_config/user_management.rb
90
106
  - lib/rsync_config/version.rb
91
107
  - rsync_config.gemspec