lorj 1.0.13 → 1.0.14

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: 2b033bdd31601389a91bf2772c3960307fdb7e2b
4
- data.tar.gz: 73451dacdb51d7c898d43f3f4752ed4dd340cfad
3
+ metadata.gz: 87a576b3dc28cb49cdd93e91746117af62bc1be4
4
+ data.tar.gz: cba9b715107fdb921c4f5f7f5d3400f6f32ead93
5
5
  SHA512:
6
- metadata.gz: c0807c1c536cf7bbccb7fc2fe224e7f136e29721bc3fe691339c3aad337f68ea6eeeef8728ce1b070cbe4483bf5e3d99f18361f6114ddd3e8831aa9db2a80c9a
7
- data.tar.gz: bd5b1c98d312503272591359658e86b3a9a3fd280a0ca6623bfc86398273351afe50d332a269fb75f55bbd19371cd97772f0c9dd3549122aa881bcc430a1c23b
6
+ metadata.gz: f0c80f5d67e1239406e106e9f3748258f75e6856e098352154f86b93a5bda9d1a09d01b97c249b9ebdc57e00474d9748cb5bb964300901936c4908c39b0085c4
7
+ data.tar.gz: d0b3371678052bcfc7febbcd7c2052e7815a1d72f37ae445cf1b42f11ea80434fc0fdd54a0c2629bc68ec305415a3a9fb4b607d9ac5ae89cfc0eb06d5d89319f
@@ -22,18 +22,67 @@ require 'lorj'
22
22
  # require 'ruby-debug'
23
23
  # Debugger.start
24
24
 
25
+ # Class to test encryted data.
26
+ class Test < Lorj::BaseDefinition
27
+ def initialize(core)
28
+ @core = core
29
+ end
30
+
31
+ def self.def_internal(name)
32
+ spec_name = 's' + name
33
+
34
+ # To call the function identified internally with 'spec' prefix
35
+ define_method(spec_name) do |*p|
36
+ send(name, *p)
37
+ end
38
+ end
39
+
40
+ # Internal function to test.
41
+ def_internal '_get_encrypt_key'
42
+ def_internal '_get_encrypted_value'
43
+
44
+ def run
45
+ puts 'Checking imported account...'
46
+ tests = [:account_key_test]
47
+ tests.each { |t| send(t) if self.class.private_method_defined?(t) }
48
+ end
49
+
50
+ private
51
+
52
+ def account_key_test
53
+ entr = _get_encrypt_key
54
+ data = @core.config['credentials#account_key']
55
+
56
+ res = _get_encrypted_value(data, entr, 'credentials#account_key')
57
+
58
+ test_state(!res.nil?, 'Account key', data)
59
+ end
60
+
61
+ def test_state(res, test, value)
62
+ test_str = "#{test}. (#{value})"
63
+ if res
64
+ puts "OK : #{test_str}"
65
+ else
66
+ puts "FAIL : #{test_str}"
67
+ end
68
+ end
69
+ end
70
+
71
+ # TODO: Implement Thor instead of ARGV use.
25
72
  if ARGV.length <= 3
26
73
  puts "Syntax is 'ruby #{__FILE__}' <LorjRef> <key> <CloudDataFile> "\
27
74
  "[<AccountName[@provider]>]\n"\
28
75
  "where:\n"\
29
76
  "LorjRef : Lorj application struture to use. \n"\
30
- " Format: <datapath>=<process>[@<libToLoad]\n"\
77
+ ' Format: <datapath[|<pdatapath>]>='\
78
+ "<process>[@<libToLoad]\n"\
31
79
  " datapath : Path where Lorj store data.\n"\
80
+ " pdatapath : Path where Lorj store private data.\n"\
32
81
  " process : Lorj process name to load. It can be a path to a\n"\
33
- ' process file.'\
82
+ " process file.\n"\
34
83
  " libToLoad : Optional. Ruby library containing The Lorj process.\n"\
35
84
  " If missing, it will try to load a lib named \n"\
36
- ' lorj_<process>'\
85
+ " lorj_<process>\n"\
37
86
  'key : Base64 encoded key. Used to decrypt the <CloudDataFi'\
38
87
  "le>\n"\
39
88
  "CloudDataFile : File containing the Lorj cloud data to import.\n"\
@@ -45,20 +94,23 @@ end
45
94
 
46
95
  ref, key_encoded, data_file, account = ARGV
47
96
 
48
- ref_found = ref.match(/^(.*)=(.*?)(@(.*))?$/)
97
+ ref_found = ref.match(/^(.*(\|(.*))?)=(.*?)(@(.*))?$/)
49
98
 
50
99
  unless ref_found
51
- puts 'LorjRef must be formatted as : <datapath>=<process>[@<libToLoad]'
100
+ puts 'LorjRef must be formatted as : <datapath[|<pdatapath>]>='\
101
+ '<process>[@<libToLoad]'
52
102
  exit 1
53
103
  end
54
104
 
55
105
  datapath = ref_found[1]
56
- process = ref_found[2]
106
+ pdatapath = datapath
107
+ pdatapath = ref_found[3] unless ref_found[3].nil?
108
+ process = ref_found[4]
57
109
 
58
- if ref_found[3].nil?
110
+ if ref_found[6].nil?
59
111
  lib_name = "lorj_#{process}"
60
112
  else
61
- lib_name = ref_found[4]
113
+ lib_name = ref_found[6]
62
114
  end
63
115
 
64
116
  unless File.exist?(data_file)
@@ -105,6 +157,7 @@ end
105
157
  name, controller = account.split('@') unless account.nil?
106
158
 
107
159
  PrcLib.data_path = datapath
160
+ PrcLib.pdata_path = pdatapath
108
161
 
109
162
  keypath = Lorj::KeyPath.new(process)
110
163
 
@@ -114,15 +167,16 @@ core = Lorj::Core.new(Lorj::Account.new, processes)
114
167
 
115
168
  data = File.read(data_file).strip
116
169
 
117
- # debugger # rubocop: disable Lint/Debugger
118
-
119
170
  core.account_import(entr, data, name, controller)
120
171
 
121
172
  puts 'Import done.'
122
173
 
123
- if core.config.ac_save
124
- puts "Config imported and saved in #{core.config['account#name']}"
125
- exit 0
174
+ unless core.config.ac_save
175
+ puts 'Issue during configuration saved.'
176
+ exit 1
126
177
  end
127
- puts 'Issue during configuration saved.'
128
- exit 1
178
+ puts "Config imported and saved in #{core.config['account#name']}"
179
+
180
+ Test.new(core).run
181
+
182
+ puts 'Import process done.'
data/lib/logging.rb CHANGED
@@ -82,8 +82,6 @@ module PrcLib
82
82
  # For details, see Logging functions
83
83
  #
84
84
  class Logging
85
- attr_reader :level
86
-
87
85
  # Initialize Logging instance
88
86
  # The log file name is defined by PrcLib.log_file
89
87
  # The log path is defined by PrcLib.app_name and will be kept as
@@ -96,7 +94,7 @@ module PrcLib
96
94
  file_logger_initialize
97
95
 
98
96
  @out_logger = Logger.new(STDOUT)
99
- @level = (PrcLib.level.nil? ? Logger::WARN : PrcLib.level)
97
+ @level = Logger::WARN
100
98
  @out_logger.level = @level
101
99
  @out_logger.formatter = proc do |severity, _datetime, _progname, msg|
102
100
  case severity
@@ -169,6 +167,8 @@ module PrcLib
169
167
  @out_logger.level = level
170
168
  end
171
169
 
170
+ attr_reader :level
171
+
172
172
  # Print out a message, not logged in the log file. This message is printed
173
173
  # out systematically as not taking care of logger level.
174
174
  def unknown(message)
@@ -267,6 +267,10 @@ module PrcLib
267
267
  nil
268
268
  end
269
269
 
270
+ def level
271
+ log_object.level
272
+ end
273
+
270
274
  # Print the message to the same line.
271
275
  def state(message, *p)
272
276
  print(format("%s%s ...\r", ANSI.clear_line,
data/lib/lorj/compat.rb CHANGED
@@ -86,7 +86,7 @@ module Base64
86
86
  # This method complies with RFC 4648.
87
87
  # No line feeds are added.
88
88
  def strict_encode64(bin)
89
- [bin].pack('m0')
89
+ [bin].pack('m0').strip
90
90
  end
91
91
 
92
92
  # Returns the Base64-decoded version of +str+.
data/lib/lorj/version.rb CHANGED
@@ -16,6 +16,6 @@
16
16
 
17
17
  # Lorj version
18
18
  module Lorj
19
- VERSION = '1.0.13'
20
- DATE = '2015-06-22'
19
+ VERSION = '1.0.14'
20
+ DATE = '2015-06-24'
21
21
  end
data/lib/lorj_account.rb CHANGED
@@ -386,6 +386,8 @@ module Lorj
386
386
  # * *Raises* :
387
387
  # Nothing
388
388
  def set(key, value, options = {})
389
+ options[:name] = 'runtime' unless options.key?(:name)
390
+
389
391
  parameters = validate_key_and_options(key, options)
390
392
  return nil if parameters.nil?
391
393
 
@@ -74,8 +74,12 @@ describe 'Module: Lorj,' do
74
74
  expect(PrcLib.log_file).to eq(log)
75
75
  end
76
76
 
77
- it 'create PrcLib.log object at first message' do
77
+ it 'set logger level' do
78
78
  PrcLib.level = Logger::FATAL
79
+ expect(PrcLib.level).to equal(Logger::FATAL)
80
+ end
81
+
82
+ it 'create PrcLib.log object at first message' do
79
83
  PrcLib.app_name = 'lorj-spec'
80
84
  PrcLib.app_defaults = File.join(File.dirname(app_path), 'lorj-spec')
81
85
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lorj
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.13
4
+ version: 1.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - forj team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-22 00:00:00.000000000 Z
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler