raas-client-rails 0.1.13 → 0.1.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 189e68f5001082d0fb193bc6b1b404a5369df1accf7588eafc006c59f9279005
4
- data.tar.gz: db02286e699cc2ec5e68dcbb0a4b3a3af16b3ef18eacafe7613fa23e54ee817e
3
+ metadata.gz: ca4ff64b4c70136dbf4ccd69808433e19add4d47701ab771a621907804b6b47a
4
+ data.tar.gz: d127857aee5259e12f897500a631dcc5e8fc9822de18bd65d6a3838ac98cb58a
5
5
  SHA512:
6
- metadata.gz: 9704abd258f891323bf8bd504cab7faa283ac89d930d9b04723c91a0e1693c0781a87fb229a10c7264be4af9c8bfed6868c6951ae0dc0e8e132db06863589922
7
- data.tar.gz: 58af69c741721b52a556f3fe2b7fef4f82d70863bf9c88f19fc0423d48c10c276044ffb8af8e7fa88ad09d71565ea3e5dec4eda47f986ed51b9a666d87537486
6
+ metadata.gz: 8aba273926ea2e74d972dfc769cb092d8e802687010e5aa97ca4f5ef7ff85f8517f40fb8fb8be57e90b41821be581aca1aca05a4383427999dcdf0be3ca076a6
7
+ data.tar.gz: 5d6ebf9757f6dc9c20e68303056d78a7c5e65fb987b812da03e9a6f584a7e7da524b7d5d5c96eab47f9cc3873761a2ba9ef53d9fd46e8f5a0013275024e1e129
data/README.md CHANGED
@@ -26,6 +26,10 @@ Once you install gem and set it up, your application has several extra endpoints
26
26
  - `/raas/report/session` : Generate external session by using your credentials for report
27
27
  - `/raas/datatraveler/session` : Generate external session by using your credentials for datatraveler
28
28
 
29
+ Both session APIs accept an optional `scope` parameter (space-delimited, e.g. `csv_admin.invoice pdf.invoice`)
30
+ for scope-based route restriction. You can also fix it on the server side by setting `@scope`
31
+ in your `prepare_tenant_and_sub` override (see below). If omitted, nothing is sent and the behavior is unchanged.
32
+
29
33
  ## Installation
30
34
 
31
35
  The client is provided as [RubyGem](https://rubygems.org/gems/raas-client-rails),
@@ -54,6 +58,9 @@ class RaasController < Raas::Client::Rails::RaasController
54
58
 
55
59
  @tenant = "xxxxx"
56
60
  @sub = "xxxx"
61
+ # Optional: scopes granted to the current user (space-delimited).
62
+ # Used for scope-based route restriction on RaaS side.
63
+ # @scope = "csv_admin.invoice pdf.invoice"
57
64
  end
58
65
  end
59
66
  ```
@@ -17,7 +17,7 @@ module Raas::Client::Rails
17
17
  @backUrl = params[:backUrl]
18
18
  @subUrl = params[:subUrl]
19
19
  prepare_tenant_and_sub()
20
- @restClient = RestClient.new(@tenant, @sub, @tenant_alias, @sub_alias, @sub_domain)
20
+ @restClient = RestClient.new(@tenant, @sub, @tenant_alias, @sub_alias, @sub_domain, @scope)
21
21
  end
22
22
 
23
23
  def prepare_tenant_and_sub()
@@ -27,6 +27,7 @@ module Raas::Client::Rails
27
27
  @tenant_alias = params[:tenantAlias]
28
28
  @sub_alias = params[:subAlias]
29
29
  @sub_domain = params[:subDomain]
30
+ @scope = params[:scope]
30
31
  end
31
32
 
32
33
  def report_session()
@@ -66,9 +67,9 @@ module Raas::Client::Rails
66
67
  if type.nil?
67
68
  type = "application/pdf"
68
69
  end
69
- #by default empty Hash if nothing is assigned
70
+ #by default no query parameter if nothing is assigned
70
71
  if parameters.nil?
71
- payload = Hash.new
72
+ payload = nil
72
73
  else
73
74
  payload = parameters
74
75
  end
@@ -79,14 +80,16 @@ module Raas::Client::Rails
79
80
 
80
81
  # How you return the value? This can be changed by passing mimeType through parameter
81
82
  def handleMime(mimeType, fileName,type, response)
83
+ #上流のHTTPステータス(403/404等)をそのままクライアントへ返す
84
+ status = response.code.to_i
82
85
  case mimeType
83
86
  when MIME_TYPE_HTML
84
87
  #sanitize response automatically
85
- render html: response.body
88
+ render html: response.body, status: status
86
89
  when MIME_TYPE_JSON
87
- render json: response.body
90
+ render json: response.body, status: status
88
91
  when MIME_TYPE_FILE
89
- send_data(response, filename: fileName, type: type)
92
+ send_data(response, filename: fileName, type: type, status: status)
90
93
  end
91
94
  # p "#{fileName} #{type} #{mimeType}"
92
95
  end
@@ -102,7 +105,8 @@ module Raas::Client::Rails
102
105
  payload = JSON.parse(parameters)
103
106
  end
104
107
  Rails.logger.warn("delete path=#{path} parameters=#{parameters}");
105
- return @restClient.delete(path,payload)
108
+ response = @restClient.delete(path,payload)
109
+ render json: response.body, status: response.code.to_i
106
110
  end
107
111
 
108
112
  #/raas/post
@@ -117,7 +121,7 @@ module Raas::Client::Rails
117
121
  end
118
122
  Rails.logger.warn("post path=#{path} requestBody=#{requestBody}");
119
123
  response = @restClient.post(path,payload)
120
- return response.body;
124
+ render json: response.body, status: response.code.to_i
121
125
  end
122
126
 
123
127
  #/raas/put
@@ -132,7 +136,7 @@ module Raas::Client::Rails
132
136
  end
133
137
  Rails.logger.warn("post path=#{path} requestBody=#{requestBody}");
134
138
  response = @restClient.put(path,payload)
135
- return response.body;
139
+ render json: response.body, status: response.code.to_i
136
140
  end
137
141
 
138
142
  end
@@ -12,7 +12,7 @@ module Raas::Client::Rails
12
12
  DELETE = "delete"
13
13
  APEX_DOMAIN = "functions.asaservice.inc";
14
14
 
15
- def initialize(tenant, sub, tenant_alias, sub_alias, sub_domain)
15
+ def initialize(tenant, sub, tenant_alias, sub_alias, sub_domain, scope = nil)
16
16
  @application = Raas::Client::Rails::Engine.config.raas_client_rails.application
17
17
  @landscape = Raas::Client::Rails::Engine.config.raas_client_rails.landscape
18
18
  @token = Raas::Client::Rails::Engine.config.raas_client_rails.token
@@ -21,6 +21,7 @@ module Raas::Client::Rails
21
21
  @tenant_alias = tenant_alias
22
22
  @sub_alias = sub_alias
23
23
  @sub_domain = sub_domain
24
+ @scope = scope
24
25
  end
25
26
 
26
27
  def createExternalSession(msa,backUrl,subUrl,subDomain)
@@ -39,8 +40,9 @@ module Raas::Client::Rails
39
40
  body["tenantAlias"] = @tenant_alias
40
41
  end
41
42
  if @sub_alias
42
- body["subAlias"] = @sub_alias
43
+ body["subAlias"] = @sub_alias
43
44
  end
45
+ body["scope"] = @scope if @scope
44
46
  return body
45
47
  end
46
48
 
@@ -49,16 +51,24 @@ module Raas::Client::Rails
49
51
  Rails.logger.debug("[TRACE] getUserToken is started");
50
52
  #Use Rails default cache system, this simply use cache otherwise fetch and store
51
53
  Rails.logger.debug("Attempt to recycle token");
52
- cacheName = "#{@tenant}+++#{@sub}"
54
+ # scope 付きトークンは scope 単位でキャッシュし、切り替え時に再取得する
55
+ if @scope
56
+ cacheName = "#{@tenant}+++#{@sub}+++#{@scope}"
57
+ else
58
+ cacheName = "#{@tenant}+++#{@sub}"
59
+ end
53
60
  Rails.logger.debug("Cache name is #{cacheName}")
54
61
  # p cacheName
55
- return token = Rails.cache.fetch(cacheName) do
56
- Rails.logger.debug("No cache found, fetch it by api");
57
- Rails.logger.debug("tenant #=> #{@tenant} / sub #=> #{@sub}")
58
- response = getUserTokenImpl("report");
59
- Rails.logger.debug(response.body)
60
- return JSON.parse(response.body);
61
- end
62
+ cached = Rails.cache.read(cacheName)
63
+ return cached if cached
64
+ Rails.logger.debug("No cache found, fetch it by api");
65
+ Rails.logger.debug("tenant #=> #{@tenant} / sub #=> #{@sub}")
66
+ response = getUserTokenImpl("report");
67
+ Rails.logger.debug(response.body)
68
+ json = JSON.parse(response.body);
69
+ # エラー応答 (invalid_scope の 400 等) を永続キャッシュしないよう成功時のみ保存する
70
+ Rails.cache.write(cacheName, json) if response.is_a?(Net::HTTPSuccess)
71
+ return json
62
72
  end
63
73
 
64
74
  # fetch token from RaaS because no cache
@@ -98,7 +108,8 @@ module Raas::Client::Rails
98
108
  url = URI.parse(uri)
99
109
  unless params.nil?
100
110
  #should I do like this!?
101
- parameters_hash = params.to_unsafe_h
111
+ # ActionController::Parameters 以外 (素の Hash) で渡されることもある
112
+ parameters_hash = params.respond_to?(:to_unsafe_h) ? params.to_unsafe_h : params
102
113
  url.query = URI.encode_www_form(parameters_hash) unless params.nil?
103
114
  end
104
115
  # replacing context path form urI to match actual gateway URI
@@ -1,7 +1,7 @@
1
1
  module Raas
2
2
  module Client
3
3
  module Rails
4
- VERSION = "0.1.13"
4
+ VERSION = "0.1.15"
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.13
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunao Suzuki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-20 00:00:00.000000000 Z
11
+ date: 2026-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails