peatio1.9 0.4.4
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 +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/.simplecov +17 -0
- data/.travis.yml +17 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +107 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/peatio +12 -0
- data/bin/setup +8 -0
- data/lib/peatio.rb +20 -0
- data/lib/peatio/auth/error.rb +18 -0
- data/lib/peatio/auth/jwt_authenticator.rb +127 -0
- data/lib/peatio/command/amqp.rb +9 -0
- data/lib/peatio/command/base.rb +11 -0
- data/lib/peatio/command/db.rb +20 -0
- data/lib/peatio/command/inject.rb +11 -0
- data/lib/peatio/command/root.rb +16 -0
- data/lib/peatio/command/security.rb +30 -0
- data/lib/peatio/command/service.rb +26 -0
- data/lib/peatio/error.rb +18 -0
- data/lib/peatio/executor.rb +64 -0
- data/lib/peatio/injectors/peatio_events.rb +209 -0
- data/lib/peatio/logger.rb +37 -0
- data/lib/peatio/mq/client.rb +30 -0
- data/lib/peatio/mq/events.rb +128 -0
- data/lib/peatio/ranger.rb +106 -0
- data/lib/peatio/security/key_generator.rb +26 -0
- data/lib/peatio/sql/client.rb +19 -0
- data/lib/peatio/sql/schema.rb +72 -0
- data/lib/peatio/version.rb +3 -0
- data/peatio1.9.gemspec +44 -0
- metadata +331 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 21e80cf48d4e7fdde91bdcc54415b5de89382fc3d771f4a1d10ae10593e1c209
|
4
|
+
data.tar.gz: 3e9328c73c580e323ad011c1c1c54f21c9d2aa5baf0a7ec4c4f933801c975188
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 777ac8d99de880e823479b65987d689f4ebf353b79d6faab850d2e263530e4f2aeafe4cef938771743ba49ab4cde091626373a50ca4ae69eb4c9a5ba3f27c372
|
7
|
+
data.tar.gz: 13081c7908134089e5c5b4842fdeac92ffeed6a9c00165d38ef98239e9c5a6f47def17610342fc4cd6686fe354a5e85cb8f22cc5b9776085128be23c98e8b158
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.simplecov
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
require 'simplecov-json'
|
3
|
+
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter '/spec/'
|
6
|
+
end
|
7
|
+
|
8
|
+
SimpleCov.formatters = [
|
9
|
+
SimpleCov::Formatter::HTMLFormatter,
|
10
|
+
SimpleCov::Formatter::JSONFormatter,
|
11
|
+
]
|
12
|
+
|
13
|
+
# save to CircleCI's artifacts directory if we're on CircleCI
|
14
|
+
if ENV['CIRCLE_ARTIFACTS']
|
15
|
+
dir = File.join(ENV['CIRCLE_ARTIFACTS'], "coverage")
|
16
|
+
SimpleCov.coverage_dir(dir)
|
17
|
+
end
|
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 2.5.3
|
6
|
+
before_install: gem install bundler -v 1.17.1
|
7
|
+
env:
|
8
|
+
- WEBSOCKET_HOST: localhost
|
9
|
+
WEBSOCKET_PORT: 8081
|
10
|
+
deploy:
|
11
|
+
provider: rubygems
|
12
|
+
api_key:
|
13
|
+
secure: MTlSs+/1/+djQBx9UpZBoPdkLb9j9tx31CxoJ2uw3a429cj9qhJc+qZL9Gbim4kqdDhWAlfIFKDn2aeVPHIcd3VAP3dBUkG2gMxC440gx7rBJXSGpo+zwS9pnsFNQb9RnFZ4OI0dDr0VvYyctZh2h4VVTKhP2m7U59A6yNeNhW8K5HzUZ3+QvykiEQVQUrT29BRpf+9vEISVDPk3o0S0HO+RRvWXOBe5F2M/5hhJUdxUZ2/Pikg3PFJGhS1+g23YhLiEvMN6TiHz/PbUdLN1hnAVgmE86t/DU2lRzhDHNX3CetEhEhtElkTlbpIitmfy8309G0lUMZkN4Z6qKjuYKjuGYXYjXS6nEq6oy5U0HK2Ljo6ka4WZC5u08t5+I12jzCJ5Nq3kdqJkYZwMODgzvcyw4EKNHejyYLGGIbrXgbuYtR6wwvIYz7hz/j/fFxFDawBYC9s92/gvthtHNTzosBi/I07DYYhdF7Rt4TMfdPpasctV8ijTQ+ePH76cNPaDBqupemZUMSJRuuPOXS8SXS1xLDrPviffok/a3zmHDHgYWjqqBzktjCZ5C2PIeVo3o+ClSiWu8tJ3UquqdQ2ug60LK6ttbKxvDk/De3JcV4SEpqJBroSWD84hp0IiyQMEAhl/SxCVLXn9m5xF3evqH168p/Tgr5pklFUDw/tpSh8=
|
14
|
+
gem: peatio
|
15
|
+
on:
|
16
|
+
tags: true
|
17
|
+
repo: top1st/peatio-core-1.9
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
peatio1.9 (0.4.4)
|
5
|
+
amqp
|
6
|
+
bunny
|
7
|
+
clamp
|
8
|
+
em-websocket
|
9
|
+
eventmachine
|
10
|
+
jwt
|
11
|
+
mysql2
|
12
|
+
|
13
|
+
GEM
|
14
|
+
remote: https://rubygems.org/
|
15
|
+
specs:
|
16
|
+
amq-protocol (2.3.0)
|
17
|
+
amqp (1.8.0)
|
18
|
+
amq-protocol (>= 2.2.0)
|
19
|
+
eventmachine
|
20
|
+
ast (2.4.0)
|
21
|
+
bump (0.6.1)
|
22
|
+
bunny (2.12.0)
|
23
|
+
amq-protocol (~> 2.3, >= 2.3.0)
|
24
|
+
bunny-mock (1.7.0)
|
25
|
+
bunny (>= 1.7)
|
26
|
+
clamp (1.3.1)
|
27
|
+
diff-lcs (1.3)
|
28
|
+
docile (1.3.1)
|
29
|
+
em-spec (0.2.7)
|
30
|
+
eventmachine
|
31
|
+
em-websocket (0.5.1)
|
32
|
+
eventmachine (>= 0.12.9)
|
33
|
+
http_parser.rb (~> 0.6.0)
|
34
|
+
em-websocket-client (0.1.2)
|
35
|
+
eventmachine
|
36
|
+
websocket
|
37
|
+
eventmachine (1.2.7)
|
38
|
+
eventmachine (1.2.7-x64-mingw32)
|
39
|
+
http_parser.rb (0.6.0)
|
40
|
+
jaro_winkler (1.5.1)
|
41
|
+
json (2.3.1)
|
42
|
+
jwt (2.2.1)
|
43
|
+
mysql2 (0.5.3)
|
44
|
+
mysql2 (0.5.3-x64-mingw32)
|
45
|
+
parallel (1.12.1)
|
46
|
+
parser (2.5.1.2)
|
47
|
+
ast (~> 2.4.0)
|
48
|
+
powerpack (0.1.2)
|
49
|
+
rainbow (3.0.0)
|
50
|
+
rake (13.0.1)
|
51
|
+
rspec (3.8.0)
|
52
|
+
rspec-core (~> 3.8.0)
|
53
|
+
rspec-expectations (~> 3.8.0)
|
54
|
+
rspec-mocks (~> 3.8.0)
|
55
|
+
rspec-core (3.8.0)
|
56
|
+
rspec-support (~> 3.8.0)
|
57
|
+
rspec-expectations (3.8.2)
|
58
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
+
rspec-support (~> 3.8.0)
|
60
|
+
rspec-mocks (3.8.0)
|
61
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
+
rspec-support (~> 3.8.0)
|
63
|
+
rspec-support (3.8.0)
|
64
|
+
rspec_junit_formatter (0.4.1)
|
65
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
66
|
+
rubocop (0.60.0)
|
67
|
+
jaro_winkler (~> 1.5.1)
|
68
|
+
parallel (~> 1.10)
|
69
|
+
parser (>= 2.5, != 2.5.1.1)
|
70
|
+
powerpack (~> 0.1)
|
71
|
+
rainbow (>= 2.2.2, < 4.0)
|
72
|
+
ruby-progressbar (~> 1.7)
|
73
|
+
unicode-display_width (~> 1.4.0)
|
74
|
+
rubocop-github (0.12.0)
|
75
|
+
rubocop (~> 0.59)
|
76
|
+
ruby-progressbar (1.10.0)
|
77
|
+
simplecov (0.16.1)
|
78
|
+
docile (~> 1.1)
|
79
|
+
json (>= 1.8, < 3)
|
80
|
+
simplecov-html (~> 0.10.0)
|
81
|
+
simplecov-html (0.10.2)
|
82
|
+
simplecov-json (0.2)
|
83
|
+
json
|
84
|
+
simplecov
|
85
|
+
unicode-display_width (1.4.0)
|
86
|
+
websocket (1.2.8)
|
87
|
+
|
88
|
+
PLATFORMS
|
89
|
+
ruby
|
90
|
+
x64-mingw32
|
91
|
+
|
92
|
+
DEPENDENCIES
|
93
|
+
bump
|
94
|
+
bundler (~> 1.16)
|
95
|
+
bunny-mock
|
96
|
+
em-spec
|
97
|
+
em-websocket-client
|
98
|
+
peatio1.9!
|
99
|
+
rake (~> 13.0)
|
100
|
+
rspec (~> 3.0)
|
101
|
+
rspec_junit_formatter
|
102
|
+
rubocop-github
|
103
|
+
simplecov
|
104
|
+
simplecov-json
|
105
|
+
|
106
|
+
BUNDLED WITH
|
107
|
+
1.17.3
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Peatio
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/peatio`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'peatio'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install peatio
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/peatio.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "peatio"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/peatio
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- RUBY -*-
|
3
|
+
|
4
|
+
PEATIO_CORE = ENV["PEATIO_CORE"] || File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
5
|
+
$: << File.join(PEATIO_CORE, "lib")
|
6
|
+
|
7
|
+
require "clamp"
|
8
|
+
|
9
|
+
require "peatio"
|
10
|
+
require "peatio/command/root"
|
11
|
+
|
12
|
+
Peatio::Root.run
|
data/bin/setup
ADDED
data/lib/peatio.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "json"
|
3
|
+
require "mysql2"
|
4
|
+
require "bunny"
|
5
|
+
require "eventmachine"
|
6
|
+
require "em-websocket"
|
7
|
+
|
8
|
+
module Peatio
|
9
|
+
require_relative "peatio/error"
|
10
|
+
require_relative "peatio/logger"
|
11
|
+
require_relative "peatio/version"
|
12
|
+
require_relative "peatio/sql/client"
|
13
|
+
require_relative "peatio/sql/schema"
|
14
|
+
require_relative "peatio/mq/client"
|
15
|
+
require_relative "peatio/mq/events"
|
16
|
+
require_relative "peatio/ranger"
|
17
|
+
require_relative "peatio/injectors/peatio_events"
|
18
|
+
require_relative "peatio/security/key_generator"
|
19
|
+
require_relative "peatio/auth/jwt_authenticator"
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Peatio::Auth
|
2
|
+
# Error repesent all errors that can be returned from Auth module.
|
3
|
+
class Error < Peatio::Error
|
4
|
+
# @return [String, JWT::*] Reason store underlying reason for given error.
|
5
|
+
#
|
6
|
+
# @see https://github.com/jwt/ruby-jwt/blob/master/lib/jwt/error.rb List of JWT::* errors.
|
7
|
+
attr_reader :reason
|
8
|
+
|
9
|
+
def initialize(reason = nil)
|
10
|
+
@reason = reason
|
11
|
+
|
12
|
+
super(
|
13
|
+
code: 2001,
|
14
|
+
text: "Authorization failed".tap { |t| t << ": #{reason}" if reason },
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require "jwt"
|
2
|
+
|
3
|
+
require_relative "error"
|
4
|
+
|
5
|
+
module Peatio::Auth
|
6
|
+
# JWTAuthenticator used to authenticate user using JWT.
|
7
|
+
#
|
8
|
+
# It allows configuration of JWT verification through following ENV
|
9
|
+
# variables (all optional):
|
10
|
+
# * JWT_ISSUER
|
11
|
+
# * JWT_AUDIENCE
|
12
|
+
# * JWT_ALGORITHM (default: RS256)
|
13
|
+
# * JWT_DEFAULT_LEEWAY
|
14
|
+
# * JWT_ISSUED_AT_LEEWAY
|
15
|
+
# * JWT_EXPIRATION_LEEWAY
|
16
|
+
# * JWT_NOT_BEFORE_LEEWAY
|
17
|
+
#
|
18
|
+
# @see https://github.com/jwt/ruby-jwt JWT validation parameters.
|
19
|
+
#
|
20
|
+
# @example Token validation
|
21
|
+
# rsa_private = OpenSSL::PKey::RSA.generate(2048)
|
22
|
+
# rsa_public = rsa_private.public_key
|
23
|
+
#
|
24
|
+
# payload = {
|
25
|
+
# iat: Time.now.to_i,
|
26
|
+
# exp: (Time.now + 60).to_i,
|
27
|
+
# sub: "session",
|
28
|
+
# iss: "barong",
|
29
|
+
# aud: [
|
30
|
+
# "peatio",
|
31
|
+
# "barong",
|
32
|
+
# ],
|
33
|
+
# jti: "BEF5617B7B2762DDE61702F5",
|
34
|
+
# uid: "TEST123",
|
35
|
+
# email: "user@example.com",
|
36
|
+
# role: "admin",
|
37
|
+
# level: 4,
|
38
|
+
# state: "active",
|
39
|
+
# }
|
40
|
+
#
|
41
|
+
# token = JWT.encode(payload, rsa_private, "RS256")
|
42
|
+
#
|
43
|
+
# auth = Peatio::Auth::JWTAuthenticator.new(rsa_public)
|
44
|
+
# auth.authenticate!("Bearer #{token}")
|
45
|
+
class JWTAuthenticator
|
46
|
+
# Creates new authenticator with given public key.
|
47
|
+
#
|
48
|
+
# @param public_key [OpenSSL::PKey::PKey] Public key object to verify
|
49
|
+
# signature.
|
50
|
+
# @param private_key [OpenSSL::PKey::PKey] Optional private key that used
|
51
|
+
# only to encode new tokens.
|
52
|
+
def initialize(public_key, private_key = nil)
|
53
|
+
@public_key = public_key
|
54
|
+
@private_key = private_key
|
55
|
+
|
56
|
+
@verify_options = {
|
57
|
+
verify_expiration: true,
|
58
|
+
verify_not_before: true,
|
59
|
+
iss: ENV["JWT_ISSUER"],
|
60
|
+
verify_iss: !ENV["JWT_ISSUER"].nil?,
|
61
|
+
verify_iat: true,
|
62
|
+
verify_jti: true,
|
63
|
+
aud: ENV["JWT_AUDIENCE"].to_s.split(",").reject(&:empty?),
|
64
|
+
verify_aud: !ENV["JWT_AUDIENCE"].nil?,
|
65
|
+
sub: "session",
|
66
|
+
verify_sub: true,
|
67
|
+
algorithms: [ENV["JWT_ALGORITHM"] || "RS256"],
|
68
|
+
leeway: ENV["JWT_DEFAULT_LEEWAY"].yield_self { |n| n.to_i unless n.nil? },
|
69
|
+
iat_leeway: ENV["JWT_ISSUED_AT_LEEWAY"].yield_self { |n| n.to_i unless n.nil? },
|
70
|
+
exp_leeway: ENV["JWT_EXPIRATION_LEEWAY"].yield_self { |n| n.to_i unless n.nil? },
|
71
|
+
nbf_leeway: ENV["JWT_NOT_BEFORE_LEEWAY"].yield_self { |n| n.to_i unless n.nil? },
|
72
|
+
}.compact
|
73
|
+
|
74
|
+
@encode_options = {
|
75
|
+
algorithm: @verify_options[:algorithms].first,
|
76
|
+
}.compact
|
77
|
+
end
|
78
|
+
|
79
|
+
# Decodes and verifies JWT.
|
80
|
+
# Returns payload from JWT or raises an exception
|
81
|
+
#
|
82
|
+
# @param token [String] Token string. Must start from <tt>"Bearer "</tt>.
|
83
|
+
# @return [Hash] Payload Hash from JWT without any changes.
|
84
|
+
#
|
85
|
+
# @raise [Peatio::Auth::Error] If token is invalid or can't be verified.
|
86
|
+
def authenticate!(token)
|
87
|
+
token_type, token_value = token.to_s.split(" ")
|
88
|
+
|
89
|
+
unless token_type == "Bearer"
|
90
|
+
raise(Peatio::Auth::Error, "Token type is not provided or invalid.")
|
91
|
+
end
|
92
|
+
|
93
|
+
decode_and_verify_token(token_value)
|
94
|
+
rescue => error
|
95
|
+
case error
|
96
|
+
when Peatio::Auth::Error
|
97
|
+
raise(error)
|
98
|
+
else
|
99
|
+
raise(Peatio::Auth::Error, error.message)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Encodes given payload and produces JWT.
|
104
|
+
#
|
105
|
+
# @param payload [String, Hash] Payload to encode.
|
106
|
+
# @return [String] JWT token string.
|
107
|
+
#
|
108
|
+
# @raise [ArgumentError] If no private key was passed to constructor.
|
109
|
+
def encode(payload)
|
110
|
+
raise(::ArgumentError, "No private key given.") if @private_key.nil?
|
111
|
+
|
112
|
+
JWT.encode(payload, @private_key, @encode_options[:algorithm])
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
def decode_and_verify_token(token)
|
118
|
+
payload, header = JWT.decode(token, @public_key, true, @verify_options)
|
119
|
+
|
120
|
+
payload.keys.each { |k| payload[k.to_sym] = payload.delete(k) }
|
121
|
+
|
122
|
+
payload
|
123
|
+
rescue JWT::DecodeError => e
|
124
|
+
raise(Peatio::Auth::Error, "Failed to decode and verify JWT")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|