secure_conf 1.0.0 → 1.1.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/README.md +8 -2
- data/exe/secure_conf.rb +98 -0
- data/lib/secure_conf/config.rb +29 -9
- data/lib/secure_conf/storage/yaml.rb +0 -5
- data/lib/secure_conf/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e3c76b854e1a1f9928b858a30e35323dd7d149d
|
4
|
+
data.tar.gz: 565f358aeaf3fce3a0102a3f734861769824daaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
26
|
-
config["enc:
|
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
|
data/exe/secure_conf.rb
ADDED
@@ -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
|
data/lib/secure_conf/config.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
1
3
|
module SecureConf
|
2
|
-
class Config <
|
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
|
-
|
17
|
+
super(@storage.load(path))
|
16
18
|
end
|
17
19
|
|
18
|
-
|
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
|
-
|
30
|
-
value = @serializer.dump(value)
|
31
|
-
plain_store(key, @encripter.encrypt(value))
|
32
|
-
end
|
41
|
+
# get
|
33
42
|
|
34
|
-
|
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,
|
66
|
+
@storage.save(path, __getobj__)
|
47
67
|
end
|
48
68
|
end
|
49
69
|
end
|
data/lib/secure_conf/version.rb
CHANGED
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.
|
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:
|
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
|