dinomischus 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c817f8c29b1b2fc3db6af10567c63b806ccaf7974fb6119364b2d76a8ef0ad1e
4
- data.tar.gz: 6ee738a175fe7a9ab23bafa356c7c989468daec3dcf9d1d1b4ec7de525acd0c1
3
+ metadata.gz: 9be59068e706c1dbc49c6f9571fd3f9213caeab3b36794a48aac55ee72a9c721
4
+ data.tar.gz: 935a13f4059df89faed1d9d7391fb9564a083dd7f78f91133bc1d2108c66ebfa
5
5
  SHA512:
6
- metadata.gz: 73e65a9ec46a854ae953f84b671c35f1e2766852057c435cf008d8f6771e32818120148d7b64f79b891a2f66c217e7ae2671e4270130dcf9377dfe8bf726b58a
7
- data.tar.gz: 88b1974e147c1becc5d2142d4ef878f0efd711d33454b9e633b6c9b984f4e665b599db69a58708cd5eb87fd2f1e424529cac082d7ad2153730e07984d2ba6612
6
+ metadata.gz: e91250f997fae463e4a6d2ed1c340258d30645d692c509339949b5d90b43cbf398adf072e65246096d210f3b5b23923ab77f2d7fa2e0dc8df27c1b7ea266a1a2
7
+ data.tar.gz: 9d06db65c79a773f5d6719710e172596c4ba2769d3d7a3d3858153165fe5ece37870df77cc71ffa52d3dd2e994816e8ac4a5d6e07b015a5b745b593d765c3201
data/README.md CHANGED
@@ -109,6 +109,20 @@ hash = Dinomischus.load_file('project_name_config_index.yml')
109
109
  ```
110
110
  The setting value of ```:fruit``` changed to ```banana``` depending on the file read later.
111
111
 
112
+ ### For Reading by the CLI
113
+
114
+ get 1 value
115
+
116
+ ```
117
+ bash$ dinomischus -g -f [FileName] -k [key]
118
+ ```
119
+
120
+ get key-value list
121
+
122
+ ```
123
+ bash$ dinomischus -l -f [FileName]
124
+ ```
125
+
112
126
  ### For Write Setting
113
127
 
114
128
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'dinomischus'
3
+ require_relative '../lib/dinomischus'
4
4
  require 'optparse'
5
5
  Version = Dinomischus::VERSION
6
6
 
@@ -21,11 +21,11 @@ class Command
21
21
  @options.include?(name)
22
22
  end
23
23
 
24
- # 指定したオプションを全て指定いるか?
24
+ # 指定したオプションを全て指定しているか?
25
25
  def has_all?(*names)
26
26
  all_finded = true
27
27
  names.each do |nm|
28
- finded = @options.include?(@option.get(nm))
28
+ finded = @options.include?(nm)
29
29
  $stderr.puts("This Command needs '#{nm}' option. ") unless finded
30
30
  all_finded &&= finded
31
31
  end
@@ -44,6 +44,16 @@ class Command
44
44
  def self.CmdList( path )
45
45
  Dinomischus.load_file( path )
46
46
  end
47
+
48
+ def self.PrintHash( hash )
49
+ # pp "#{value}"
50
+ max_length = hash.keys.max_by(&:length).length
51
+ print "{\n"
52
+ hash.each do |k, v|
53
+ print sprintf(" %<key>-#{max_length}s : %<value>s \n", {key:k, value:v})
54
+ end
55
+ print "}\n"
56
+ end
47
57
  end
48
58
 
49
59
  # メニュー振り分け処理と引数チェック
@@ -59,7 +69,7 @@ case true
59
69
  when cmd.has?(:list) then
60
70
  return unless cmd.has_all?(:file)
61
71
  value = Command.CmdList( cmd.get(:file) )
62
- pp "#{value}"
72
+ Command.PrintHash(value)
63
73
 
64
74
  # CUI メニュー表示
65
75
  when cmd.has?(:menu) then
@@ -1,13 +1,11 @@
1
1
  require 'yaml'
2
2
 
3
- require File.expand_path("../dinomischus/version", __FILE__)
4
-
5
- require File.expand_path("../dinomischus/crypt_aes.rb", __FILE__)
6
- require File.expand_path("../dinomischus/merge_yaml.rb", __FILE__)
7
- require File.expand_path("../dinomischus/l_key.rb", __FILE__)
8
- require File.expand_path("../dinomischus/l_def.rb", __FILE__)
9
- require File.expand_path("../dinomischus/l_conf.rb", __FILE__)
10
- require File.expand_path("../dinomischus/menu.rb", __FILE__)
3
+ require_relative "./dinomischus/version"
4
+ require_relative "./dinomischus/utils/merge_yaml.rb"
5
+ require_relative "./dinomischus/l_key.rb"
6
+ require_relative "./dinomischus/l_def.rb"
7
+ require_relative "./dinomischus/l_conf.rb"
8
+ require_relative "./dinomischus/menu.rb"
11
9
 
12
10
 
13
11
  module Dinomischus
@@ -40,13 +38,24 @@ module Dinomischus
40
38
  def self.load_file( path, specify = false )
41
39
  # get loading target
42
40
  yml = YAML.load_file(path)
43
- files = yml[0].has_key?(:conf_path) ? yml : [ {conf_path: path} ]
41
+ # files = yml[0].has_key?(:conf_path) ? yml : [ {conf_path: path} ]
42
+ # base_dir = yml[0].has_key?
43
+ files = []
44
+ base_dir = ""
45
+ if yml[0].has_key?(:conf_path) then
46
+ files = yml
47
+ base_dir = File.dirname(path)
48
+ else
49
+ files = [ {conf_path: path} ]
50
+ base_dir = Dir.pwd
51
+ end
44
52
 
45
53
  # loading config files...
46
54
  config_list = {}
47
55
  files.each do |p|
48
56
  items = {}
49
- items = load_conf(p[:conf_path], specify)
57
+ conf_path = File.expand_path(p[:conf_path], base_dir )
58
+ items = load_conf(conf_path, specify)
50
59
  merge_yaml(config_list, items)
51
60
  end
52
61
  config_list
@@ -4,7 +4,7 @@ require 'optparse'
4
4
  require 'securerandom'
5
5
  require 'base64'
6
6
 
7
- require File.expand_path('../crypt_aes.rb', __FILE__)
7
+ require_relative './utils/crypt_dino.rb'
8
8
 
9
9
  module Dinomischus
10
10
 
@@ -32,7 +32,8 @@ module Dinomischus
32
32
  key_path = yml[0][:key_path]
33
33
  raise RuntimeError.new("鍵ファイルが存在しません。#{key_path}") if !File.exist?(key_path)
34
34
 
35
- val_text = do_encrypt ? "?#{exec_encrypt( key_path, value)}" : value
35
+ #val_text = do_encrypt ? "?#{exec_encrypt( key_path, value)}" : value
36
+ val_text = do_encrypt ? "?#{Dinomischus::dino_encrypt( key_path, value)}" : value
36
37
 
37
38
  yml[1][key.to_sym] = {"value": val_text, "desc": desc}
38
39
  File.open(conf_path, 'w') do |f|
@@ -46,7 +47,8 @@ module Dinomischus
46
47
  raise RuntimeError.new("設定ファイルが存在しません。#{conf_path}") if !File.exist?(conf_path)
47
48
 
48
49
  conf_file = YAML.load_file(conf_path)
49
- key_path = conf_file[0][:key_path]
50
+ key_path = sprintf("%s", conf_file[0][:key_path] )
51
+ key_path = File.expand_path(key_path, File.dirname(conf_path))
50
52
  raw_items = conf_file[1]
51
53
  items = {}
52
54
  raw_items.keys.each do |key|
@@ -70,7 +72,8 @@ module Dinomischus
70
72
  if value.match /^\?.*/
71
73
  ret.gsub!("\n","")
72
74
  ret = ret[/\?(.*)/, 1]
73
- ret = exec_decrypt(key_path, ret)
75
+ #ret = exec_decrypt(key_path, ret)
76
+ ret = Dinomischus::dino_decrypt(key_path, ret)
74
77
  else
75
78
  ret = value
76
79
  end
@@ -4,8 +4,7 @@ require 'optparse'
4
4
  require 'securerandom'
5
5
  require 'base64'
6
6
 
7
- require File.expand_path('../crypt_aes.rb', __FILE__)
8
- require File.expand_path('../l_conf.rb', __FILE__)
7
+ require_relative './l_conf.rb'
9
8
 
10
9
  module Dinomischus
11
10
  attr_reader :items
@@ -31,7 +30,8 @@ module Dinomischus
31
30
  files = load_file(def_path)
32
31
  configs = {}
33
32
  files.each do |f|
34
- cfg = Dinomischus::ConfFile.load_file(f[:conf_path])
33
+ conf_path = File.expand_path(f[:conf_path], def_path)
34
+ cfg = Dinomischus::ConfFile.load_file(conf_path)
35
35
  configs.merge!(cfg)
36
36
  end
37
37
  configs
@@ -4,8 +4,6 @@ require 'optparse'
4
4
  require 'securerandom'
5
5
  require 'base64'
6
6
 
7
- require File.expand_path('../crypt_aes.rb', __FILE__)
8
-
9
7
  module Dinomischus
10
8
  class KeyFile
11
9
 
@@ -0,0 +1,37 @@
1
+ require 'base64'
2
+ require 'securerandom'
3
+ require_relative './crypt_aes.rb'
4
+
5
+ module Dinomischus
6
+ def self.dino_encrypt(key_path, value)
7
+ raise RuntimeError.new("鍵ファイルが存在しません。#{key_path}") if !File.exist?(key_path)
8
+
9
+ keys = YAML.load_file(key_path)
10
+ enctype = keys[:key][:type]
11
+ if enctype == "sha256"
12
+ # sha256の処理。
13
+ pass = keys[:key][:value]
14
+ enc1 = Crypter::CryptAes.encrypt( value, pass, true )
15
+ enc2 = Crypter::CryptAes.encrypt( enc1.to_s, pass, false )
16
+ else
17
+ raise RuntimeError.new("未サポートの暗号です。#{enctype}")
18
+ end
19
+ enc2[0]
20
+ end
21
+
22
+ def self.dino_decrypt(key_path, value)
23
+ raise RuntimeError.new("鍵ファイルが存在しません。#{key_path}") if !File.exist?(key_path)
24
+
25
+ keys = YAML.load_file(key_path)
26
+ enctype = keys[:key][:type]
27
+ if enctype == "sha256"
28
+ pass = keys[:key][:value]
29
+ v2 = Crypter::CryptAes.decrypt( value, pass )
30
+ v1raw = YAML.load(v2)
31
+ v1 = Crypter::CryptAes.decrypt( v1raw[0], pass, v1raw[1])
32
+ else
33
+ raise RuntimeError.new("未サポートの暗号です。#{enctype}")
34
+ end
35
+ end
36
+ end
37
+
@@ -1,3 +1,3 @@
1
1
  module Dinomischus
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dinomischus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kuroko Sin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-08 00:00:00.000000000 Z
11
+ date: 2020-11-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -30,12 +30,13 @@ files:
30
30
  - dinomischus.gemspec
31
31
  - exe/dinomischus
32
32
  - lib/dinomischus.rb
33
- - lib/dinomischus/crypt_aes.rb
34
33
  - lib/dinomischus/l_conf.rb
35
34
  - lib/dinomischus/l_def.rb
36
35
  - lib/dinomischus/l_key.rb
37
36
  - lib/dinomischus/menu.rb
38
- - lib/dinomischus/merge_yaml.rb
37
+ - lib/dinomischus/utils/crypt_aes.rb
38
+ - lib/dinomischus/utils/crypt_dino.rb
39
+ - lib/dinomischus/utils/merge_yaml.rb
39
40
  - lib/dinomischus/version.rb
40
41
  homepage: https://github.com/kurokoSin/Dinomischus
41
42
  licenses: