kafo 0.2.2 → 0.3.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.

Potentially problematic release.


This version of kafo might be problematic. Click here for more details.

@@ -1,20 +1,22 @@
1
- module Params
2
- class Boolean < Param
3
- def value=(value)
4
- super
5
- @value = typecast(@value)
6
- end
1
+ module Kafo
2
+ module Params
3
+ class Boolean < Param
4
+ def value=(value)
5
+ super
6
+ @value = typecast(@value)
7
+ end
7
8
 
8
- private
9
+ private
9
10
 
10
- def typecast(value)
11
- case value
12
- when '0', 'false', 'f', false
13
- false
14
- when '1', 'true', 't', true
15
- true
16
- else
17
- value
11
+ def typecast(value)
12
+ case value
13
+ when '0', 'false', 'f', false
14
+ false
15
+ when '1', 'true', 't', true
16
+ true
17
+ else
18
+ value
19
+ end
18
20
  end
19
21
  end
20
22
  end
@@ -1,14 +1,16 @@
1
- module Params
2
- class Integer < Param
3
- def value=(value)
4
- super
5
- @value = typecast(@value)
6
- end
1
+ module Kafo
2
+ module Params
3
+ class Integer < Param
4
+ def value=(value)
5
+ super
6
+ @value = typecast(@value)
7
+ end
7
8
 
8
- private
9
+ private
9
10
 
10
- def typecast(value)
11
- value.nil? ? nil : value.to_i
11
+ def typecast(value)
12
+ value.nil? ? nil : value.to_i
13
+ end
12
14
  end
13
15
  end
14
16
  end
@@ -1,49 +1,55 @@
1
- module Params
2
- # A password paramater is stored encrypted in answer file using AES 256 in CBC mode
3
- #
4
- # we use a passphrase that is stored in kafo.yaml for encryption
5
- # encrypted password is prefixed with $1$ (for historical reasons, no connection to
6
- # Modular Crypt Format)
7
- class Password < Param
8
- def value=(value)
9
- super
10
- if @value.nil? || @value.empty?
11
- @value = password_manager.password
12
- end
13
- setup_password if @value.is_a?(::String)
14
- @value
15
- end
1
+ module Kafo
2
+ module Params
3
+ # A password paramater is stored encrypted in answer file using AES 256 in CBC mode
4
+ #
5
+ # we use a passphrase that is stored in kafo.yaml for encryption
6
+ # encrypted password is prefixed with $1$ (for historical reasons, no connection to
7
+ # Modular Crypt Format)
8
+ class Password < Param
9
+ def value=(value)
10
+ super
11
+ if @value.nil? || @value.empty?
12
+ @value = password_manager.password
13
+ end
14
+ setup_password if @value.is_a?(::String)
15
+ @value
16
+ end
16
17
 
17
- def value
18
- @encrypted
19
- end
18
+ def value
19
+ @encrypted
20
+ end
20
21
 
21
- private
22
+ def condition_value
23
+ "\"#{value}\""
24
+ end
22
25
 
23
- def setup_password
24
- encrypted? ? decrypt : encrypt
25
- end
26
+ private
26
27
 
27
- def encrypted?
28
- @value.length > 3 && @value[0..2] == '$1$'
29
- end
28
+ def setup_password
29
+ encrypted? ? decrypt : encrypt
30
+ end
30
31
 
31
- def decrypt
32
- @encrypted = @value
33
- @value = password_manager.aes_decrypt(@value[3..-1], phrase)
34
- end
32
+ def encrypted?
33
+ @value.length > 3 && @value[0..2] == '$1$'
34
+ end
35
35
 
36
- def encrypt
37
- @encrypted = '$1$' + password_manager.aes_encrypt(@value, phrase)
38
- end
36
+ def decrypt
37
+ @encrypted = @value
38
+ @value = password_manager.aes_decrypt(@value[3..-1], phrase)
39
+ end
39
40
 
40
- def password_manager
41
- @password_manager ||= PasswordManager.new
42
- end
41
+ def encrypt
42
+ @encrypted = '$1$' + password_manager.aes_encrypt(@value, phrase)
43
+ end
43
44
 
44
- def phrase
45
- KafoConfigure.config.app[:password]
46
- end
45
+ def password_manager
46
+ @password_manager ||= PasswordManager.new
47
+ end
48
+
49
+ def phrase
50
+ KafoConfigure.config.app[:password]
51
+ end
47
52
 
53
+ end
48
54
  end
49
55
  end
@@ -1,3 +1,9 @@
1
- module Params
2
- class String < Param; end
1
+ module Kafo
2
+ module Params
3
+ class String < Param
4
+ def condition_value
5
+ %{"#{value}"}
6
+ end
7
+ end
8
+ end
3
9
  end
@@ -4,42 +4,44 @@ require 'digest/sha2'
4
4
  require 'openssl'
5
5
  require 'base64'
6
6
 
7
- class PasswordManager
8
- # generate a random password of lenght n
9
- #
10
- # on ruby >= 1.9 we use builtin method urlsafe_base64, on olders we use our own
11
- # implementation (inspired by urlsafe_base64)
12
- #
13
- # the result may contain A-Z, a-z, 0-9, “-” and “_”. “=”
14
- def password(n = 32)
15
- return SecureRandom.urlsafe_base64(n) if SecureRandom.respond_to?(:urlsafe_base64)
7
+ module Kafo
8
+ class PasswordManager
9
+ # generate a random password of lenght n
10
+ #
11
+ # on ruby >= 1.9 we use builtin method urlsafe_base64, on olders we use our own
12
+ # implementation (inspired by urlsafe_base64)
13
+ #
14
+ # the result may contain A-Z, a-z, 0-9, “-” and “_”. “=”
15
+ def password(n = 32)
16
+ return SecureRandom.urlsafe_base64(n) if SecureRandom.respond_to?(:urlsafe_base64)
16
17
 
17
- s = [SecureRandom.random_bytes(n)].pack("m*")
18
- s.delete!("\n")
19
- s.tr!("+/", "-_")
20
- s.delete!("=")
21
- s
22
- end
18
+ s = [SecureRandom.random_bytes(n)].pack("m*")
19
+ s.delete!("\n")
20
+ s.tr!("+/", "-_")
21
+ s.delete!("=")
22
+ s
23
+ end
23
24
 
24
- def aes_encrypt(text, passphrase)
25
- cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
26
- cipher.encrypt
27
- cipher.key = Digest::SHA2.hexdigest(passphrase)
28
- cipher.iv = Digest::SHA2.hexdigest(passphrase + passphrase)
25
+ def aes_encrypt(text, passphrase)
26
+ cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
27
+ cipher.encrypt
28
+ cipher.key = Digest::SHA2.hexdigest(passphrase)
29
+ cipher.iv = Digest::SHA2.hexdigest(passphrase + passphrase)
29
30
 
30
- encrypted = cipher.update(text)
31
- encrypted << cipher.final
32
- Base64.encode64(encrypted)
33
- end
31
+ encrypted = cipher.update(text)
32
+ encrypted << cipher.final
33
+ Base64.encode64(encrypted)
34
+ end
34
35
 
35
- def aes_decrypt(text, passphrase)
36
- cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
37
- cipher.decrypt
38
- cipher.key = Digest::SHA2.hexdigest(passphrase)
39
- cipher.iv = Digest::SHA2.hexdigest(passphrase + passphrase)
36
+ def aes_decrypt(text, passphrase)
37
+ cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
38
+ cipher.decrypt
39
+ cipher.key = Digest::SHA2.hexdigest(passphrase)
40
+ cipher.iv = Digest::SHA2.hexdigest(passphrase + passphrase)
40
41
 
41
- decrypted = cipher.update(Base64.decode64(text))
42
- decrypted << cipher.final
43
- decrypted
42
+ decrypted = cipher.update(Base64.decode64(text))
43
+ decrypted << cipher.final
44
+ decrypted
45
+ end
44
46
  end
45
47
  end
@@ -1,71 +1,74 @@
1
+ # encoding: UTF-8
1
2
  require 'powerbar'
2
3
  require 'ansi/code'
3
4
 
5
+ module Kafo
4
6
  # Progress bar base class
5
7
  #
6
8
  # To define new progress bar you can inherit from this class and implement
7
9
  # #finite_template and #infinite_template methods. Also you may find useful to
8
10
  # change more methods like #done_message or #print_error
9
- class ProgressBar
10
- def initialize
11
- @lines = 0
12
- @all_lines = 0
13
- @total = :unknown
14
- @bar = PowerBar.new
15
- @bar.settings.tty.infinite.template.main = infinite_template
16
- @bar.settings.tty.finite.template.main = finite_template
17
- @bar.settings.tty.finite.template.padchar = ' '
18
- @bar.settings.tty.finite.template.barchar = '.'
19
- @bar.settings.tty.finite.output = Proc.new { |s| $stderr.print s }
20
- end
11
+ class ProgressBar
12
+ def initialize
13
+ @lines = 0
14
+ @all_lines = 0
15
+ @total = :unknown
16
+ @bar = PowerBar.new
17
+ @bar.settings.tty.infinite.template.main = infinite_template
18
+ @bar.settings.tty.finite.template.main = finite_template
19
+ @bar.settings.tty.finite.template.padchar = ' '
20
+ @bar.settings.tty.finite.template.barchar = '.'
21
+ @bar.settings.tty.finite.output = Proc.new { |s| $stderr.print s }
22
+ end
21
23
 
22
- def update(line)
23
- @total = $1.to_i if line =~ /\w*START (\d+)/
24
- @lines += 1 if line.include?('RESOURCE') && @lines < @total - 1
25
- @all_lines += 1
24
+ def update(line)
25
+ @total = $1.to_i if line =~ /\w*START (\d+)/
26
+ @lines += 1 if line.include?('RESOURCE') && @lines < @total - 1
27
+ @all_lines += 1
26
28
 
27
- # we print every 20th line during installation preparing otherwise we update every line
28
- if @all_lines % 20 == 0 || @total != :unknown
29
- @bar.show({ :msg => format(line),
30
- :done => @lines,
31
- :total => @total })
29
+ # we print every 20th line during installation preparing otherwise we update every line
30
+ if @all_lines % 20 == 0 || @total != :unknown
31
+ @bar.show({ :msg => format(line),
32
+ :done => @lines,
33
+ :total => @total })
34
+ end
32
35
  end
33
- end
34
36
 
35
- def close
36
- @bar.show({ :msg => done_message,
37
- :done => @total == :unknown ? @bar.done + 1 : @total,
38
- :total => @total }, true)
39
- @bar.close
40
- end
37
+ def close
38
+ @bar.show({ :msg => done_message,
39
+ :done => @total == :unknown ? @bar.done + 1 : @total,
40
+ :total => @total }, true)
41
+ @bar.close
42
+ end
41
43
 
42
- def print(line)
43
- @bar.print line
44
- end
44
+ def print(line)
45
+ @bar.print line
46
+ end
45
47
 
46
- def print_error(line)
47
- print line
48
- end
48
+ def print_error(line)
49
+ print line
50
+ end
49
51
 
50
- private
52
+ private
51
53
 
52
- def done_message
53
- text = 'Done'
54
- text + (' ' * (50 - text.length))
55
- end
54
+ def done_message
55
+ text = 'Done'
56
+ text + (' ' * (50 - text.length))
57
+ end
56
58
 
57
- def format(line)
58
- (line.tr("\r\n", '') + (' ' * 50))[0..49]
59
- end
59
+ def format(line)
60
+ (line.tr("\r\n", '') + (' ' * 50))[0..49]
61
+ end
60
62
 
61
- def finite_template
62
- 'Installing... [${<percent>%}]'
63
- end
63
+ def finite_template
64
+ 'Installing... [${<percent>%}]'
65
+ end
64
66
 
65
- def infinite_template
66
- 'Installing...'
67
- end
67
+ def infinite_template
68
+ 'Installing...'
69
+ end
68
70
 
71
+ end
69
72
  end
70
73
 
71
74
  require 'kafo/progress_bars/colored'
@@ -1,15 +1,17 @@
1
- module ProgressBars
2
- class BlackWhite < ProgressBar
1
+ module Kafo
2
+ module ProgressBars
3
+ class BlackWhite < ProgressBar
3
4
 
4
- private
5
+ private
5
6
 
6
- def finite_template
7
- 'Installing'.ljust(22) + ' ${<msg>} [${<percent>%}] [${<bar>}]'
8
- end
7
+ def finite_template
8
+ 'Installing'.ljust(22) + ' ${<msg>} [${<percent>%}] [${<bar>}]'
9
+ end
9
10
 
10
- def infinite_template
11
- 'Preparing installation ${<msg>}'
12
- end
11
+ def infinite_template
12
+ 'Preparing installation ${<msg>}'
13
+ end
13
14
 
15
+ end
14
16
  end
15
17
  end
@@ -1,26 +1,28 @@
1
- module ProgressBars
2
- class Colored < ProgressBar
1
+ module Kafo
2
+ module ProgressBars
3
+ class Colored < ProgressBar
3
4
 
4
- def print_error(line)
5
- print ANSI::Code.red { line }
6
- end
5
+ def print_error(line)
6
+ print ANSI::Code.red { line }
7
+ end
7
8
 
8
- private
9
+ private
9
10
 
10
- def done_message
11
- ANSI::Code.green { super }
12
- end
11
+ def done_message
12
+ ANSI::Code.green { super }
13
+ end
13
14
 
14
- def finite_template
15
- 'Installing'.ljust(22) +
16
- ANSI::Code.yellow { ' ${<msg>}' } +
17
- ANSI::Code.green { ' [${<percent>%}]' } +
18
- ' [${<bar>}]'
19
- end
15
+ def finite_template
16
+ 'Installing'.ljust(22) +
17
+ ANSI::Code.yellow { ' ${<msg>}' } +
18
+ ANSI::Code.green { ' [${<percent>%}]' } +
19
+ ' [${<bar>}]'
20
+ end
20
21
 
21
- def infinite_template
22
- 'Preparing installation' + ANSI::Code.yellow { ' ${<msg>}' }
23
- end
22
+ def infinite_template
23
+ 'Preparing installation' + ANSI::Code.yellow { ' ${<msg>}' }
24
+ end
24
25
 
26
+ end
25
27
  end
26
28
  end