raas-client-rails 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6c4f44354fc42a8fe599680f73fef59c0120d9265a05661ae3eea7b8c527af4
4
- data.tar.gz: c83b4968c3f023ebd3cfcb2e2fb82e6eb12eb7126906a52bff7e7a869249c04b
3
+ metadata.gz: 87ef9e3d0ac5352f339eb54381946d31c686e346624ed8ea2f83d2d6af828eca
4
+ data.tar.gz: dfc5e841be021daf7765872d278a911f8e5a0342700284d7d063e4b3b4411059
5
5
  SHA512:
6
- metadata.gz: accb3436b7087aa5827111d34af8fc481f40ccd7b0ff71e3a506bccda38c0a2d078f5258664b9e280c04e73af6db8c5fe76d0aa7a27e928b38985cb3632fd492
7
- data.tar.gz: 32f79a1e62cedb106d5ac87671f9d59452732daf63a1dd700890b87d8de3d1700e4fe35ad525f23b657f9288e4a3e0e5637aad4062101d502cb4dc304eaa2096
6
+ metadata.gz: 0b030baa89b5745cecae093dbb066bd1c3bc032926571162695c67cb9631b204189b68fd9c10fdc56f011b5349e23fb57d1c413ae9856e1f4c47fd7f0ffd4b0b
7
+ data.tar.gz: f762f6cd1d17d6708db7c32dd9244d8619a9ddf80fc02fd24b3050e69b794aa2a4917d41fa5bb1873b3019add43c19e558b22bb01706dfd5b96116b07fbf3fd1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Raas::Client::Rails
2
2
 
3
- Adding extra endpoints to access RaaS. These endpoints allows you to fetch external token to access RaaS or enables you to invoke specific functions through them.
3
+ Adding client to access Raas. This client allows you to call Raas API.
4
4
 
5
5
  ## Usage
6
6
 
@@ -21,11 +21,10 @@ This condifuration is **mandatory** please, do not forget before you start inter
21
21
 
22
22
  ### APIs
23
23
 
24
- Once you install your gem, your application has several extra endpoints to interact with RaaS.
24
+ Once you install gem and set it up, your application has several extra endpoints to interact with RaaS.
25
25
 
26
26
  - `/raas/report/session` : Generate external session by using your credentials for report
27
- - `/raas/datatraveler/session` : Generate external session by using your credentials for report
28
- - `/raas/health` : Ask RaaS to get current health condition
27
+ - `/raas/datatraveler/session` : Generate external session by using your credentials for datatraveler
29
28
 
30
29
  ## Installation
31
30
 
@@ -44,17 +43,34 @@ gem "raas-client-rails"
44
43
  $ bundle install
45
44
  ```
46
45
 
47
- 3. mount endPoint on `config/routes.rb`
46
+ 3. implement raas_controller.rb
48
47
 
49
48
  ```ruby
50
- mount Raas::Client::Rails::Engine => "[PATH]"
49
+ class RaasController < Raas::Client::Rails::RaasController
50
+ skip_before_action :verify_authenticity_token
51
+
52
+ def prepare_tenant_and_sub
53
+ super
54
+
55
+ @tenant = "xxxxx"
56
+ @sub = "xxxx"
57
+ end
58
+ end
59
+ ```
60
+
61
+ 3. add endPoint on `config/routes.rb`
62
+
63
+ ```ruby
64
+ post '/raas/datatraveler/session', to: 'raas#datatraveler_session'
65
+ post '/raas/report/session', to: 'raas#report_session'
51
66
  ```
52
67
 
53
68
  4. Launch your rails server
54
69
 
55
70
  5. then you can use this with...
56
71
 
57
- `/PATH/raas/endPointList`
72
+ `/raas/datatraveler/session`
73
+ `/raas/report/session`
58
74
 
59
75
  ## License
60
76
  All the patents belong to SuTech
@@ -1,135 +1,8 @@
1
1
  module Raas::Client::Rails
2
-
3
- require_relative 'rest_client'
4
2
 
5
- class RaasController < ApplicationController
6
-
7
- MSA_REPORT = "report";
8
- MSA_DT = "datatraveler";
9
-
10
- #/raas/health
11
- def health()
12
- prepare(params)
13
- render plain: "Moving #{@tenant}/#{@sub}";
14
- end
15
-
16
- def prepare(params)
17
- # seven arguments are needed to make this work
18
- application = Raas::Client::Rails::Engine.config.raas_client_rails.application
19
- landscape = Raas::Client::Rails::Engine.config.raas_client_rails.landscape
20
- token = Raas::Client::Rails::Engine.config.raas_client_rails.token
21
- @backUrl = params[:backUrl]
22
- @subUrl = params[:subUrl]
23
- @tenant = params[:tenant]
24
- @sub = params[:sub]
25
- @restClient = RestClient.new(application,landscape,token)
26
- end
27
-
28
- def report_session()
29
- Rails.logger.warn("session parameter=#{params}");
30
- prepare(params)
31
- response = @restClient.createExternalSession(MSA_REPORT,@backUrl,@subUrl,@tenant,@sub)
32
- render json: response.body
33
- end
34
-
35
- def datatraveler_session()
36
- Rails.logger.warn("session parameter=#{params}")
37
- prepare(params)
38
- response = @restClient.createExternalSession(MSA_DT,@backUrl,@subUrl,@tenant,@sub)
39
- render json: response.body
40
- end
41
-
42
- MIME_TYPE_HTML = "html"
43
- MIME_TYPE_FILE = "file"
44
- MIME_TYPE_JSON = "json"
45
-
46
- #/raas/get
47
- def get()
48
- prepare(params)
49
- path = params[:path]
50
- parameters = params[:parameters]
51
- mimeType = params[:mimeType]
52
- fileName = params[:fileName]
53
- type = params[:type]
54
- #by default return HTML
55
- if mimeType.nil?
56
- mimeType = MIME_TYPE_HTML
57
- end
58
- #by default return download.pdf
59
- if fileName.nil?
60
- fileName = "download"
61
- end
62
- if type.nil?
63
- type = "application/pdf"
64
- end
65
- #by default empty Hash if nothing is assigned
66
- if parameters.nil?
67
- payload = Hash.new
68
- else
69
- payload = parameters
70
- end
71
- Rails.logger.warn("get path=#{path} parameters=#{payload}");
72
- response = @restClient.get(path,payload,@tenant,@sub)
73
- handleMime(mimeType, fileName, type, response)
74
- end
75
-
76
- # How you return the value? This can be changed by passing mimeType through parameter
77
- def handleMime(mimeType, fileName,type, response)
78
- case mimeType
79
- when MIME_TYPE_HTML
80
- #sanitize response automatically
81
- render html: response.body
82
- when MIME_TYPE_JSON
83
- render json: response.body
84
- when MIME_TYPE_FILE
85
- send_data(response, filename: fileName, type: type)
86
- end
87
- # p "#{fileName} #{type} #{mimeType}"
88
- end
89
-
90
- #/raas/delete
91
- def delete()
92
- prepare(params)
93
- path = params[:path]
94
- parameters = params[:parameters]
95
- if parameters.nil?
96
- payload = nil
97
- else
98
- payload = JSON.parse(parameters)
99
- end
100
- Rails.logger.warn("delete path=#{path} parameters=#{parameters}");
101
- return @restClient.delete(path,payload,@tenant,@sub)
102
- end
103
-
104
- #/raas/post
105
- def post()
106
- prepare(params)
107
- path = params[:path]
108
- requestBody = params[:requestbody]
109
- if requestBody.nil?
110
- payload = nil
111
- else
112
- payload = JSON.parse(requestBody)
113
- end
114
- Rails.logger.warn("post path=#{path} requestBody=#{requestBody}");
115
- response = @restClient.post(path,payload,@tenant,@sub)
116
- return response.body;
117
- end
118
-
119
- #/raas/put
120
- def put()
121
- prepare(params)
122
- path = params[:path]
123
- requestBody = params[:requestbody]
124
- if requestBody.nil?
125
- payload = nil
126
- else
127
- payload = JSON.parse(requestBody)
128
- end
129
- Rails.logger.warn("post path=#{path} requestBody=#{requestBody}");
130
- response = @restClient.put(path,payload,@tenant,@sub)
131
- return response.body;
132
- end
3
+ require_relative 'raas_controller_module'
133
4
 
5
+ class RaasController < ApplicationController
6
+ include RaasControllerModule
134
7
  end
135
8
  end
@@ -0,0 +1,136 @@
1
+ module Raas::Client::Rails
2
+
3
+ require_relative 'rest_client'
4
+
5
+ class RaasController < ApplicationController
6
+
7
+ MSA_REPORT = "report";
8
+ MSA_DT = "datatraveler";
9
+
10
+ #/raas/health
11
+ def health()
12
+ prepare(params)
13
+ render plain: "Moving #{@tenant}/#{@sub}";
14
+ end
15
+
16
+ def prepare(params)
17
+ @backUrl = params[:backUrl]
18
+ @subUrl = params[:subUrl]
19
+ prepare_tenant_and_sub()
20
+ @restClient = RestClient.new(@tenant, @sub)
21
+ end
22
+
23
+ def prepare_tenant_and_sub()
24
+ # For Overload
25
+ @tenant = params[:tenant]
26
+ @sub = params[:sub]
27
+ end
28
+
29
+ def report_session()
30
+ Rails.logger.warn("session parameter=#{params}");
31
+ prepare(params)
32
+ response = @restClient.createExternalSession(MSA_REPORT,@backUrl,@subUrl)
33
+ render json: response.body
34
+ end
35
+
36
+ def datatraveler_session()
37
+ Rails.logger.warn("session parameter=#{params}")
38
+ prepare(params)
39
+ response = @restClient.createExternalSession(MSA_DT,@backUrl,@subUrl)
40
+ render json: response.body
41
+ end
42
+
43
+ MIME_TYPE_HTML = "html"
44
+ MIME_TYPE_FILE = "file"
45
+ MIME_TYPE_JSON = "json"
46
+
47
+ #/raas/get
48
+ def get()
49
+ prepare(params)
50
+ path = params[:path]
51
+ parameters = params[:parameters]
52
+ mimeType = params[:mimeType]
53
+ fileName = params[:fileName]
54
+ type = params[:type]
55
+ #by default return HTML
56
+ if mimeType.nil?
57
+ mimeType = MIME_TYPE_HTML
58
+ end
59
+ #by default return download.pdf
60
+ if fileName.nil?
61
+ fileName = "download"
62
+ end
63
+ if type.nil?
64
+ type = "application/pdf"
65
+ end
66
+ #by default empty Hash if nothing is assigned
67
+ if parameters.nil?
68
+ payload = Hash.new
69
+ else
70
+ payload = parameters
71
+ end
72
+ Rails.logger.warn("get path=#{path} parameters=#{payload}");
73
+ response = @restClient.get(path,payload)
74
+ handleMime(mimeType, fileName, type, response)
75
+ end
76
+
77
+ # How you return the value? This can be changed by passing mimeType through parameter
78
+ def handleMime(mimeType, fileName,type, response)
79
+ case mimeType
80
+ when MIME_TYPE_HTML
81
+ #sanitize response automatically
82
+ render html: response.body
83
+ when MIME_TYPE_JSON
84
+ render json: response.body
85
+ when MIME_TYPE_FILE
86
+ send_data(response, filename: fileName, type: type)
87
+ end
88
+ # p "#{fileName} #{type} #{mimeType}"
89
+ end
90
+
91
+ #/raas/delete
92
+ def delete()
93
+ prepare(params)
94
+ path = params[:path]
95
+ parameters = params[:parameters]
96
+ if parameters.nil?
97
+ payload = nil
98
+ else
99
+ payload = JSON.parse(parameters)
100
+ end
101
+ Rails.logger.warn("delete path=#{path} parameters=#{parameters}");
102
+ return @restClient.delete(path,payload)
103
+ end
104
+
105
+ #/raas/post
106
+ def post()
107
+ prepare(params)
108
+ path = params[:path]
109
+ requestBody = params[:requestbody]
110
+ if requestBody.nil?
111
+ payload = nil
112
+ else
113
+ payload = JSON.parse(requestBody)
114
+ end
115
+ Rails.logger.warn("post path=#{path} requestBody=#{requestBody}");
116
+ response = @restClient.post(path,payload)
117
+ return response.body;
118
+ end
119
+
120
+ #/raas/put
121
+ def put()
122
+ prepare(params)
123
+ path = params[:path]
124
+ requestBody = params[:requestbody]
125
+ if requestBody.nil?
126
+ payload = nil
127
+ else
128
+ payload = JSON.parse(requestBody)
129
+ end
130
+ Rails.logger.warn("post path=#{path} requestBody=#{requestBody}");
131
+ response = @restClient.put(path,payload)
132
+ return response.body;
133
+ end
134
+
135
+ end
136
+ end
@@ -12,21 +12,20 @@ module Raas::Client::Rails
12
12
  DELETE = "delete"
13
13
  APEX_DOMAIN = "functions.asaservice.inc";
14
14
 
15
- def initialize(application,landscape,token)
16
- @application = application
17
- @landscape = landscape
18
- @token = token
15
+ def initialize(tenant, sub)
16
+ @application = Raas::Client::Rails::Engine.config.raas_client_rails.application
17
+ @landscape = Raas::Client::Rails::Engine.config.raas_client_rails.landscape
18
+ @token = Raas::Client::Rails::Engine.config.raas_client_rails.token
19
+ @tenant = tenant
20
+ @sub = sub
19
21
  end
20
22
 
21
- # ResponseEntity<String> resp = raasClient.createExternalSession(Constant.MSA_REPORT,req.getBackUrl(),req.getSubUrl(), saasContextProvider.getTenant(), saasContextProvider.getSub());
22
-
23
-
24
- def createExternalSession(msa,backUrl,subUrl,tenant,sub)
23
+ def createExternalSession(msa,backUrl,subUrl)
25
24
  body = Hash.new
26
25
  body["backUrl"] = backUrl
27
26
  body["subUrl"] = subUrl
28
- body["tenant"] = tenant
29
- body["sub"] = sub
27
+ body["tenant"] = @tenant
28
+ body["sub"] = @sub
30
29
  return proxy(body,POST,"/#{msa}/external/session",nil,@token)
31
30
  end
32
31
 
@@ -36,51 +35,41 @@ module Raas::Client::Rails
36
35
  #Use Rails default cache system, this simply use cache otherwise fetch and store
37
36
  Rails.logger.debug("Attempt to recycle token");
38
37
  cacheName = "#{@tenant}+++#{@sub}"
39
- @@t = @tenant
40
- @@s = @sub
41
38
  Rails.logger.debug("Cache name is #{cacheName}")
42
39
  # p cacheName
43
40
  return token = Rails.cache.fetch(cacheName) do
44
41
  Rails.logger.debug("No cache found, fetch it by api");
45
- Rails.logger.debug("tenant #=> #{@@t} / sub #=> #{@@s}")
46
- response = getUserTokenImpl( "report" , @@t , @@s);
42
+ Rails.logger.debug("tenant #=> #{@tenant} / sub #=> #{@sub}")
43
+ response = getUserTokenImpl("report");
47
44
  Rails.logger.debug(response.body)
48
45
  return JSON.parse(response.body);
49
46
  end
50
47
  end
51
48
 
52
49
  # fetch token from RaaS because no cache
53
- def getUserTokenImpl(msa,tenant,sub)
50
+ def getUserTokenImpl(msa)
54
51
  body = Hash.new
55
- body["tenant"] = tenant
56
- body["sub"] = sub
52
+ body["tenant"] = @tenant
53
+ body["sub"] = @sub
57
54
  response = proxy(body,POST,"/#{msa}/external/token",nil,@token);
58
55
  end
59
56
 
60
- def get(requestUrl, params,tenant,sub)
61
- @tenant = tenant
62
- @sub = sub
57
+ def get(requestUrl, params)
63
58
  json = getUserToken()
64
59
  return proxy(nil, GET,requestUrl,params,json["token"]);
65
60
  end
66
61
 
67
- def delete(requestUrl, params,tenant,sub)
68
- @tenant = tenant
69
- @sub = sub
62
+ def delete(requestUrl, params)
70
63
  json = getUserToken()
71
64
  return proxy(nil, DELETE,requestUrl,params,json["token"]);
72
65
  end
73
66
 
74
- def put(requestUrl,body,tenant,sub)
75
- @tenant = tenant
76
- @sub = sub
67
+ def put(requestUrl,body)
77
68
  json = getUserToken()
78
69
  return proxy(body , PUT,requestUrl,nil,json["token"]);
79
70
  end
80
71
 
81
- def post(requestUrl,body,tenant,sub)
82
- @tenant = tenant
83
- @sub = sub
72
+ def post(requestUrl,body)
84
73
  json = getUserToken()
85
74
  return proxy(body , POST,requestUrl,nil,json["token"]);
86
75
  end
@@ -1,7 +1,7 @@
1
1
  module Raas
2
2
  module Client
3
3
  module Rails
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raas-client-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunao Suzuki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-20 00:00:00.000000000 Z
11
+ date: 2023-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,6 +38,7 @@ files:
38
38
  - app/assets/stylesheets/raas/client/rails/application.css
39
39
  - app/controllers/raas/client/rails/application_controller.rb
40
40
  - app/controllers/raas/client/rails/raas_controller.rb
41
+ - app/controllers/raas/client/rails/raas_controller_module.rb
41
42
  - app/controllers/raas/client/rails/rest_client.rb
42
43
  - app/helpers/raas/client/rails/application_helper.rb
43
44
  - app/helpers/raas/client/rails/raa_s_helper.rb