wireway 0.1.0 → 202012021551
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 +4 -4
- data/README.md +35 -20
- data/app/controllers/wireway/application_controller.rb +1 -0
- data/app/controllers/wireway/restful_controller.rb +13 -0
- data/app/models/wireway/business_logic/restful.rb +76 -32
- data/app/models/wireway/spark.rb +15 -4
- data/config/routes.rb +5 -0
- data/lib/wireway/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8568460d0bef7166032661c260370d9b10cdeb8b677b9b18340b33464295e4ca
|
4
|
+
data.tar.gz: 1f2b0e0593783e059bcbf9f903579e28392c1cc4bc47ebd8a5870ae3bde5e58e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37e37be17d98fb26481d70973b53e13d1fb487d4515d64cdb386ce2e958d8bd15b1ad796402bada5711767a3e8a034a3e1938f84478e48c47beb5ba1af4c84a2
|
7
|
+
data.tar.gz: fae03643a8cee2b0f3925d6db73a59e314b0c2e54f01d41a0e746b5a133ef4539f109966fce605bab0c712354950e1407bff939729e44a3d6450cae2980af198
|
data/README.md
CHANGED
@@ -1,5 +1,28 @@
|
|
1
|
+
|
2
|
+
<!-- TOC -->
|
3
|
+
|
4
|
+
- [说明](#说明)
|
5
|
+
- [执照](#执照)
|
6
|
+
- [插件作用](#插件作用)
|
7
|
+
- [行为准则](#行为准则)
|
8
|
+
- [关于C919](#关于c919)
|
9
|
+
- [使用示例](#使用示例)
|
10
|
+
|
11
|
+
<!-- /TOC -->
|
12
|
+
|
1
13
|
# 说明
|
2
14
|
|
15
|
+
## 执照
|
16
|
+
|
17
|
+
根据以下条款,该Gem可作为开源软件使用 [MIT License](https://opensource.org/licenses/MIT).
|
18
|
+
|
19
|
+
## 插件作用
|
20
|
+
|
21
|
+
该Gem主要起到反向代理作用,通过该Gem可实现C919系列插件的调用.
|
22
|
+
|
23
|
+
该Gem本身并不实现任何具体功能,只是将请求转发给具体的服务接口.<br>
|
24
|
+
因此,具体可用功能以及参数格式以各组件示例页面为准.
|
25
|
+
|
3
26
|
## 行为准则
|
4
27
|
|
5
28
|
0. 集成该Gem后可实现各组件任意调用.
|
@@ -7,31 +30,23 @@
|
|
7
30
|
0. 各组件的具体配置信息可以通过Satcom实时获取最新配置内容.
|
8
31
|
0. 后期应允许符合某种安全机制的节点自主加入并注册允许发现.
|
9
32
|
|
10
|
-
|
11
|
-
Short description and motivation.
|
33
|
+
## 关于C919
|
12
34
|
|
13
|
-
|
14
|
-
How to use my plugin.
|
35
|
+
C919为系列Gem组件的集合,具体组成部分及相关示例[参考](https://gitlab.com/ff4c00/space/-/tree/master/%E7%9F%A5%E8%AF%86%E4%BD%93%E7%B3%BB/%E5%BA%94%E7%94%A8%E7%A7%91%E5%AD%A6/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6/%E8%BD%AF%E4%BB%B6%E5%B7%A5%E7%A8%8B/Rails/C919)
|
15
36
|
|
16
|
-
##
|
17
|
-
Add this line to your application's Gemfile:
|
37
|
+
## 使用示例
|
18
38
|
|
19
39
|
```ruby
|
20
|
-
|
40
|
+
Wireway::Spark.satcom(api_code: :finance_fund_base_info, code: '161725')
|
41
|
+
# => [true, {:基金全称=>"招商中证白酒指数分级证券投资基金", :基金简称=>"招商中证白酒指数分级", :基金代码=>"161725(前端)", :基金类型=>"股票指数", :发行日期=>"2015年05月12日", :"成立日期/规模"=>"2015年05月27日 / 3.965亿份", :资产规模=>"129.25亿元(截止至:2020年06月30日)", :份额规模=>"184.0866亿份(截止至:2020年08月26日)", :基金经理人=>"侯昊", :基金托管人=>"中国银行", :成立来分红=>"每份累计0.00元(0次)", :管理费率=>"1.00%(每年)", :托管费率=>"0.22%(每年)", :销售服务费率=>"---(每年)", :最高认购费率=>"0.80%(前端)", :业绩比较基准=>"中证白酒指数收益率×95%+金融机构人民币活期存款基准利率(税后)×5%", :跟踪标的=>"中证白酒指数", :母子基金=>"161725(母)150269 150270(子)", :是否配对转换=>"是", :是否转LOF=>"否", :封闭期=>"无", :提前结束条款=>"无", :定期折算日=>"每个会计年度的12月15日(遇节假日顺延)", :不定期折算条件=>"当招商中证白酒份额的基金份额净值达到1.500元;当招商中证白酒B份额的基金份额参考净值达到0.250元。", :固定收益份额年化收益率=>"一年期定期存款利率(税后)+3%", :亏损临界点=>"无", :保收益临界点=>"无", :超额收益临界点=>"无"}]
|
21
42
|
```
|
22
43
|
|
23
|
-
|
24
|
-
```bash
|
25
|
-
$ bundle
|
26
|
-
```
|
44
|
+
或无需引用Gem直接发起Post请求:
|
27
45
|
|
28
|
-
Or install it yourself as:
|
29
46
|
```bash
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
## License
|
37
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
47
|
+
curl --location --request POST '123.57.155.17:3114/wireway/restful/request_api' \
|
48
|
+
--header 'Content-Type: application/x-www-form-urlencoded' \
|
49
|
+
--data-urlencode 'platform=satcom' \
|
50
|
+
--data-urlencode 'api_code=finance_fund_base_info' \
|
51
|
+
--data-urlencode 'code=161725'
|
52
|
+
```
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Wireway
|
2
|
+
class RestfulController < ApplicationController
|
3
|
+
def request_api
|
4
|
+
# TODO 初步了解为rails5的安全机制 去除存在风险 暂时先这样
|
5
|
+
args = params.permit!.to_hash.reject!{|key| ["action", "controller"].include?(key)}.deep_symbolize_keys
|
6
|
+
|
7
|
+
res = Wireway::Spark.send(args[:platform], args)
|
8
|
+
tmp = {success: res[0], result: res[1]}
|
9
|
+
(tmp.merge!(res[2]) rescue nil) if res[2].present?
|
10
|
+
render json: tmp.merge!(tmp)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -3,61 +3,105 @@ module Wireway
|
|
3
3
|
module Restful
|
4
4
|
extend self
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
$wireway_node_addresses = 404
|
7
|
+
|
8
|
+
# 后期应由专门组件对于已登记地址信息进行活跃验证,并将可用节点信息回传给Satcom
|
9
|
+
# 后期当某一节点调用不通过时将常量赋值为404进行更新
|
10
|
+
# url路径不需要动态获取,只有ip和端口是动态的,如果请求路径都不一致,不能认为是合规的节点.
|
11
|
+
def node_addresses
|
12
|
+
return $wireway_node_addresses unless $wireway_node_addresses == 404
|
13
|
+
|
14
|
+
nodes = ['123.57.155.17:3113']
|
15
|
+
route = '/satcom/other/c919/node_addresses.json'
|
16
|
+
res = get(addresses: nodes, route: route) do |result|
|
17
|
+
hash = JSON.parse(result[1][:body]).deep_symbolize_keys
|
18
|
+
[true, hash]
|
19
|
+
end
|
20
|
+
|
21
|
+
return res unless res[0]
|
22
|
+
$wireway_node_addresses = res[1].map{|key, value| [key, value[:nodes]]}.to_h
|
12
23
|
end
|
13
24
|
|
14
25
|
def dashboard(**args)
|
15
26
|
params = {
|
16
27
|
response_type: 'json',
|
17
28
|
}.merge!(args)
|
18
|
-
|
19
|
-
url = 'http://172.28.81.156:3111/dashboard/restful/request_api'
|
29
|
+
route = '/dashboard/restful/request_api'
|
20
30
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
[true, body['html_content']]
|
31
|
+
post(addresses: node_addresses[:dashboard], route: route, params: params) do |result|
|
32
|
+
return result if (params[:response_type] != 'json')
|
33
|
+
body = JSON.parse(result[1][:body]).deep_symbolize_keys
|
34
|
+
return [false, body[:result]] unless body[:success]
|
35
|
+
[true, body[:html_content]]
|
36
|
+
end
|
28
37
|
end
|
29
38
|
|
30
39
|
def satcom(**args)
|
31
|
-
params = {
|
32
|
-
|
33
|
-
|
34
|
-
url = 'http://172.28.81.156:3113/satcom/restful/request_api'
|
40
|
+
params = {}.merge!(args)
|
41
|
+
route = '/satcom/restful/request_api'
|
35
42
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
[true, body[:result]]
|
43
|
+
post(addresses: node_addresses[:satcom], route: route, params: params) do |result|
|
44
|
+
body = JSON.parse(result[1][:body]).deep_symbolize_keys
|
45
|
+
return [false, body[:result], body[:errors]].compact unless body[:success]
|
46
|
+
[true, body[:result]]
|
47
|
+
end
|
43
48
|
end
|
44
49
|
|
50
|
+
def wireway(**args)
|
51
|
+
params = {
|
52
|
+
local: false
|
53
|
+
}.merge!(args)
|
54
|
+
route = '/wireway/restful/request_api'
|
55
|
+
|
56
|
+
post(addresses: node_addresses[:wireway], route: route, params: params) do |result|
|
57
|
+
body = JSON.parse(result[1][:body]).deep_symbolize_keys
|
58
|
+
return [false, body[:result], body[:errors]].compact unless body[:success]
|
59
|
+
[true, body[:result]]
|
60
|
+
end
|
61
|
+
end
|
45
62
|
|
46
|
-
def get(
|
47
|
-
|
48
|
-
full_url = [
|
63
|
+
def get(addresses:, route:, params: {})
|
64
|
+
result = round_robin(addresses: addresses) do |address|
|
65
|
+
full_url = [address+route, URI.encode_www_form(params)]
|
49
66
|
full_url.delete_if{|item| !item.present? }
|
50
67
|
RestClient.get(full_url.join("?"))
|
51
68
|
end
|
69
|
+
return result unless (result[0] && block_given?)
|
70
|
+
|
71
|
+
begin
|
72
|
+
yield result
|
73
|
+
rescue
|
74
|
+
return [false, '运行时结果处理异常', {errors: {message: $!.to_s, path: $@}}]
|
75
|
+
end
|
52
76
|
end
|
53
77
|
|
54
|
-
def post(
|
55
|
-
|
56
|
-
RestClient.post
|
78
|
+
def post(addresses:, route:, params: {})
|
79
|
+
result = round_robin(addresses: addresses) do |address|
|
80
|
+
RestClient.post "#{address}/#{route}", params
|
81
|
+
end
|
82
|
+
return result unless (result[0] && block_given?)
|
83
|
+
|
84
|
+
begin
|
85
|
+
yield result
|
86
|
+
rescue
|
87
|
+
return [false, '运行时结果处理异常', {errors: {message: $!.to_s, path: $@}}]
|
57
88
|
end
|
58
89
|
end
|
59
90
|
|
60
91
|
private
|
92
|
+
def round_robin(addresses:)
|
93
|
+
res = nil
|
94
|
+
addresses.each do |address|
|
95
|
+
res = get_response do
|
96
|
+
yield address
|
97
|
+
end
|
98
|
+
# TODO: 后期应该优化判断是服务不可以用还是传递参数问题倒是返回false
|
99
|
+
# 或者当一定比例节点均无法正常响应时即判定为参数问题
|
100
|
+
break if res[0]
|
101
|
+
end
|
102
|
+
res
|
103
|
+
end
|
104
|
+
|
61
105
|
def get_response
|
62
106
|
begin
|
63
107
|
response = yield
|
data/app/models/wireway/spark.rb
CHANGED
@@ -3,10 +3,21 @@ module Wireway
|
|
3
3
|
|
4
4
|
# Wireway::Spark.dashboard(api_code: :publish_other_request_assets, rely_assets: ["bootstrap_4", "jQuery_3_5_1", "chart_js"])
|
5
5
|
# Wireway::Spark.satcom(api_code: :finance_fund_base_info, code: '161725')
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
# Wireway::BusinessLogic::Restful::node_addresses
|
7
|
+
# Wireway::Spark.wireway(platform: :satcom, api_code: :finance_fund_base_info, code: '161725')
|
8
|
+
def self.method_missing(method_name, local: true, **args)
|
9
|
+
begin
|
10
|
+
target = Wireway::BusinessLogic::Restful
|
11
|
+
return [false, '未找到相关定义方法'] unless target.respond_to?(method_name)
|
12
|
+
res = target.send(method_name, args)
|
13
|
+
rescue
|
14
|
+
error_msg = [false, '请求异常', {errors: {message: $!.to_s, path: $@}}]
|
15
|
+
return error_msg unless [true, 'true', 1, '1', 'yes'].include?(local)
|
16
|
+
# 当以Gem形式的组件无法处理请求时,尝试请求线上版组件是否可以正常处理请求
|
17
|
+
# 即当gem出现问题时会请求线上服务 有利于断点排查
|
18
|
+
args.merge!(platform: method_name)
|
19
|
+
res = target.wireway(args)
|
20
|
+
end
|
10
21
|
end
|
11
22
|
|
12
23
|
end
|
data/config/routes.rb
CHANGED
data/lib/wireway/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wireway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '202012021551'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ff4c00
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -72,7 +72,7 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 3.9.0
|
75
|
-
description:
|
75
|
+
description: 用于反向代理C919各组件,实现组件间组网协作.
|
76
76
|
email:
|
77
77
|
- ff4c00@gmail.com
|
78
78
|
executables: []
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- app/assets/javascripts/wireway/application.js
|
87
87
|
- app/assets/stylesheets/wireway/application.css
|
88
88
|
- app/controllers/wireway/application_controller.rb
|
89
|
+
- app/controllers/wireway/restful_controller.rb
|
89
90
|
- app/helpers/wireway/application_helper.rb
|
90
91
|
- app/jobs/wireway/application_job.rb
|
91
92
|
- app/mailers/wireway/application_mailer.rb
|