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.
@@ -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
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /*.gem
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ # Ignore RubyMine files
15
+ .idea
16
+ .rakeTasks
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,8 @@
1
+ inherit_gem:
2
+ rubocop-github:
3
+ - config/default.yml
4
+
5
+ AllCops:
6
+ DisabledByDefault: true
7
+ Exclude:
8
+ - spec/**/*
@@ -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
@@ -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
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in peatio.gemspec
6
+ gemspec
@@ -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
@@ -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.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -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__)
@@ -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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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
@@ -0,0 +1,9 @@
1
+ module Peatio::Command::AMQP
2
+ class Root < Peatio::Command::Base
3
+
4
+ def execute
5
+ say "Nothing here"
6
+ end
7
+
8
+ end
9
+ end