secure_conf 1.0.0 → 1.1.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: 5577c49a1bbfcc5e15217e66b508445823bea95e
4
- data.tar.gz: 47d482b939a3c124cd7e5112af2c6611a7a13eb2
3
+ metadata.gz: 2e3c76b854e1a1f9928b858a30e35323dd7d149d
4
+ data.tar.gz: 565f358aeaf3fce3a0102a3f734861769824daaa
5
5
  SHA512:
6
- metadata.gz: 4a3b111bf1d3ca46607d03d76d2324238cbe25bd1c087a58d35d2b827d188ee7f5bbd00f1f5fcc0a95a1fbfcc58f41260c974b395b2f380a6f47586d9432e0b7
7
- data.tar.gz: 3aab96dbf9603ecfedc503df1cce653e01d827ca4b470df05a53045e8999a8fdf7a0a98fdfb4498ba36041808dd7bb7cfcd3fecf27310a988c468fa6dea12bd3
6
+ metadata.gz: 6633e4d0d35351ef51838d2c4cc6bd31c25ce94c2ddb29c53c87a21125f22b1598c9271b50c50b60e1e73e9bc27daceb0d930497b49d7fe6dd352afaa316c105
7
+ data.tar.gz: c724cd2b2dc2416914b46871667386c042b0f5f23e9af7c4395d6f80ccdd91f771c61b6277240169189323e79670f1aa821bc3b4b81a63de29105b67bdd14a0b
data/README.md CHANGED
@@ -22,9 +22,15 @@ Or install it yourself as:
22
22
 
23
23
  path = File.expand_path("config.yml", File.dirname(__FILE__))
24
24
  config = SecureConf::Config.new(path)
25
- p config["enc:aaa"]
26
- config["enc:aaa"] = "aaa"
25
+
26
+ config["enc:id"] = "yoshida-eth0"
27
+ config["enc:pass"] = "himitsu"
28
+ config["last_access"] = Time.now.to_s
27
29
  config.save
30
+
31
+ p config["enc:id"]
32
+ p config["enc:pass"]
33
+ p config["last_access"]
28
34
 
29
35
 
30
36
  ## Development
@@ -0,0 +1,98 @@
1
+ #!/bin/ruby
2
+
3
+ $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
4
+
5
+ require 'secure_conf'
6
+
7
+ method = (ARGV[0]||"").to_sym
8
+ path = ARGV[1]
9
+ key = ARGV[2]
10
+ value = ARGV[3]
11
+
12
+ class SecureConfCmd
13
+
14
+ def initialize(path)
15
+ @path = path
16
+ end
17
+
18
+ def config
19
+ unless @config
20
+ unless @path
21
+ raise "path is required."
22
+ end
23
+ #unless File.file?(@path)
24
+ # raise "path is not found."
25
+ #end
26
+
27
+ @config = SecureConf::Config.new(@path, auto_commit: true)
28
+ end
29
+ @config
30
+ end
31
+
32
+ def read(key)
33
+ raise "key is required." unless key
34
+
35
+ val = config[key]
36
+
37
+ puts "read"
38
+ puts " key: #{key}"
39
+ puts " val: #{val}"
40
+ end
41
+
42
+ def write(key, value)
43
+ raise "key is required." unless key
44
+ raise "value is required." unless value
45
+
46
+ puts "write"
47
+ puts " key: #{key}"
48
+ puts " val: #{value}"
49
+ config[key] = value
50
+ puts "write ok."
51
+ end
52
+
53
+ def delete(key)
54
+ raise "key is required." unless key
55
+
56
+ puts "delete"
57
+ puts " key: #{key}"
58
+ config.delete(key)
59
+ puts "delete ok."
60
+ end
61
+
62
+ def usage
63
+ lines = []
64
+ lines << "Usage:"
65
+ lines << " #{File.basename($0)} method path [key [value]]"
66
+ lines << ""
67
+ lines << " method:"
68
+ lines << " read write delete"
69
+ lines << ""
70
+ lines << " required args"
71
+ lines << " read : path key"
72
+ lines << " write : path key value"
73
+ lines << " delete: path key"
74
+ lines.join("\n")
75
+ end
76
+ end
77
+
78
+
79
+ cmd = SecureConfCmd.new(path)
80
+
81
+ begin
82
+ case method
83
+ when :read
84
+ cmd.read(key)
85
+ when :write
86
+ cmd.write(key, value)
87
+ when :delete
88
+ cmd.delete(key)
89
+ else
90
+ puts cmd.usage
91
+ end
92
+ rescue => e
93
+ puts e
94
+ puts
95
+ puts cmd.usage
96
+
97
+ #puts e.backtrace.join("\n")
98
+ end
@@ -1,5 +1,7 @@
1
+ require 'delegate'
2
+
1
3
  module SecureConf
2
- class Config < Hash
4
+ class Config < SimpleDelegator
3
5
  attr_reader :path
4
6
  attr_reader :encripter
5
7
  attr_reader :serializer
@@ -12,10 +14,20 @@ module SecureConf
12
14
  @serializer = serializer || Serializer::Marshal
13
15
  @storage = storage || Storage.fetch(path)
14
16
  @auto_commit = auto_commit
15
- self.replace(@storage.load(path))
17
+ super(@storage.load(path))
16
18
  end
17
19
 
18
- alias_method :plain_store, :store
20
+ # store
21
+
22
+ def plain_store(key, value)
23
+ __getobj__.store(key, value)
24
+ save if @auto_commit
25
+ end
26
+
27
+ def secure_store(key, value)
28
+ value = @serializer.dump(value)
29
+ plain_store(key, @encripter.encrypt(value))
30
+ end
19
31
 
20
32
  def store(key, value)
21
33
  if key.to_s.start_with?("enc:")
@@ -26,12 +38,11 @@ module SecureConf
26
38
  end
27
39
  alias_method :[]=, :store
28
40
 
29
- def secure_store(key, value)
30
- value = @serializer.dump(value)
31
- plain_store(key, @encripter.encrypt(value))
32
- end
41
+ # get
33
42
 
34
- alias_method :plain_get, :[]
43
+ def plain_get(key)
44
+ __getobj__[key]
45
+ end
35
46
 
36
47
  def [](key)
37
48
  value = plain_get(key)
@@ -42,8 +53,17 @@ module SecureConf
42
53
  value
43
54
  end
44
55
 
56
+ # delete
57
+
58
+ def delete(key)
59
+ __getobj__.delete(key)
60
+ save if @auto_commit
61
+ end
62
+
63
+ # save
64
+
45
65
  def save
46
- @storage.save(path, self)
66
+ @storage.save(path, __getobj__)
47
67
  end
48
68
  end
49
69
  end
@@ -2,11 +2,6 @@ require "yaml"
2
2
 
3
3
  module SecureConf
4
4
  module Storage
5
- def self.fetch(path)
6
- ext = File.extname(path).sub(".", "").capitalize
7
- const_get(ext)
8
- end
9
-
10
5
  module Yaml
11
6
  def self.load(path)
12
7
  if File.file?(path)
@@ -1,3 +1,3 @@
1
1
  module SecureConf
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secure_conf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshida
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-05 00:00:00.000000000 Z
11
+ date: 2017-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -55,7 +55,8 @@ dependencies:
55
55
  description: To encrypt the configuration value.
56
56
  email:
57
57
  - yoshida.eth0@gmail.com
58
- executables: []
58
+ executables:
59
+ - secure_conf.rb
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
@@ -68,6 +69,7 @@ files:
68
69
  - Rakefile
69
70
  - bin/console
70
71
  - bin/setup
72
+ - exe/secure_conf.rb
71
73
  - lib/secure_conf.rb
72
74
  - lib/secure_conf/config.rb
73
75
  - lib/secure_conf/core_ext.rb