hobby-rpc 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/hobby/rpc.rb +79 -0
  3. metadata +86 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 34cd6d8707a326830ee359ffd413ca313a4893fbe5545cbb3423171a659f57a6
4
+ data.tar.gz: c7e6e3f1202778b76b956d46d087951c0fc5b53ed9779c7b775898825e3b014e
5
+ SHA512:
6
+ metadata.gz: 89ac9149cff9c6c44608cd97ec8a2ac8ab83ce069fc27c65279903f25a9d422edb8def1a973ff9d73f20e9f649d5250f35a595e4255b7d5760eff26dffbe9304
7
+ data.tar.gz: ccb6c62344c3dbdc7c25628768eb9e38ec87f236bf0fef59de9fbeddea7372a8f49dd14a6fe39f447f5f78d9176b9d3a81e2985f7f9aff2b61fcb7405b2d5571
data/lib/hobby/rpc.rb ADDED
@@ -0,0 +1,79 @@
1
+ module Hobby
2
+ class RPC
3
+ class CORS
4
+ def initialize app
5
+ @app = app
6
+ end
7
+
8
+ def call env
9
+ case env['REQUEST_METHOD']
10
+ when 'OPTIONS'
11
+ response = Rack::Response.new
12
+
13
+ response.add_header 'Access-Control-Allow-Origin', '*'
14
+ response.add_header 'Access-Control-Allow-Methods', 'POST, OPTIONS'
15
+ response.add_header 'Access-Control-Allow-Headers', 'Authorization, Content-Type'
16
+ response.add_header 'Access-Control-Max-Age', '86400'
17
+
18
+ response.to_a
19
+ else
20
+ status, headers, body = @app.call(env).to_a
21
+ headers['Access-Control-Allow-Origin'] = '*'
22
+ [status, headers, body]
23
+ end
24
+ end
25
+ end
26
+
27
+ module User
28
+ def self.roles
29
+ @roles ||= []
30
+ end
31
+
32
+ def self.find_by_token token
33
+ roles.each do |role|
34
+ if user = (role.find_by_token token)
35
+ return user
36
+ end
37
+ end
38
+ return false
39
+ end
40
+
41
+ def can? _function
42
+ end
43
+
44
+ def self.included role
45
+ roles << role
46
+ end
47
+ end
48
+
49
+ require 'hobby'
50
+ require 'hobby/auth'
51
+ require 'hobby/json/keys'
52
+
53
+ include Hobby
54
+ include Auth[User]
55
+ include JSON::Keys
56
+
57
+ use CORS
58
+
59
+ key :fn, String
60
+ optional {
61
+ key :in
62
+ }
63
+
64
+ User post {
65
+ begin
66
+ function = keys[:fn]
67
+
68
+ if user.can? function
69
+ function = Object.const_get function
70
+ function.(user: user, input: keys[:in])
71
+ else
72
+ response.status = 403
73
+ end
74
+ rescue
75
+ response.status = 400
76
+ end
77
+ }
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hobby-rpc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Anatoly Chernov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-04-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hobby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: hobby-auth
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: hobby-json-keys
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.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.0.0
55
+ description: A simple RPC system for callable Ruby constants. It allows to expose
56
+ them over HTTP safely, only to authorized users.
57
+ email: chertoly@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/hobby/rpc.rb
63
+ homepage: https://github.com/ch1c0t/hobby-rpc
64
+ licenses:
65
+ - ISC
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.1.6
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: A simple RPC system.
86
+ test_files: []