lioooo_utils 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -0
- data/lib/lioooo_utils.rb +3 -3
- data/lib/sigcheck.rb +37 -0
- metadata +5 -4
- /data/lib/{logs/lioooo_log.rb → lioooo_log.rb} +0 -0
data/README.md
CHANGED
@@ -26,3 +26,20 @@ LiooooLogger = LiooooUtilsLogger.new :lioooo,'/tmp' #new instance with log paren
|
|
26
26
|
LiooooLogger.shell_exec! 'echo ok' # this will can shell `echo` command
|
27
27
|
|
28
28
|
```
|
29
|
+
|
30
|
+
#### you can check is runtime machine in lan
|
31
|
+
```
|
32
|
+
require 'lioooo_utils'
|
33
|
+
|
34
|
+
LiooooLogger.is_dev? # this will check runtime machine in lan return ***0*** or ***nil***
|
35
|
+
|
36
|
+
```
|
37
|
+
|
38
|
+
|
39
|
+
#### you can gen sig for some code like this
|
40
|
+
```
|
41
|
+
require 'lioooo_utils'
|
42
|
+
|
43
|
+
LiooooUtils::SigCheck.makeSig('get',"/api/user",{:name=>'lioooo'},"appkey"); #=> 9yX6wvZOdxorfjmQtlG8n7cX+zo
|
44
|
+
|
45
|
+
```
|
data/lib/lioooo_utils.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#encoding: utf-8
|
2
|
-
Root=File.expand_path('../../',__FILE__)
|
3
|
-
require "#{Root}/lib/
|
2
|
+
Root=File.expand_path('../../', __FILE__)
|
3
|
+
require "#{Root}/lib/lioooo_log"
|
4
4
|
require "#{Root}/lib/utils"
|
5
|
-
require "#{Root}/lib/
|
5
|
+
require "#{Root}/lib/sigcheck"
|
data/lib/sigcheck.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'cgi'
|
3
|
+
require 'digest/sha1'
|
4
|
+
require 'base64'
|
5
|
+
class LiooooUtils
|
6
|
+
module SigCheck
|
7
|
+
class << self
|
8
|
+
#生成URL签名
|
9
|
+
#@param string method 请求方法 "get" or "post"
|
10
|
+
#@param string url_path
|
11
|
+
#@param array params 表单参数
|
12
|
+
#@param string secret 密钥
|
13
|
+
def makeSig(method, url_path, params, secret)
|
14
|
+
mk = makeSource(method, url_path, params)
|
15
|
+
_secret = secret.tr('-_', '+/')
|
16
|
+
my_sign = Digest::HMAC.digest(mk, _secret, Digest::SHA1)
|
17
|
+
my_sign = Base64.encode64(my_sign).gsub("\n", "")
|
18
|
+
return my_sign
|
19
|
+
end
|
20
|
+
|
21
|
+
def makeSource(method, url_path, params)
|
22
|
+
_method = method.upcase
|
23
|
+
_url_path = CGI.escape(url_path)
|
24
|
+
_query_string = params.sort.collect { |v| v.join('=') }.join('&')
|
25
|
+
query_string = CGI.escape(_query_string)
|
26
|
+
_strs = "#{_method}&#{_url_path}&"
|
27
|
+
strs = _strs.gsub('~', '%7E')
|
28
|
+
_source_str = "#{strs}#{query_string}".gsub('+', '%20')
|
29
|
+
return _source_str
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
#puts LiooooUtils::SigCheck.makeSig('xxx',"/sddd",{},"sdfsdfs");
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lioooo_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colored
|
@@ -164,8 +164,9 @@ extra_rdoc_files:
|
|
164
164
|
- LICENSE.txt
|
165
165
|
- README.md
|
166
166
|
files:
|
167
|
+
- lib/lioooo_log.rb
|
167
168
|
- lib/lioooo_utils.rb
|
168
|
-
- lib/
|
169
|
+
- lib/sigcheck.rb
|
169
170
|
- lib/utils.rb
|
170
171
|
- lib/version.rb
|
171
172
|
- LICENSE.txt
|
@@ -187,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
187
188
|
version: '0'
|
188
189
|
segments:
|
189
190
|
- 0
|
190
|
-
hash:
|
191
|
+
hash: 465683426702398527
|
191
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
193
|
none: false
|
193
194
|
requirements:
|
File without changes
|