hiera-eyaml 3.3.0 → 4.0.0
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 +4 -4
- data/.github/dependabot.yml +17 -0
- data/.github/workflows/release.yml +2 -2
- data/.github/workflows/test.yml +38 -21
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +416 -0
- data/CHANGELOG.md +59 -0
- data/Gemfile +13 -14
- data/README.md +37 -7
- data/Rakefile +11 -4
- data/hiera-eyaml.gemspec +17 -15
- data/lib/hiera/backend/eyaml/CLI.rb +12 -19
- data/lib/hiera/backend/eyaml/commands.rb +2 -6
- data/lib/hiera/backend/eyaml/edithelper.rb +24 -19
- data/lib/hiera/backend/eyaml/encrypthelper.rb +17 -19
- data/lib/hiera/backend/eyaml/encryptor.rb +40 -43
- data/lib/hiera/backend/eyaml/encryptors/pkcs7.rb +79 -105
- data/lib/hiera/backend/eyaml/highlinehelper.rb +3 -5
- data/lib/hiera/backend/eyaml/logginghelper.rb +27 -29
- data/lib/hiera/backend/eyaml/options.rb +13 -16
- data/lib/hiera/backend/eyaml/parser/encrypted_tokens.rb +2 -2
- data/lib/hiera/backend/eyaml/parser/parser.rb +35 -36
- data/lib/hiera/backend/eyaml/parser/token.rb +15 -6
- data/lib/hiera/backend/eyaml/plugins.rb +13 -18
- data/lib/hiera/backend/eyaml/subcommand.rb +72 -74
- data/lib/hiera/backend/eyaml/subcommands/createkeys.rb +2 -6
- data/lib/hiera/backend/eyaml/subcommands/decrypt.rb +52 -52
- data/lib/hiera/backend/eyaml/subcommands/edit.rb +58 -59
- data/lib/hiera/backend/eyaml/subcommands/encrypt.rb +65 -69
- data/lib/hiera/backend/eyaml/subcommands/help.rb +17 -22
- data/lib/hiera/backend/eyaml/subcommands/recrypt.rb +13 -20
- data/lib/hiera/backend/eyaml/subcommands/unknown_command.rb +10 -14
- data/lib/hiera/backend/eyaml/subcommands/version.rb +4 -9
- data/lib/hiera/backend/eyaml/utils.rb +27 -28
- data/lib/hiera/backend/eyaml.rb +7 -9
- data/lib/hiera/backend/eyaml_backend.rb +34 -28
- metadata +63 -14
- data/tools/git_tag_release.rb +0 -98
- data/tools/regem.sh +0 -11
@@ -8,144 +8,118 @@ class Hiera
|
|
8
8
|
module Backend
|
9
9
|
module Eyaml
|
10
10
|
module Encryptors
|
11
|
-
|
12
11
|
class Pkcs7 < Encryptor
|
13
|
-
|
14
12
|
self.options = {
|
15
|
-
:
|
16
|
-
|
17
|
-
|
18
|
-
:
|
19
|
-
|
20
|
-
|
21
|
-
:
|
22
|
-
|
23
|
-
:
|
24
|
-
|
25
|
-
:
|
26
|
-
|
27
|
-
|
28
|
-
:keysize => { :desc => "Key size used for encryption",
|
29
|
-
:type => :integer,
|
30
|
-
:default => 2048 },
|
31
|
-
:digest => { :desc => "Hash function used for PKCS7",
|
32
|
-
:type => :string,
|
33
|
-
:default => "SHA256"},
|
13
|
+
private_key: { desc: 'Path to private key',
|
14
|
+
type: :string,
|
15
|
+
default: './keys/private_key.pkcs7.pem', },
|
16
|
+
public_key: { desc: 'Path to public key',
|
17
|
+
type: :string,
|
18
|
+
default: './keys/public_key.pkcs7.pem', },
|
19
|
+
private_key_env_var: { desc: 'Name of environment variable to read private key from',
|
20
|
+
type: :string, },
|
21
|
+
public_key_env_var: { desc: 'Name of environment variable to read public key from',
|
22
|
+
type: :string, },
|
23
|
+
keysize: { desc: 'Key size used for encryption',
|
24
|
+
type: :integer,
|
25
|
+
default: 2048, },
|
34
26
|
}
|
35
27
|
|
36
|
-
self.tag =
|
37
|
-
|
38
|
-
def self.encrypt plaintext
|
28
|
+
self.tag = 'PKCS7'
|
39
29
|
|
40
|
-
|
30
|
+
def self.encrypt(plaintext)
|
31
|
+
LoggingHelper.trace 'PKCS7 encrypt'
|
41
32
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
if public_key_env_var and ENV[public_key_env_var]
|
51
|
-
public_key_pem = ENV[public_key_env_var]
|
33
|
+
public_key_pem = load_public_key_pem
|
34
|
+
if public_key_pem.include? 'BEGIN CERTIFICATE'
|
35
|
+
public_key_x509 = OpenSSL::X509::Certificate.new(public_key_pem)
|
36
|
+
elsif public_key_pem.include? 'BEGIN PUBLIC KEY'
|
37
|
+
public_key_rsa = OpenSSL::PKey::RSA.new(public_key_pem)
|
38
|
+
public_key_x509 = OpenSSL::X509::Certificate.new
|
39
|
+
public_key_x509.public_key = public_key_rsa.public_key
|
52
40
|
else
|
53
|
-
public_key_pem
|
41
|
+
raise StandardError, "file #{public_key_pem} cannot be used to encrypt - invalid public key format"
|
54
42
|
end
|
55
|
-
public_key_x509 = OpenSSL::X509::Certificate.new( public_key_pem )
|
56
43
|
|
57
|
-
cipher = OpenSSL::Cipher
|
58
|
-
OpenSSL::PKCS7
|
44
|
+
cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
45
|
+
OpenSSL::PKCS7.encrypt([public_key_x509], plaintext, cipher, OpenSSL::PKCS7::BINARY).to_der
|
59
46
|
end
|
60
47
|
|
61
|
-
def self.decrypt
|
62
|
-
|
63
|
-
LoggingHelper::trace 'PKCS7 decrypt'
|
48
|
+
def self.decrypt(ciphertext)
|
49
|
+
LoggingHelper.trace 'PKCS7 decrypt'
|
64
50
|
|
65
|
-
|
66
|
-
|
67
|
-
public_key_env_var = self.option :public_key_env_var
|
68
|
-
private_key_env_var = self.option :private_key_env_var
|
69
|
-
raise StandardError, "pkcs7_public_key is not defined" unless public_key or public_key_env_var
|
70
|
-
raise StandardError, "pkcs7_private_key is not defined" unless private_key or private_key_env_var
|
51
|
+
private_key_pem = load_private_key_pem
|
52
|
+
private_key_rsa = OpenSSL::PKey::RSA.new(private_key_pem)
|
71
53
|
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
if private_key and private_key_env_var
|
76
|
-
warn "both private_key and private_key_env_var specified, using private_key"
|
77
|
-
end
|
54
|
+
public_key_pem = load_public_key_pem
|
55
|
+
public_key_x509 = OpenSSL::X509::Certificate.new(public_key_pem)
|
78
56
|
|
79
|
-
|
80
|
-
private_key_pem = ENV[private_key_env_var]
|
81
|
-
else
|
82
|
-
private_key_pem = File.read private_key
|
83
|
-
end
|
84
|
-
private_key_rsa = OpenSSL::PKey::RSA.new( private_key_pem )
|
85
|
-
|
86
|
-
if public_key_env_var and ENV[public_key_env_var]
|
87
|
-
public_key_pem = ENV[public_key_env_var]
|
88
|
-
else
|
89
|
-
public_key_pem = File.read public_key
|
90
|
-
end
|
91
|
-
public_key_x509 = OpenSSL::X509::Certificate.new( public_key_pem )
|
92
|
-
|
93
|
-
pkcs7 = OpenSSL::PKCS7.new( ciphertext )
|
57
|
+
pkcs7 = OpenSSL::PKCS7.new(ciphertext)
|
94
58
|
pkcs7.decrypt(private_key_rsa, public_key_x509)
|
95
|
-
|
96
59
|
end
|
97
60
|
|
98
61
|
def self.create_keys
|
62
|
+
# Do equivalent of:
|
63
|
+
# openssl req -x509 -nodes -newkey rsa:2048 -keyout privatekey.pem -out publickey.pem -batch
|
99
64
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
public_key = self.option :public_key
|
104
|
-
private_key = self.option :private_key
|
105
|
-
subject = self.option :subject
|
106
|
-
keysize = self.option :keysize
|
107
|
-
digest = self.option :digest
|
65
|
+
public_key = option :public_key
|
66
|
+
private_key = option :private_key
|
67
|
+
keysize = option :keysize
|
108
68
|
|
109
69
|
key = OpenSSL::PKey::RSA.new(keysize)
|
110
70
|
EncryptHelper.ensure_key_dir_exists private_key
|
111
|
-
EncryptHelper.write_important_file :
|
71
|
+
EncryptHelper.write_important_file filename: private_key, content: key.to_pem, mode: 0o600
|
112
72
|
|
113
|
-
cert = OpenSSL::X509::Certificate.new
|
114
|
-
|
115
|
-
cert.
|
116
|
-
|
73
|
+
cert = OpenSSL::X509::Certificate.new
|
74
|
+
# In JRuby implementation of openssl, not_before and not_after
|
75
|
+
# are required to sign cert with key and digest. Signing the
|
76
|
+
# certificate is only required for Ruby 2.7 to call cert.to_pem.
|
117
77
|
cert.not_before = Time.now
|
118
|
-
cert.not_after = if 1.size == 8
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
78
|
+
cert.not_after = if 1.size == 8 # 64bit
|
79
|
+
Time.now + (50 * 365 * 24 * 60 * 60)
|
80
|
+
else # 32bit
|
81
|
+
Time.at(0x7fffffff)
|
82
|
+
end
|
123
83
|
cert.public_key = key.public_key
|
84
|
+
cert.sign key, OpenSSL::Digest.new('SHA256')
|
124
85
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
ef.create_extension("basicConstraints","CA:TRUE", true),
|
130
|
-
ef.create_extension("subjectKeyIdentifier", "hash"),
|
131
|
-
]
|
132
|
-
cert.add_extension ef.create_extension("authorityKeyIdentifier",
|
133
|
-
"keyid:always,issuer:always")
|
86
|
+
EncryptHelper.ensure_key_dir_exists public_key
|
87
|
+
EncryptHelper.write_important_file filename: public_key, content: cert.to_pem
|
88
|
+
LoggingHelper.info 'Keys created OK'
|
89
|
+
end
|
134
90
|
|
135
|
-
|
91
|
+
def self.load_ANY_key_pem(optname_key, optname_env_var)
|
92
|
+
opt_key = option(optname_key.to_sym)
|
93
|
+
opt_key_env_var = option(optname_env_var.to_sym)
|
136
94
|
|
137
|
-
|
138
|
-
|
139
|
-
|
95
|
+
if opt_key and opt_key_env_var
|
96
|
+
warn "both #{optname_key} and #{optname_env_var} specified, using #{optname_env_var}"
|
97
|
+
end
|
140
98
|
|
99
|
+
if opt_key_env_var
|
100
|
+
raise StandardError, "env #{opt_key_env_var} is not set" unless ENV[opt_key_env_var]
|
101
|
+
|
102
|
+
opt_key_pem = ENV.fetch(opt_key_env_var, nil)
|
103
|
+
elsif opt_key
|
104
|
+
raise StandardError, "file #{opt_key} does not exist" unless File.exist? opt_key
|
105
|
+
|
106
|
+
opt_key_pem = File.read opt_key
|
107
|
+
else
|
108
|
+
raise StandardError, "pkcs7_#{optname_key} is not defined" unless opt_key or opt_key_env_var
|
109
|
+
end
|
110
|
+
|
111
|
+
opt_key_pem
|
141
112
|
end
|
142
113
|
|
143
|
-
|
114
|
+
def self.load_public_key_pem
|
115
|
+
load_ANY_key_pem('public_key', 'public_key_env_var')
|
116
|
+
end
|
144
117
|
|
118
|
+
def self.load_private_key_pem
|
119
|
+
load_ANY_key_pem('private_key', 'private_key_env_var')
|
120
|
+
end
|
121
|
+
end
|
145
122
|
end
|
146
|
-
|
147
123
|
end
|
148
|
-
|
149
124
|
end
|
150
|
-
|
151
125
|
end
|
@@ -4,20 +4,18 @@ class Hiera
|
|
4
4
|
module Backend
|
5
5
|
module Eyaml
|
6
6
|
class HighlineHelper
|
7
|
-
|
8
7
|
def self.read_password
|
9
|
-
ask(
|
8
|
+
ask('Enter password: ') { |q| q.echo = '*' }
|
10
9
|
end
|
11
10
|
|
12
|
-
def self.confirm?
|
11
|
+
def self.confirm?(message)
|
13
12
|
result = ask("#{message} (y/N): ")
|
14
|
-
if result.downcase ==
|
13
|
+
if result.downcase == 'y' or result.downcase == 'yes'
|
15
14
|
true
|
16
15
|
else
|
17
16
|
false
|
18
17
|
end
|
19
18
|
end
|
20
|
-
|
21
19
|
end
|
22
20
|
end
|
23
21
|
end
|
@@ -5,14 +5,13 @@ class Hiera
|
|
5
5
|
module Backend
|
6
6
|
module Eyaml
|
7
7
|
class LoggingHelper
|
8
|
-
|
9
|
-
|
10
|
-
message = {:from => "hiera-eyaml-core"}
|
8
|
+
def self.structure_message(messageinfo)
|
9
|
+
message = { from: 'hiera-eyaml-core' }
|
11
10
|
case messageinfo.class.to_s
|
12
11
|
when 'Hash'
|
13
12
|
message.merge!(messageinfo)
|
14
13
|
else
|
15
|
-
message.merge!({:
|
14
|
+
message.merge!({ msg: messageinfo.to_s })
|
16
15
|
end
|
17
16
|
message[:prefix] = "[#{message[:from]}]"
|
18
17
|
message[:spacer] = " #{' ' * message[:from].length} "
|
@@ -26,54 +25,53 @@ class Hiera
|
|
26
25
|
formatted_output.join "\n"
|
27
26
|
end
|
28
27
|
|
29
|
-
def self.warn
|
30
|
-
|
28
|
+
def self.warn(messageinfo)
|
29
|
+
print_message({ message: structure_message(messageinfo), hiera_loglevel: :warn, cli_color: :red })
|
31
30
|
end
|
32
31
|
|
33
|
-
def self.info
|
34
|
-
|
32
|
+
def self.info(messageinfo)
|
33
|
+
print_message({ message: structure_message(messageinfo), hiera_loglevel: :debug, cli_color: :white, threshold: 0 })
|
35
34
|
end
|
36
35
|
|
37
|
-
def self.debug
|
38
|
-
|
36
|
+
def self.debug(messageinfo)
|
37
|
+
print_message({ message: structure_message(messageinfo), hiera_loglevel: :debug, cli_color: :green, threshold: 1 })
|
39
38
|
end
|
40
39
|
|
41
|
-
def self.trace
|
42
|
-
|
40
|
+
def self.trace(messageinfo)
|
41
|
+
print_message({ message: structure_message(messageinfo), hiera_loglevel: :debug, cli_color: :blue, threshold: 2 })
|
43
42
|
end
|
44
43
|
|
45
|
-
def self.print_message(
|
46
|
-
message = args[:message] ||=
|
44
|
+
def self.print_message(args)
|
45
|
+
message = args[:message] ||= ''
|
47
46
|
hiera_loglevel = args[:hiera_loglevel] ||= :debug
|
48
47
|
cli_color = args[:cli_color] ||= :blue
|
49
48
|
threshold = args[:threshold]
|
50
49
|
|
51
|
-
if
|
50
|
+
if hiera?
|
52
51
|
Hiera.send(hiera_loglevel, message) if threshold.nil? or Eyaml.verbosity_level > threshold
|
53
|
-
|
54
|
-
STDERR.puts self.colorize( message, cli_color )
|
52
|
+
elsif threshold.nil? or Eyaml.verbosity_level > threshold
|
53
|
+
STDERR.puts self.colorize( message, cli_color )
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
|
-
def self.colorize
|
57
|
+
def self.colorize(message, color)
|
59
58
|
suffix = "\e[0m"
|
60
59
|
prefix = case color
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
60
|
+
when :red
|
61
|
+
"\e[31m"
|
62
|
+
when :green
|
63
|
+
"\e[32m"
|
64
|
+
when :blue
|
65
|
+
"\e[34m"
|
66
|
+
else # :white
|
67
|
+
"\e[0m"
|
68
|
+
end
|
70
69
|
"#{prefix}#{message}#{suffix}"
|
71
70
|
end
|
72
71
|
|
73
72
|
def self.hiera?
|
74
|
-
|
73
|
+
'hiera'.eql? Eyaml::Options[:source]
|
75
74
|
end
|
76
|
-
|
77
75
|
end
|
78
76
|
end
|
79
77
|
end
|
@@ -2,37 +2,34 @@ class Hiera
|
|
2
2
|
module Backend
|
3
3
|
module Eyaml
|
4
4
|
class Options
|
5
|
-
|
6
|
-
def self.[]= key, value
|
5
|
+
def self.[]=(key, value)
|
7
6
|
@@options ||= {}
|
8
|
-
@@options[
|
7
|
+
@@options[key.to_sym] = value
|
9
8
|
end
|
10
9
|
|
11
|
-
def self.[]
|
10
|
+
def self.[](key)
|
12
11
|
@@options ||= {}
|
13
|
-
@@options[
|
12
|
+
@@options[key.to_sym]
|
14
13
|
end
|
15
14
|
|
16
|
-
def self.set
|
15
|
+
def self.set(hash)
|
17
16
|
@@options = {}
|
18
17
|
hash.each do |k, v|
|
19
|
-
@@options[
|
18
|
+
@@options[k.to_sym] = v
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
22
|
def self.trace
|
24
|
-
LoggingHelper
|
25
|
-
LoggingHelper
|
23
|
+
LoggingHelper.trace 'Dump of eyaml tool options dict:'
|
24
|
+
LoggingHelper.trace '--------------------------------'
|
26
25
|
@@options.each do |k, v|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
26
|
+
LoggingHelper.trace format '%18s %-18s = %18s %-18s', "(#{k.class.name})", k.to_s, "(#{v.class.name})",
|
27
|
+
v.to_s
|
28
|
+
rescue StandardError
|
29
|
+
LoggingHelper.trace format '%18s %-18s = %18s %-18s', "(#{k.class.name})", k.to_s, "(#{v.class.name})", '<unprintable>' # case where v is binary
|
32
30
|
end
|
33
|
-
LoggingHelper
|
31
|
+
LoggingHelper.trace '--------------------------------'
|
34
32
|
end
|
35
|
-
|
36
33
|
end
|
37
34
|
end
|
38
35
|
end
|
@@ -66,7 +66,7 @@ class Hiera
|
|
66
66
|
case format
|
67
67
|
when :block
|
68
68
|
@cipher = @cipher.gsub(/\s/, '')
|
69
|
-
chevron = args[:use_chevron].nil? || args[:use_chevron] ? ">\n" : ''
|
69
|
+
chevron = (args[:use_chevron].nil? || args[:use_chevron]) ? ">\n" : ''
|
70
70
|
"#{label_string}#{chevron}" + @indentation + "ENC[#{@encryptor.tag},#{@cipher}]".scan(/.{1,60}/).join("\n" + @indentation)
|
71
71
|
when :string
|
72
72
|
ciphertext = @cipher.gsub(/[\n\r]/, '')
|
@@ -85,7 +85,7 @@ class Hiera
|
|
85
85
|
|
86
86
|
case format
|
87
87
|
when :block
|
88
|
-
chevron = args[:use_chevron].nil? || args[:use_chevron] ? ">\n" : ''
|
88
|
+
chevron = (args[:use_chevron].nil? || args[:use_chevron]) ? ">\n" : ''
|
89
89
|
"#{label_string}#{chevron}" + indentation + "DEC#{index}::#{@encryptor.tag}[" + @plain_text + ']!'
|
90
90
|
when :string
|
91
91
|
"#{label_string}DEC#{index}::#{@encryptor.tag}[" + @plain_text + ']!'
|
@@ -8,19 +8,19 @@ class Hiera
|
|
8
8
|
module Parser
|
9
9
|
class ParserFactory
|
10
10
|
def self.encrypted_parser
|
11
|
-
enc_string = EncStringTokenType.new
|
12
|
-
enc_block = EncBlockTokenType.new
|
11
|
+
enc_string = EncStringTokenType.new
|
12
|
+
enc_block = EncBlockTokenType.new
|
13
13
|
Parser.new([enc_string, enc_block])
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.decrypted_parser
|
17
|
-
dec_string = DecStringTokenType.new
|
18
|
-
dec_block = DecBlockTokenType.new
|
17
|
+
dec_string = DecStringTokenType.new
|
18
|
+
dec_block = DecBlockTokenType.new
|
19
19
|
Parser.new([dec_string, dec_block])
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.hiera_backend_parser
|
23
|
-
enc_hiera = EncHieraTokenType.new
|
23
|
+
enc_hiera = EncHieraTokenType.new
|
24
24
|
Parser.new([enc_hiera])
|
25
25
|
end
|
26
26
|
end
|
@@ -32,51 +32,50 @@ class Hiera
|
|
32
32
|
@token_types = token_types
|
33
33
|
end
|
34
34
|
|
35
|
-
def parse
|
35
|
+
def parse(text)
|
36
36
|
parse_scanner(StringScanner.new(text)).reverse
|
37
37
|
end
|
38
38
|
|
39
|
-
def parse_scanner
|
39
|
+
def parse_scanner(s)
|
40
40
|
if s.eos?
|
41
41
|
[]
|
42
42
|
else
|
43
43
|
# Check if the scanner currently matches a regex
|
44
|
-
current_match = @token_types.find
|
44
|
+
current_match = @token_types.find do |token_type|
|
45
45
|
s.match?(token_type.regex)
|
46
|
-
|
46
|
+
end
|
47
47
|
|
48
48
|
token =
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
49
|
+
if current_match.nil?
|
50
|
+
# No regex matches here. Find the earliest match.
|
51
|
+
next_match_indexes = @token_types.map do |token_type|
|
52
|
+
next_match = s.check_until(token_type.regex)
|
53
|
+
if next_match.nil?
|
54
|
+
nil
|
55
|
+
else
|
56
|
+
next_match.length - s.matched.length
|
57
|
+
end
|
58
|
+
end.reject { |i| i.nil? }
|
59
|
+
non_match_size =
|
60
|
+
if next_match_indexes.length == 0
|
61
|
+
s.rest_size
|
62
|
+
else
|
63
|
+
next_match_indexes.min
|
64
|
+
end
|
65
|
+
non_match = s.peek(non_match_size)
|
66
|
+
# advance scanner
|
67
|
+
s.pos = s.pos + non_match_size
|
68
|
+
NonMatchToken.new(non_match)
|
69
|
+
else
|
70
|
+
# A regex matches so create a token and do a recursive call with the advanced scanner
|
71
|
+
current_match.create_token s.scan(current_match.regex)
|
72
|
+
end
|
73
73
|
|
74
|
-
|
74
|
+
parse_scanner(s) << token
|
75
75
|
end
|
76
76
|
end
|
77
|
-
|
78
77
|
end
|
79
78
|
end
|
80
79
|
end
|
81
80
|
end
|
82
|
-
end
|
81
|
+
end
|
@@ -4,26 +4,32 @@ class Hiera
|
|
4
4
|
module Parser
|
5
5
|
class TokenType
|
6
6
|
attr_reader :regex
|
7
|
+
|
7
8
|
@regex
|
8
|
-
def create_token
|
9
|
+
def create_token(_string)
|
9
10
|
raise 'Abstract method called'
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
14
|
class Token
|
14
15
|
attr_reader :match
|
16
|
+
|
15
17
|
def initialize(match)
|
16
18
|
@match = match
|
17
19
|
end
|
18
|
-
|
20
|
+
|
21
|
+
def to_encrypted(_args = {})
|
19
22
|
raise 'Abstract method called'
|
20
23
|
end
|
21
|
-
|
24
|
+
|
25
|
+
def to_decrypted(_args = {})
|
22
26
|
raise 'Abstract method called'
|
23
27
|
end
|
28
|
+
|
24
29
|
def to_plain_text
|
25
30
|
raise 'Abstract method called'
|
26
31
|
end
|
32
|
+
|
27
33
|
def to_s
|
28
34
|
"#{self.class.name}:#{@match}"
|
29
35
|
end
|
@@ -33,12 +39,15 @@ class Hiera
|
|
33
39
|
def initialize(non_match)
|
34
40
|
super(non_match)
|
35
41
|
end
|
36
|
-
|
42
|
+
|
43
|
+
def to_encrypted(_args = {})
|
37
44
|
@match
|
38
45
|
end
|
39
|
-
|
46
|
+
|
47
|
+
def to_decrypted(_args = {})
|
40
48
|
@match
|
41
49
|
end
|
50
|
+
|
42
51
|
def to_plain_text
|
43
52
|
@match
|
44
53
|
end
|
@@ -46,4 +55,4 @@ class Hiera
|
|
46
55
|
end
|
47
56
|
end
|
48
57
|
end
|
49
|
-
end
|
58
|
+
end
|