idcf-faraday_middleware 0.0.1.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +17 -0
- data/.gitignore +13 -0
- data/.pryrc +2 -0
- data/.rspec +2 -0
- data/.rubocop.yml +18 -0
- data/.travis.yml +12 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +145 -0
- data/Rakefile +6 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/idcf-faraday_middleware.gemspec +38 -0
- data/lib/idcf/faraday_middleware.rb +20 -0
- data/lib/idcf/faraday_middleware/cdn_signature.rb +38 -0
- data/lib/idcf/faraday_middleware/computing_signature.rb +61 -0
- data/lib/idcf/faraday_middleware/configuration.rb +13 -0
- data/lib/idcf/faraday_middleware/errors.rb +7 -0
- data/lib/idcf/faraday_middleware/signature.rb +53 -0
- data/lib/idcf/faraday_middleware/validations.rb +17 -0
- data/lib/idcf/faraday_middleware/version.rb +5 -0
- metadata +219 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e5ed90852c12f8a543731c0dc1b8fe172192256
|
4
|
+
data.tar.gz: 99d3a403ab481643ff102a8f35f825b5ec2bad22
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 93a7feb0e50bf9af03e0a3fd935190cc881113822da4edd11f987019fee1a4c81b90b6a6b1abfe27d9a3a83c30b24ad009ba6a72e6f6c6bcd5a652b2715bfbee
|
7
|
+
data.tar.gz: 88bc183fad2037008a5fd7545cd90d7229179038fb44674235788a18d107669038753909b1f5e3d1dd5a62f054bf74cf3c320e8a501b9dce711cdbc9056c77a9
|
data/.codeclimate.yml
ADDED
data/.gitignore
ADDED
data/.pryrc
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.4
|
3
|
+
Exclude:
|
4
|
+
- 'vendor/**/*'
|
5
|
+
|
6
|
+
Style/FrozenStringLiteralComment:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/AsciiComments:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Metrics/BlockLength:
|
13
|
+
Exclude:
|
14
|
+
- '*.gemspec'
|
15
|
+
|
16
|
+
PercentLiteralDelimiters:
|
17
|
+
PreferredDelimiters:
|
18
|
+
'%i': '()'
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at issue. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 IDC Frontier Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
# Idcf::FaradayMiddleware
|
2
|
+
[![Code Climate](https://codeclimate.com/github/idcf/idcf-faraday_middleware/badges/gpa.svg)](https://codeclimate.com/github/idcf/idcf-faraday_middleware)
|
3
|
+
[![Issue Count](https://codeclimate.com/github/idcf/idcf-faraday_middleware/badges/issue_count.svg)](https://codeclimate.com/github/idcf/idcf-faraday_middleware)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'idcf-faraday_middleware'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install idcf-faraday_middleware
|
20
|
+
|
21
|
+
## Dependencies
|
22
|
+
- Ruby 1.9.3 or later
|
23
|
+
- Rails 4.2 or later
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Computing
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'faraday'
|
31
|
+
require 'faraday_middleware'
|
32
|
+
require 'idcf/faraday_middleware'
|
33
|
+
|
34
|
+
Faraday::Request.register_middleware(
|
35
|
+
signature: Idcf::FaradayMiddleware::ComputingSignature
|
36
|
+
)
|
37
|
+
|
38
|
+
@connection ||=
|
39
|
+
Faraday.new(url: 'https://compute.jp-east.idcfcloud.com/') do |faraday|
|
40
|
+
faraday.request :json
|
41
|
+
faraday.request :signature, api_key: api_key, secret_key: secret_key
|
42
|
+
faraday.response :json
|
43
|
+
faraday.adapter Faraday.default_adapter
|
44
|
+
end
|
45
|
+
@connection.get '/client/api?command=listZones'
|
46
|
+
```
|
47
|
+
|
48
|
+
## ILB
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require 'faraday'
|
52
|
+
require 'faraday_middleware'
|
53
|
+
require 'idcf/faraday_middleware'
|
54
|
+
|
55
|
+
Faraday::Request.register_middleware(
|
56
|
+
signature: Idcf::FaradayMiddleware::Signature
|
57
|
+
)
|
58
|
+
|
59
|
+
@connection ||=
|
60
|
+
Faraday.new(url: 'https://ilb.jp-east.idcfcloud.com/') do |faraday|
|
61
|
+
faraday.request :json
|
62
|
+
faraday.request :signature, api_key: api_key, secret_key: secret_key
|
63
|
+
faraday.response :json
|
64
|
+
faraday.adapter Faraday.default_adapter
|
65
|
+
end
|
66
|
+
@connection.get '/api/v1/loadbalancers'
|
67
|
+
```
|
68
|
+
|
69
|
+
## DNS
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
require 'faraday'
|
73
|
+
require 'faraday_middleware'
|
74
|
+
require 'idcf/faraday_middleware'
|
75
|
+
|
76
|
+
Faraday::Request.register_middleware(
|
77
|
+
signature: Idcf::FaradayMiddleware::Signature
|
78
|
+
)
|
79
|
+
|
80
|
+
@connection ||=
|
81
|
+
Faraday.new(url: 'https://dns.idcfcloud.com/') do |faraday|
|
82
|
+
faraday.request :json
|
83
|
+
faraday.request :signature, api_key: api_key, secret_key: secret_key
|
84
|
+
faraday.response :json
|
85
|
+
faraday.adapter Faraday.default_adapter
|
86
|
+
end
|
87
|
+
@connection.get '/api/v1/zones'
|
88
|
+
```
|
89
|
+
|
90
|
+
### Billing
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
require 'faraday'
|
94
|
+
require 'faraday_middleware'
|
95
|
+
require 'idcf/faraday_middleware'
|
96
|
+
|
97
|
+
Faraday::Request.register_middleware(
|
98
|
+
signature: Idcf::FaradayMiddleware::Signature
|
99
|
+
)
|
100
|
+
|
101
|
+
@connection ||=
|
102
|
+
Faraday.new(url: 'https://your.idcfcloud.com/') do |faraday|
|
103
|
+
faraday.request :json
|
104
|
+
faraday.request :signature, api_key: api_key, secret_key: secret_key
|
105
|
+
faraday.response :json
|
106
|
+
faraday.adapter Faraday.default_adapter
|
107
|
+
end
|
108
|
+
@connection.get '/api/v1/billings/history?format=json'
|
109
|
+
```
|
110
|
+
|
111
|
+
### Content Cache
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
require 'faraday'
|
115
|
+
require 'faraday_middleware'
|
116
|
+
require 'idcf/faraday_middleware'
|
117
|
+
|
118
|
+
Faraday::Request.register_middleware(
|
119
|
+
signature: Idcf::FaradayMiddleware::CdnSignature
|
120
|
+
)
|
121
|
+
|
122
|
+
@connection ||=
|
123
|
+
Faraday.new(url: 'https://cdn.idcfcloud.com/') do |faraday|
|
124
|
+
faraday.request :json
|
125
|
+
faraday.request :signature, api_key: api_key, secret_key: secret_key
|
126
|
+
faraday.response :json
|
127
|
+
faraday.adapter Faraday.default_adapter
|
128
|
+
end
|
129
|
+
@connection.get "/api/v0/fqdns?api_key=#{api_key}"
|
130
|
+
```
|
131
|
+
|
132
|
+
## Development
|
133
|
+
|
134
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
135
|
+
|
136
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
137
|
+
|
138
|
+
## Contributing
|
139
|
+
|
140
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/idcf/idcf-faraday_middleware. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
141
|
+
|
142
|
+
|
143
|
+
## License
|
144
|
+
|
145
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
require 'idcf/faraday_middleware'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
require 'pry'
|
12
|
+
Pry.start
|
13
|
+
|
14
|
+
# require 'irb'
|
15
|
+
# IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'idcf/faraday_middleware/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'idcf-faraday_middleware'
|
9
|
+
spec.version = Idcf::FaradayMiddleware::VERSION
|
10
|
+
spec.authors = ['IDC Frontier Inc.']
|
11
|
+
|
12
|
+
spec.summary = 'A Ruby client for IDCF Cloud Service.'
|
13
|
+
# spec.description = ''
|
14
|
+
spec.homepage = 'https://www.idcf.jp/english/cloud/'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'activesupport', '>= 4.2'
|
25
|
+
spec.add_runtime_dependency 'activemodel', '>= 4.2'
|
26
|
+
spec.add_runtime_dependency 'faraday'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
29
|
+
spec.add_development_dependency 'yard'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
spec.add_development_dependency 'simplecov'
|
33
|
+
spec.add_development_dependency 'pry'
|
34
|
+
spec.add_development_dependency 'awesome_print'
|
35
|
+
spec.add_development_dependency 'faraday_middleware'
|
36
|
+
|
37
|
+
spec.required_ruby_version = '>= 1.9.3'
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'faraday'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext/class/attribute'
|
5
|
+
require 'active_support/dependencies/autoload'
|
6
|
+
|
7
|
+
require 'idcf/faraday_middleware/version'
|
8
|
+
require 'idcf/faraday_middleware/errors'
|
9
|
+
|
10
|
+
module Idcf
|
11
|
+
# 各クラスを読み込みます
|
12
|
+
module FaradayMiddleware
|
13
|
+
extend ActiveSupport::Autoload
|
14
|
+
autoload :Signature, 'idcf/faraday_middleware/signature'
|
15
|
+
autoload :CdnSignature, 'idcf/faraday_middleware/cdn_signature'
|
16
|
+
autoload :ComputingSignature, 'idcf/faraday_middleware/computing_signature'
|
17
|
+
autoload :Configuration, 'idcf/faraday_middleware/configuration'
|
18
|
+
autoload :Validations, 'idcf/faraday_middleware/validations'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Idcf
|
2
|
+
module FaradayMiddleware
|
3
|
+
# コンテンツキャッシュ用のシグネチャ生成を実施します。
|
4
|
+
class CdnSignature < Signature
|
5
|
+
def call(env)
|
6
|
+
raise InvalidKeys, errors.messages.to_s if invalid?
|
7
|
+
|
8
|
+
env[:request_headers][EXPIRES] = expires
|
9
|
+
env[:request_headers][SIGNATURE] = signature env
|
10
|
+
|
11
|
+
@app.call env
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def signature(env)
|
17
|
+
Base64.strict_encode64(
|
18
|
+
OpenSSL::HMAC.hexdigest(
|
19
|
+
OpenSSL::Digest::SHA256.new,
|
20
|
+
secret_key,
|
21
|
+
signature_seed(env)
|
22
|
+
)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def signature_seed(env)
|
27
|
+
[
|
28
|
+
env.method.to_s.upcase,
|
29
|
+
api_key,
|
30
|
+
secret_key,
|
31
|
+
expires,
|
32
|
+
env.url.request_uri,
|
33
|
+
env.body.to_s
|
34
|
+
].join("\n")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Idcf
|
2
|
+
module FaradayMiddleware
|
3
|
+
# コンピューティング用のシグネチャ生成を実施します。
|
4
|
+
class ComputingSignature < Faraday::Middleware
|
5
|
+
include FaradayMiddleware::Configuration
|
6
|
+
include FaradayMiddleware::Validations
|
7
|
+
|
8
|
+
class_attribute :api_key, :secret_key
|
9
|
+
|
10
|
+
def initialize(app, keys = {})
|
11
|
+
super(app)
|
12
|
+
@api_key = keys[:api_key]
|
13
|
+
@secret_key = keys[:secret_key]
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
raise InvalidKeys, errors.messages.to_s if invalid?
|
18
|
+
|
19
|
+
query = env.url.query
|
20
|
+
query = add_query_param query, 'apikey', api_key
|
21
|
+
query = add_query_param query, 'response', 'json'
|
22
|
+
query = add_query_param query, 'signature', signature(env)
|
23
|
+
env.url.query = query
|
24
|
+
|
25
|
+
@app.call env
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def add_query_param(query, key, value)
|
31
|
+
query = query.to_s
|
32
|
+
query << '&' unless query.empty?
|
33
|
+
query << "#{Faraday::Utils.escape key}=#{Faraday::Utils.escape value}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def signature(env)
|
37
|
+
Base64.strict_encode64(
|
38
|
+
OpenSSL::HMAC.digest(
|
39
|
+
OpenSSL::Digest::SHA1.new,
|
40
|
+
secret_key,
|
41
|
+
signature_seed(env)
|
42
|
+
)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def signature_seed(env)
|
47
|
+
query = env.url.query&.downcase
|
48
|
+
raise InvalidParameter, 'Must be set command=...' if query.nil?
|
49
|
+
query = URI.decode_www_form(query)
|
50
|
+
command_check query
|
51
|
+
query.sort! { |x, y| x[0] <=> y [0] }
|
52
|
+
URI.encode_www_form(query).gsub('+', '%20').downcase
|
53
|
+
end
|
54
|
+
|
55
|
+
def command_check(query)
|
56
|
+
raise InvalidParameter, 'Must be set command=...' if
|
57
|
+
query.find { |x| x[0] == 'command' && x[1].present? }.nil?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Idcf
|
2
|
+
module FaradayMiddleware
|
3
|
+
# 各種定数を定義します
|
4
|
+
module Configuration
|
5
|
+
HEADER_API_KEY = 'X-IDCF-APIKEY'.freeze
|
6
|
+
HEADER_EXPIRES = 'X-IDCF-Expires'.freeze
|
7
|
+
HEADER_SIGNATURE = 'X-IDCF-Signature'.freeze
|
8
|
+
EXPIRES = 'Expired'.freeze
|
9
|
+
SIGNATURE = 'Signature'.freeze
|
10
|
+
SIGNATURE_TTL = 600
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Idcf
|
2
|
+
module FaradayMiddleware
|
3
|
+
# ILB, DNS, Your(Billing)用のシグネチャ生成を実施します。
|
4
|
+
class Signature < Faraday::Middleware
|
5
|
+
include FaradayMiddleware::Configuration
|
6
|
+
include FaradayMiddleware::Validations
|
7
|
+
|
8
|
+
class_attribute :api_key, :secret_key
|
9
|
+
|
10
|
+
def initialize(app, keys = {})
|
11
|
+
super(app)
|
12
|
+
@api_key = keys[:api_key]
|
13
|
+
@secret_key = keys[:secret_key]
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
raise InvalidKeys, errors.messages.to_s if invalid?
|
18
|
+
|
19
|
+
env[:request_headers][HEADER_API_KEY] = api_key
|
20
|
+
env[:request_headers][HEADER_EXPIRES] = expires
|
21
|
+
env[:request_headers][HEADER_SIGNATURE] = signature env
|
22
|
+
|
23
|
+
@app.call env
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def signature(env)
|
29
|
+
Base64.strict_encode64(
|
30
|
+
OpenSSL::HMAC.digest(
|
31
|
+
OpenSSL::Digest::SHA256.new,
|
32
|
+
secret_key,
|
33
|
+
signature_seed(env)
|
34
|
+
)
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def signature_seed(env)
|
39
|
+
[
|
40
|
+
env.method.to_s.upcase,
|
41
|
+
env.url.path,
|
42
|
+
api_key,
|
43
|
+
expires,
|
44
|
+
env.url.query.to_s.gsub('+', '%20')
|
45
|
+
].join("\n")
|
46
|
+
end
|
47
|
+
|
48
|
+
def expires
|
49
|
+
(Time.now.to_i + SIGNATURE_TTL).to_s
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'active_support/concern'
|
3
|
+
module Idcf
|
4
|
+
module FaradayMiddleware
|
5
|
+
# API KeyとSecret Keyのバリデーションを定義します
|
6
|
+
module Validations
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
included do
|
9
|
+
include ActiveModel::Validations
|
10
|
+
validates :api_key, presence: true, length: { is: 86 },
|
11
|
+
format: { with: /\A[\w\-]+\z/ }
|
12
|
+
validates :secret_key, presence: true, length: { is: 86 },
|
13
|
+
format: { with: /\A[\w\-]+\z/ }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: idcf-faraday_middleware
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.rc2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- IDC Frontier Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activemodel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: awesome_print
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
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
|
+
description:
|
168
|
+
email:
|
169
|
+
executables: []
|
170
|
+
extensions: []
|
171
|
+
extra_rdoc_files: []
|
172
|
+
files:
|
173
|
+
- ".codeclimate.yml"
|
174
|
+
- ".gitignore"
|
175
|
+
- ".pryrc"
|
176
|
+
- ".rspec"
|
177
|
+
- ".rubocop.yml"
|
178
|
+
- ".travis.yml"
|
179
|
+
- CODE_OF_CONDUCT.md
|
180
|
+
- Gemfile
|
181
|
+
- LICENSE.txt
|
182
|
+
- README.md
|
183
|
+
- Rakefile
|
184
|
+
- bin/console
|
185
|
+
- bin/setup
|
186
|
+
- idcf-faraday_middleware.gemspec
|
187
|
+
- lib/idcf/faraday_middleware.rb
|
188
|
+
- lib/idcf/faraday_middleware/cdn_signature.rb
|
189
|
+
- lib/idcf/faraday_middleware/computing_signature.rb
|
190
|
+
- lib/idcf/faraday_middleware/configuration.rb
|
191
|
+
- lib/idcf/faraday_middleware/errors.rb
|
192
|
+
- lib/idcf/faraday_middleware/signature.rb
|
193
|
+
- lib/idcf/faraday_middleware/validations.rb
|
194
|
+
- lib/idcf/faraday_middleware/version.rb
|
195
|
+
homepage: https://www.idcf.jp/english/cloud/
|
196
|
+
licenses:
|
197
|
+
- MIT
|
198
|
+
metadata: {}
|
199
|
+
post_install_message:
|
200
|
+
rdoc_options: []
|
201
|
+
require_paths:
|
202
|
+
- lib
|
203
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: 1.9.3
|
208
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
|
+
requirements:
|
210
|
+
- - ">"
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: 1.3.1
|
213
|
+
requirements: []
|
214
|
+
rubyforge_project:
|
215
|
+
rubygems_version: 2.6.8
|
216
|
+
signing_key:
|
217
|
+
specification_version: 4
|
218
|
+
summary: A Ruby client for IDCF Cloud Service.
|
219
|
+
test_files: []
|