idcf-faraday_middleware 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -0
- data/README.md +2 -11
- data/idcf-faraday_middleware.gemspec +1 -1
- data/lib/idcf/faraday_middleware.rb +1 -0
- data/lib/idcf/faraday_middleware/computing_signature.rb +40 -15
- data/lib/idcf/faraday_middleware/configuration.rb +6 -0
- data/lib/idcf/faraday_middleware/version.rb +1 -1
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b42000179d2f5df6fdd51e6827fb30e8d479b9d
|
4
|
+
data.tar.gz: 3a8aa4e79e8c585fef31536417fe2e482059bbc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cb0ddb8779f8ae3c59b9c0eaca07d758bf0e12c1dc26af2b758c825bb212b776dd15cc8046380f351bbb9b17b6c454ccde7d37c0395f9a2f6c1db0878226b58
|
7
|
+
data.tar.gz: 03b00fedfc9bbf1dfb28d8db511a91a5bc7861797148ab7d0d8fc8555f8643532674f29459340f183f1324ca0204689cf30da67f4befe7f3f6d2dfe2564b526e
|
data/.codeclimate.yml
CHANGED
data/README.md
CHANGED
@@ -27,8 +27,6 @@ Or install it yourself as:
|
|
27
27
|
### Computing
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
require 'faraday'
|
31
|
-
require 'faraday_middleware'
|
32
30
|
require 'idcf/faraday_middleware'
|
33
31
|
|
34
32
|
Faraday::Request.register_middleware(
|
@@ -37,10 +35,11 @@ Faraday::Request.register_middleware(
|
|
37
35
|
|
38
36
|
@connection ||=
|
39
37
|
Faraday.new(url: 'https://compute.jp-east.idcfcloud.com/') do |faraday|
|
40
|
-
faraday.request :
|
38
|
+
faraday.request :url_encoded
|
41
39
|
faraday.request :signature, api_key: api_key, secret_key: secret_key
|
42
40
|
faraday.response :json
|
43
41
|
faraday.adapter Faraday.default_adapter
|
42
|
+
faraday.options.params_encoder = Faraday::FlatParamsEncoder
|
44
43
|
end
|
45
44
|
@connection.get '/client/api?command=listZones'
|
46
45
|
```
|
@@ -48,8 +47,6 @@ Faraday::Request.register_middleware(
|
|
48
47
|
## ILB
|
49
48
|
|
50
49
|
```ruby
|
51
|
-
require 'faraday'
|
52
|
-
require 'faraday_middleware'
|
53
50
|
require 'idcf/faraday_middleware'
|
54
51
|
|
55
52
|
Faraday::Request.register_middleware(
|
@@ -69,8 +66,6 @@ Faraday::Request.register_middleware(
|
|
69
66
|
## DNS
|
70
67
|
|
71
68
|
```ruby
|
72
|
-
require 'faraday'
|
73
|
-
require 'faraday_middleware'
|
74
69
|
require 'idcf/faraday_middleware'
|
75
70
|
|
76
71
|
Faraday::Request.register_middleware(
|
@@ -90,8 +85,6 @@ Faraday::Request.register_middleware(
|
|
90
85
|
### Billing
|
91
86
|
|
92
87
|
```ruby
|
93
|
-
require 'faraday'
|
94
|
-
require 'faraday_middleware'
|
95
88
|
require 'idcf/faraday_middleware'
|
96
89
|
|
97
90
|
Faraday::Request.register_middleware(
|
@@ -111,8 +104,6 @@ Faraday::Request.register_middleware(
|
|
111
104
|
### Content Cache
|
112
105
|
|
113
106
|
```ruby
|
114
|
-
require 'faraday'
|
115
|
-
require 'faraday_middleware'
|
116
107
|
require 'idcf/faraday_middleware'
|
117
108
|
|
118
109
|
Faraday::Request.register_middleware(
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_runtime_dependency 'activesupport', '>= 4.2'
|
25
25
|
spec.add_runtime_dependency 'activemodel', '>= 4.2'
|
26
26
|
spec.add_runtime_dependency 'faraday'
|
27
|
+
spec.add_runtime_dependency 'faraday_middleware'
|
27
28
|
|
28
29
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
29
30
|
spec.add_development_dependency 'yard'
|
@@ -32,7 +33,6 @@ Gem::Specification.new do |spec|
|
|
32
33
|
spec.add_development_dependency 'simplecov'
|
33
34
|
spec.add_development_dependency 'pry'
|
34
35
|
spec.add_development_dependency 'awesome_print'
|
35
|
-
spec.add_development_dependency 'faraday_middleware'
|
36
36
|
|
37
37
|
spec.required_ruby_version = '>= 1.9.3'
|
38
38
|
end
|
@@ -16,45 +16,70 @@ module Idcf
|
|
16
16
|
def call(env)
|
17
17
|
raise InvalidKeys, errors.messages.to_s if invalid?
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
if env.body.nil?
|
20
|
+
env.url.query = make_get_params(env)
|
21
|
+
else
|
22
|
+
env.body = make_params_body(env)
|
23
|
+
end
|
25
24
|
@app.call env
|
26
25
|
end
|
27
26
|
|
28
27
|
private
|
29
28
|
|
29
|
+
def make_params_body(env)
|
30
|
+
params = URI.decode_www_form(env.url.query)
|
31
|
+
params.concat(URI.decode_www_form(env.body))
|
32
|
+
params << ['apikey', api_key]
|
33
|
+
params << %w(response json)
|
34
|
+
params << ['signature', signature(URI.encode_www_form(params))]
|
35
|
+
URI.encode_www_form(params)
|
36
|
+
end
|
37
|
+
|
38
|
+
def make_get_params(env)
|
39
|
+
query = env.url.query
|
40
|
+
query = add_query_param query, 'apikey', api_key
|
41
|
+
query = add_query_param query, 'response', 'json'
|
42
|
+
add_query_param query, 'signature', signature(query)
|
43
|
+
end
|
44
|
+
|
30
45
|
def add_query_param(query, key, value)
|
31
46
|
query = query.to_s
|
32
47
|
query << '&' unless query.empty?
|
33
48
|
query << "#{Faraday::Utils.escape key}=#{Faraday::Utils.escape value}"
|
34
49
|
end
|
35
50
|
|
36
|
-
def signature(
|
51
|
+
def signature(query)
|
37
52
|
Base64.strict_encode64(
|
38
53
|
OpenSSL::HMAC.digest(
|
39
54
|
OpenSSL::Digest::SHA1.new,
|
40
55
|
secret_key,
|
41
|
-
signature_seed(
|
56
|
+
signature_seed(query)
|
42
57
|
)
|
43
58
|
)
|
44
59
|
end
|
45
60
|
|
46
|
-
def signature_seed(
|
47
|
-
query = env.url.query&.downcase
|
61
|
+
def signature_seed(query)
|
48
62
|
raise InvalidParameter, 'Must be set command=...' if query.nil?
|
49
|
-
query = URI.decode_www_form(query)
|
63
|
+
query = URI.decode_www_form(query.downcase)
|
50
64
|
command_check query
|
51
|
-
query.sort
|
52
|
-
|
65
|
+
query = query.sort do |x, y|
|
66
|
+
x[0] <=> y[0]
|
67
|
+
end
|
68
|
+
signeture_seed_part_decode(URI.encode_www_form(query)).downcase
|
69
|
+
end
|
70
|
+
|
71
|
+
def signeture_seed_part_decode(query)
|
72
|
+
PARTIALLY_DECODE.each do |list|
|
73
|
+
query = query.gsub(*list)
|
74
|
+
end
|
75
|
+
query
|
53
76
|
end
|
54
77
|
|
55
78
|
def command_check(query)
|
56
|
-
|
57
|
-
|
79
|
+
list = query.find do |x|
|
80
|
+
x[0] == 'command' && x[1].present?
|
81
|
+
end
|
82
|
+
raise InvalidParameter, 'Must be set command=...' if list.nil?
|
58
83
|
end
|
59
84
|
end
|
60
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idcf-faraday_middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IDC Frontier Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday_middleware
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,20 +164,6 @@ dependencies:
|
|
150
164
|
- - ">="
|
151
165
|
- !ruby/object:Gem::Version
|
152
166
|
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: faraday_middleware
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
167
|
description:
|
168
168
|
email:
|
169
169
|
executables: []
|