et_ccd_client 0.3.1
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +200 -0
- data/.rubocop_todo.yml +7 -0
- data/.ruby-version +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +91 -0
- data/LICENSE.txt +21 -0
- data/README.md +95 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/et_ccd_client.gemspec +37 -0
- data/lib/et_ccd_client.rb +18 -0
- data/lib/et_ccd_client/client.rb +291 -0
- data/lib/et_ccd_client/common_rest_client.rb +27 -0
- data/lib/et_ccd_client/common_rest_client_with_login.rb +33 -0
- data/lib/et_ccd_client/config.rb +108 -0
- data/lib/et_ccd_client/exceptions.rb +2 -0
- data/lib/et_ccd_client/exceptions/base.rb +52 -0
- data/lib/et_ccd_client/exceptions/forbidden.rb +6 -0
- data/lib/et_ccd_client/exceptions/gateway_timeout.rb +6 -0
- data/lib/et_ccd_client/exceptions/internal_server_error.rb +6 -0
- data/lib/et_ccd_client/exceptions/not_found.rb +13 -0
- data/lib/et_ccd_client/exceptions/unauthorized.rb +6 -0
- data/lib/et_ccd_client/exceptions/unprocessable_entity.rb +18 -0
- data/lib/et_ccd_client/idam_client.rb +57 -0
- data/lib/et_ccd_client/null_logger.rb +100 -0
- data/lib/et_ccd_client/tidam_client.rb +64 -0
- data/lib/et_ccd_client/ui_client.rb +159 -0
- data/lib/et_ccd_client/ui_idam_client.rb +40 -0
- data/lib/et_ccd_client/ui_remote_config.rb +23 -0
- data/lib/et_ccd_client/uploaded_file.rb +36 -0
- data/lib/et_ccd_client/version.rb +3 -0
- metadata +251 -0
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "et_ccd_client"
|
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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "et_ccd_client/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "et_ccd_client"
|
8
|
+
spec.version = EtCcdClient::VERSION
|
9
|
+
spec.authors = ["Gary Taylor"]
|
10
|
+
spec.email = ["gary.taylor@hmcts.net"]
|
11
|
+
|
12
|
+
spec.summary = %q{A client to communicate with the employment tribunals CCD system}
|
13
|
+
spec.description = %q{This client implements methods to call the relevant CCD endpoints for the employment tribunals CCD system}
|
14
|
+
spec.homepage = "https://github.com/hmcts/et-ccd-client-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency 'addressable', '~> 2.6'
|
27
|
+
spec.add_dependency 'rest-client', '~> 2.0', '>= 2.0.2'
|
28
|
+
spec.add_dependency 'webmock', '~> 3.6'
|
29
|
+
spec.add_dependency 'rotp', '~> 6.0'
|
30
|
+
spec.add_dependency 'connection_pool', '~> 2.2', '>= 2.2.2'
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_development_dependency 'rubocop', '~> 0.71.0'
|
35
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.33'
|
36
|
+
spec.add_development_dependency 'rack', '~> 2.0', '>= 2.0.7'
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "et_ccd_client/version"
|
2
|
+
require 'et_ccd_client/null_logger'
|
3
|
+
require 'et_ccd_client/config'
|
4
|
+
require 'et_ccd_client/idam_client'
|
5
|
+
require 'et_ccd_client/tidam_client'
|
6
|
+
require 'et_ccd_client/client'
|
7
|
+
require 'et_ccd_client/ui_client'
|
8
|
+
require 'et_ccd_client/exceptions'
|
9
|
+
require 'et_ccd_client/uploaded_file'
|
10
|
+
|
11
|
+
module EtCcdClient
|
12
|
+
class Error < StandardError; end
|
13
|
+
|
14
|
+
def self.config
|
15
|
+
yield Config.instance if block_given?
|
16
|
+
Config.instance
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,291 @@
|
|
1
|
+
require "addressable/template"
|
2
|
+
require 'rest_client'
|
3
|
+
require 'et_ccd_client/idam_client'
|
4
|
+
require 'et_ccd_client/config'
|
5
|
+
require 'et_ccd_client/exceptions'
|
6
|
+
require 'et_ccd_client/common_rest_client'
|
7
|
+
require 'et_ccd_client/common_rest_client_with_login'
|
8
|
+
require 'json'
|
9
|
+
require 'forwardable'
|
10
|
+
require 'connection_pool'
|
11
|
+
module EtCcdClient
|
12
|
+
# A client to interact with the CCD API (backend)
|
13
|
+
class Client
|
14
|
+
extend Forwardable
|
15
|
+
include CommonRestClient
|
16
|
+
include CommonRestClientWithLogin
|
17
|
+
|
18
|
+
|
19
|
+
def initialize(idam_client: nil, config: ::EtCcdClient.config)
|
20
|
+
self.idam_client = idam_client || (config.use_sidam ? IdamClient.new : TidamClient.new)
|
21
|
+
self.config = config
|
22
|
+
self.logger = config.logger
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.use(&block)
|
26
|
+
connection_pool.with(&block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.connection_pool(config: ::EtCcdClient.config)
|
30
|
+
@connection_pool ||= ConnectionPool.new(size: config.pool_size, timeout: config.pool_timeout) do
|
31
|
+
new.tap do |client|
|
32
|
+
client.login
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
delegate login: :idam_client
|
38
|
+
|
39
|
+
# Initiate the case ready for creation
|
40
|
+
# @param [String] case_type_id
|
41
|
+
#
|
42
|
+
# @return [Hash] The json response
|
43
|
+
def caseworker_start_case_creation(case_type_id:)
|
44
|
+
logger.tagged('EtCcdClient::Client') do
|
45
|
+
url = initiate_case_url(case_type_id, config.initiate_claim_event_id)
|
46
|
+
get_request_with_login(url, log_subject: 'Start case creation', extra_headers: headers_from_idam_client)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Initiate a bulk action case ready for creation
|
51
|
+
# @param [String] case_type_id
|
52
|
+
#
|
53
|
+
# @return [Hash] The json response
|
54
|
+
def caseworker_start_bulk_creation(case_type_id:)
|
55
|
+
logger.tagged('EtCcdClient::Client') do
|
56
|
+
url = initiate_case_url(case_type_id, config.initiate_bulk_event_id)
|
57
|
+
get_request_with_login(url, log_subject: 'Start bulk creation', extra_headers: headers_from_idam_client)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Initiate a document upload
|
62
|
+
# @param [String] ctid
|
63
|
+
# @param [String] cid
|
64
|
+
#
|
65
|
+
# @return [Hash] The json response
|
66
|
+
def caseworker_start_upload_document(ctid:, cid:)
|
67
|
+
url = initiate_document_upload_url(ctid, cid)
|
68
|
+
get_request_with_login(url, log_subject: 'Start upload document', extra_headers: headers_from_idam_client)
|
69
|
+
end
|
70
|
+
|
71
|
+
# @param [Hash] data
|
72
|
+
# @param [String] case_type_id
|
73
|
+
#
|
74
|
+
# @return [Hash] The json response
|
75
|
+
def caseworker_case_create(data, case_type_id:)
|
76
|
+
logger.tagged('EtCcdClient::Client') do
|
77
|
+
tpl = Addressable::Template.new(config.create_case_url)
|
78
|
+
url = tpl.expand(uid: idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id).to_s
|
79
|
+
post_request_with_login(url, data, log_subject: 'Case worker create case', extra_headers: headers_from_idam_client)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Search for cases by reference - useful for testing
|
84
|
+
# @param [String] reference The reference number to search for
|
85
|
+
# @param [String] case_type_id The case type ID to set the search scope to
|
86
|
+
# @param [Integer] page - The page number to fetch
|
87
|
+
# @param [String] sort_direction (defaults to 'desc') - Change to 'asc' to do oldest first
|
88
|
+
#
|
89
|
+
# @return [Array<Hash>] The json response from the server
|
90
|
+
def caseworker_search_by_reference(reference, case_type_id:, page: 1, sort_direction: 'desc')
|
91
|
+
logger.tagged('EtCcdClient::Client') do
|
92
|
+
tpl = Addressable::Template.new(config.cases_url)
|
93
|
+
url = tpl.expand(uid: idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id, query: { 'case.feeGroupReference' => reference, page: page, 'sortDirection' => sort_direction }).to_s
|
94
|
+
get_request_with_login(url, log_subject: 'Caseworker search by reference', extra_headers: headers_from_idam_client)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Search for the latest case matching the reference. Useful for testing
|
99
|
+
# @param [String] reference The reference number to search for
|
100
|
+
# @param [String] case_type_id The case type ID to set the search scope to
|
101
|
+
# @return [Hash] The case object returned from the server
|
102
|
+
def caseworker_search_latest_by_reference(reference, case_type_id:)
|
103
|
+
results = caseworker_search_by_reference(reference, case_type_id: case_type_id, page: 1, sort_direction: 'desc')
|
104
|
+
results.first
|
105
|
+
end
|
106
|
+
|
107
|
+
# Search for cases by multiple reference - useful for testing
|
108
|
+
# @param [String] reference The multiples reference number to search for
|
109
|
+
# @param [String] case_type_id The case type ID to set the search scope to
|
110
|
+
# @param [Integer] page - The page number to fetch
|
111
|
+
# @param [String] sort_direction (defaults to 'desc') - Change to 'asc' to do oldest first
|
112
|
+
#
|
113
|
+
# @return [Array<Hash>] The json response from the server
|
114
|
+
def caseworker_search_by_multiple_reference(reference, case_type_id:, page: 1, sort_direction: 'desc')
|
115
|
+
logger.tagged('EtCcdClient::Client') do
|
116
|
+
tpl = Addressable::Template.new(config.cases_url)
|
117
|
+
url = tpl.expand(uid: idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id, query: { 'case.multipleReference' => reference, page: page, 'sortDirection' => sort_direction }).to_s
|
118
|
+
get_request_with_login(url, log_subject: 'Caseworker search by multiple reference', extra_headers: headers_from_idam_client)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Search for the latest case matching the multiples reference. Useful for testing
|
123
|
+
# @param [String] reference The multiples reference number to search for
|
124
|
+
# @param [String] case_type_id The case type ID to set the search scope to
|
125
|
+
# @return [Hash] The case object returned from the server
|
126
|
+
def caseworker_search_latest_by_multiple_reference(reference, case_type_id:)
|
127
|
+
results = caseworker_search_by_multiple_reference(reference, case_type_id: case_type_id, page: 1, sort_direction: 'desc')
|
128
|
+
results.first
|
129
|
+
end
|
130
|
+
|
131
|
+
# @param [String] case_type_id
|
132
|
+
# @param [Integer] quantity
|
133
|
+
# @return [Hash] The json response from the server
|
134
|
+
def start_multiple(case_type_id:, quantity:)
|
135
|
+
logger.tagged('EtCcdClient::Client') do
|
136
|
+
url = config.start_multiple_url
|
137
|
+
payload = {
|
138
|
+
case_details: {
|
139
|
+
case_data: {
|
140
|
+
caseRefNumberCount: quantity.to_s
|
141
|
+
},
|
142
|
+
case_type_id: case_type_id
|
143
|
+
}
|
144
|
+
}
|
145
|
+
post_request_with_login(url, payload.to_json, log_subject: 'Start multiple', extra_headers: headers_from_idam_client)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# Search for cases by ethos case reference - useful for testing
|
150
|
+
# @param [String] reference The ethos case reference number to search for
|
151
|
+
# @param [String] case_type_id The case type ID to set the search scope to
|
152
|
+
# @param [Integer] page - The page number to fetch
|
153
|
+
# @param [String] sort_direction (defaults to 'desc') - Change to 'asc' to do oldest first
|
154
|
+
#
|
155
|
+
# @return [Array<Hash>] The json response from the server
|
156
|
+
def caseworker_search_by_ethos_case_reference(reference, case_type_id:, page: 1, sort_direction: 'desc')
|
157
|
+
logger.tagged('EtCcdClient::Client') do
|
158
|
+
tpl = Addressable::Template.new(config.cases_url)
|
159
|
+
url = tpl.expand(uid: idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id, query: { 'case.ethosCaseReference' => reference, page: page, 'sortDirection' => sort_direction }).to_s
|
160
|
+
resp = get_request_with_login(url, log_subject: 'Caseworker search by ethos case reference', extra_headers: headers_from_idam_client)
|
161
|
+
unless config.document_store_url_rewrite == false
|
162
|
+
resp = reverse_rewrite_document_store_urls(resp)
|
163
|
+
end
|
164
|
+
resp
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# Search for the latest case matching the ethos case reference. Useful for testing
|
169
|
+
# @param [String] reference The ethos case reference number to search for
|
170
|
+
# @param [String] case_type_id The case type ID to set the search scope to
|
171
|
+
# @return [Hash] The case object returned from the server
|
172
|
+
def caseworker_search_latest_by_ethos_case_reference(reference, case_type_id:)
|
173
|
+
results = caseworker_search_by_ethos_case_reference(reference, case_type_id: case_type_id, page: 1, sort_direction: 'desc')
|
174
|
+
results.first
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
def caseworker_cases_pagination_metadata(case_type_id:, query: {})
|
179
|
+
logger.tagged('EtCcdClient::Client') do
|
180
|
+
tpl = Addressable::Template.new(config.cases_pagination_metadata_url)
|
181
|
+
url = tpl.expand(uid: idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id, query: query).to_s
|
182
|
+
get_request_with_login(url, log_subject: 'Caseworker cases pagination metadata', extra_headers: headers_from_idam_client)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def caseworker_update_case_documents(event_token:, files:, case_id:, case_type_id:)
|
187
|
+
tpl = Addressable::Template.new(config.case_events_url)
|
188
|
+
url = tpl.expand(uid: idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id, cid: case_id).to_s
|
189
|
+
logger.tagged('EtCcdClient::Client') do
|
190
|
+
payload = {
|
191
|
+
data: {
|
192
|
+
documentCollection: files
|
193
|
+
},
|
194
|
+
event: {
|
195
|
+
id: 'uploadDocument',
|
196
|
+
summary: '',
|
197
|
+
description: ''
|
198
|
+
},
|
199
|
+
event_token: event_token,
|
200
|
+
ignore_warning: false
|
201
|
+
}.to_json
|
202
|
+
post_request_with_login(url, payload, log_subject: 'Caseworker update documents', extra_headers: headers_from_idam_client)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# @param [String] filename The full path to the file to upload
|
207
|
+
# @return [Hash] The object returned by the server
|
208
|
+
def upload_file_from_filename(filename, content_type:)
|
209
|
+
login_on_denial do
|
210
|
+
upload_file_from_source(filename, content_type: content_type, source_name: :filename, source: filename)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# @param [String] url The url of the file to upload
|
215
|
+
# @return [Hash] The object returned by the server
|
216
|
+
def upload_file_from_url(url, content_type:, original_filename: File.basename(url))
|
217
|
+
resp = download_from_remote_source(url)
|
218
|
+
login_on_denial do
|
219
|
+
upload_file_from_source(resp.file.path, content_type: content_type, source_name: :url, source: url, original_filename: original_filename)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
private
|
224
|
+
|
225
|
+
def download_from_remote_source(url)
|
226
|
+
logger.tagged('EtCcdClient::Client') do
|
227
|
+
logger.debug("ET > Download from remote source (#{url})")
|
228
|
+
request = RestClient::Request.new(method: :get, url: url, raw_response: true, verify_ssl: config.verify_ssl)
|
229
|
+
resp = request.execute
|
230
|
+
logger.debug("ET < Download from remote source (#{url}) complete. Data not shown as very likely to be binary")
|
231
|
+
resp
|
232
|
+
rescue RestClient::Exception => e
|
233
|
+
logger.debug "ET < Download from remote source (ERROR) - #{e.response}"
|
234
|
+
Exceptions::Base.raise_exception(e, url: url, request: request)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
def upload_file_from_source(filename, content_type:, source_name:, source:, original_filename: filename)
|
239
|
+
logger.tagged('EtCcdClient::Client') do
|
240
|
+
url = config.upload_file_url
|
241
|
+
logger.debug("ET > Upload file from #{source_name} (#{url})")
|
242
|
+
uploaded_file = UploadedFile.new(filename, content_type: content_type, binary: true, original_filename: original_filename)
|
243
|
+
data = {
|
244
|
+
multipart: true,
|
245
|
+
files: uploaded_file,
|
246
|
+
classification: 'PUBLIC'
|
247
|
+
}
|
248
|
+
request = RestClient::Request.new(method: :post, url: url, payload: data, headers: { 'ServiceAuthorization' => "Bearer #{idam_client.service_token}", :authorization => "Bearer #{idam_client.user_token}" }, verify_ssl: config.verify_ssl)
|
249
|
+
resp = request.execute
|
250
|
+
resp_body = resp.body
|
251
|
+
logger.debug "ET < Upload file from #{source_name} - #{resp_body}"
|
252
|
+
unless config.document_store_url_rewrite == false
|
253
|
+
resp_body = rewrite_document_store_urls(resp_body)
|
254
|
+
end
|
255
|
+
JSON.parse(resp_body)
|
256
|
+
rescue RestClient::Exception => e
|
257
|
+
logger.debug "ET < Upload file from #{source_name} (ERROR) - #{e.response.body}"
|
258
|
+
Exceptions::Base.raise_exception(e, url: url, request: request)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
def initiate_case_url(case_type_id, event_id)
|
263
|
+
tpl = Addressable::Template.new(config.initiate_case_url)
|
264
|
+
tpl.expand(uid: idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id, etid: event_id).to_s
|
265
|
+
end
|
266
|
+
|
267
|
+
def initiate_document_upload_url(case_type_id, cid)
|
268
|
+
tpl = Addressable::Template.new(config.initiate_document_upload_url)
|
269
|
+
tpl.expand(uid: idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id, cid: cid).to_s
|
270
|
+
end
|
271
|
+
|
272
|
+
def rewrite_document_store_urls(body)
|
273
|
+
source_host, source_port, dest_host, dest_port = config.document_store_url_rewrite
|
274
|
+
body.gsub(/(https?):\/\/#{Regexp.quote source_host}:#{Regexp.quote source_port}/, "\\1://#{dest_host}:#{dest_port}")
|
275
|
+
end
|
276
|
+
|
277
|
+
def headers_from_idam_client
|
278
|
+
{'ServiceAuthorization' => "Bearer #{idam_client.service_token}", :authorization => "Bearer #{idam_client.user_token}", 'user-id' => idam_client.user_details['id'], 'user-roles' => idam_client.user_details['roles'].join(',')}
|
279
|
+
end
|
280
|
+
|
281
|
+
def reverse_rewrite_document_store_urls(json)
|
282
|
+
source_host, source_port, dest_host, dest_port = config.document_store_url_rewrite
|
283
|
+
JSON.parse(JSON.generate(json).gsub(/(https?):\/\/#{Regexp.quote dest_host}:#{Regexp.quote dest_port}/, "\\1://#{source_host}:#{source_port}"))
|
284
|
+
end
|
285
|
+
|
286
|
+
attr_accessor :idam_client, :logger
|
287
|
+
|
288
|
+
# @return [EtCcdClient::Config] The configuration
|
289
|
+
attr_accessor :config
|
290
|
+
end
|
291
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module EtCcdClient
|
2
|
+
module CommonRestClient
|
3
|
+
def get_request(url, log_subject:, extra_headers: {}, decode: true, cookies: {})
|
4
|
+
logger.debug("ET > #{log_subject} (#{url})")
|
5
|
+
proxy = config.proxy == false || config.proxy.blank? ? nil : "http://#{config.proxy}"
|
6
|
+
req = RestClient::Request.new(method: :get, url: url, headers: { content_type: 'application/json' }.merge(extra_headers), cookies: cookies, verify_ssl: config.verify_ssl, proxy: proxy)
|
7
|
+
resp = req.execute
|
8
|
+
logger.debug "ET < #{log_subject} - #{resp.body}"
|
9
|
+
decode ? JSON.parse(resp.body) : resp.body
|
10
|
+
rescue RestClient::Exception => e
|
11
|
+
logger.debug "ET < #{log_subject} (ERROR) - #{e.response&.body}"
|
12
|
+
Exceptions::Base.raise_exception(e, url: url, request: req)
|
13
|
+
end
|
14
|
+
|
15
|
+
def post_request(url, data, log_subject:, extra_headers: {}, decode: true, cookies: {})
|
16
|
+
logger.debug("ET > #{log_subject} (#{url}) - #{data.to_json}")
|
17
|
+
proxy = config.proxy == false || config.proxy.blank? ? nil : "http://#{config.proxy}"
|
18
|
+
req = RestClient::Request.new(method: :post, url: url, payload: data, headers: { content_type: 'application/json' }.merge(extra_headers), cookies: cookies, verify_ssl: config.verify_ssl, proxy: proxy)
|
19
|
+
resp = req.execute
|
20
|
+
logger.debug "ET < #{log_subject} - #{resp.body}"
|
21
|
+
decode ? JSON.parse(resp.body) : resp.body
|
22
|
+
rescue RestClient::Exception => e
|
23
|
+
logger.debug "ET < #{log_subject} (ERROR) - #{e.response&.body}"
|
24
|
+
Exceptions::Base.raise_exception(e, url: url, request: req)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module EtCcdClient
|
2
|
+
module CommonRestClientWithLogin
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def get_request_with_login(*args)
|
7
|
+
login_on_denial do
|
8
|
+
get_request(*args)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def post_request_with_login(*args)
|
13
|
+
login_on_denial do
|
14
|
+
post_request(*args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def login_on_denial
|
19
|
+
retried = false
|
20
|
+
begin
|
21
|
+
yield
|
22
|
+
rescue EtCcdClient::Exceptions::Forbidden, EtCcdClient::Exceptions::Unauthorized => e
|
23
|
+
raise if retried
|
24
|
+
|
25
|
+
retried = true
|
26
|
+
logger.tagged('Re logging in') do
|
27
|
+
login
|
28
|
+
end
|
29
|
+
retry
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'et_ccd_client/null_logger'
|
3
|
+
require 'addressable/template'
|
4
|
+
module EtCcdClient
|
5
|
+
class Config
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
attr_accessor :auth_base_url, :idam_base_url, :data_store_base_url, :ecm_base_url, :case_management_ui_base_url, :document_store_base_url, :gateway_api_url, :document_store_url_rewrite
|
9
|
+
attr_accessor :user_role, :user_id
|
10
|
+
attr_accessor :jurisdiction_id, :microservice, :microservice_secret
|
11
|
+
attr_accessor :logger
|
12
|
+
attr_accessor :verify_ssl, :use_sidam, :sidam_username, :sidam_password
|
13
|
+
attr_accessor :case_management_ui_redirect_url
|
14
|
+
attr_accessor :pool_size, :pool_timeout
|
15
|
+
attr_accessor :proxy
|
16
|
+
|
17
|
+
def idam_service_token_exchange_url
|
18
|
+
"#{auth_base_url}/lease"
|
19
|
+
end
|
20
|
+
|
21
|
+
def idam_user_token_exchange_url
|
22
|
+
use_sidam ? "#{idam_base_url}/loginUser" : "#{idam_base_url}/testing-support/lease"
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_case_url
|
26
|
+
"#{data_store_base_url}/caseworkers/{uid}/jurisdictions/{jid}/case-types/{ctid}/cases"
|
27
|
+
end
|
28
|
+
|
29
|
+
def cases_url
|
30
|
+
"#{data_store_base_url}#{cases_path}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def cases_pagination_metadata_url
|
34
|
+
"#{data_store_base_url}/caseworkers/{uid}/jurisdictions/{jid}/case-types/{ctid}/cases/pagination_metadata{?query*}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def initiate_case_url
|
38
|
+
"#{data_store_base_url}/caseworkers/{uid}/jurisdictions/{jid}/case-types/{ctid}/event-triggers/{etid}/token"
|
39
|
+
end
|
40
|
+
|
41
|
+
def initiate_document_upload_url
|
42
|
+
"#{data_store_base_url}/caseworkers/{uid}/jurisdictions/{jid}/case-types/{ctid}/cases/{cid}/event-triggers/uploadDocument/token"
|
43
|
+
end
|
44
|
+
|
45
|
+
def case_events_url
|
46
|
+
"#{data_store_base_url}/caseworkers/{uid}/jurisdictions/{jid}/case-types/{ctid}/cases/{cid}/events"
|
47
|
+
end
|
48
|
+
|
49
|
+
def upload_file_url
|
50
|
+
"#{document_store_base_url}/documents"
|
51
|
+
end
|
52
|
+
|
53
|
+
def start_multiple_url
|
54
|
+
"#{ecm_base_url}/generateCaseRefNumbers"
|
55
|
+
end
|
56
|
+
|
57
|
+
def initiate_claim_event_id
|
58
|
+
'initiateCase'
|
59
|
+
end
|
60
|
+
|
61
|
+
def initiate_bulk_event_id
|
62
|
+
'createMultiple'
|
63
|
+
end
|
64
|
+
|
65
|
+
def initiate_document_upload_event_id
|
66
|
+
'uploadDocument'
|
67
|
+
end
|
68
|
+
|
69
|
+
def case_management_ui_config_url
|
70
|
+
"#{case_management_ui_base_url}/config"
|
71
|
+
end
|
72
|
+
|
73
|
+
def cases_path
|
74
|
+
"/caseworkers/{uid}/jurisdictions/{jid}/case-types/{ctid}/cases{?query*}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def user_details_url
|
78
|
+
"#{idam_base_url}/details"
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def initialize
|
84
|
+
self.auth_base_url = 'http://localhost:4502'
|
85
|
+
self.idam_base_url = 'http://localhost:4501'
|
86
|
+
self.data_store_base_url = 'http://localhost:4452'
|
87
|
+
self.document_store_base_url = 'http://localhost:4506'
|
88
|
+
self.ecm_base_url = 'http://unknown:4506'
|
89
|
+
self.document_store_url_rewrite = 'localhost:4506:dm-store:8080'
|
90
|
+
self.case_management_ui_redirect_url = 'http://localhost:3451/oauth2redirect'
|
91
|
+
self.case_management_ui_base_url = 'http://localhost:3451'
|
92
|
+
self.gateway_api_url = 'http://localhost:3453'
|
93
|
+
self.user_id = 22
|
94
|
+
self.user_role = 'caseworker,caseworker-test,caseworker-employment-tribunal-manchester,caseworker-employment,caseworker-employment-tribunal-manchester-caseofficer,caseworker-publiclaw-localAuthority'
|
95
|
+
self.jurisdiction_id = 'EMPLOYMENT'
|
96
|
+
self.microservice = 'ccd_gw'
|
97
|
+
self.microservice_secret = 'AAAAAAAAAAAAAAAC'
|
98
|
+
self.logger = NullLogger.new
|
99
|
+
self.verify_ssl = true
|
100
|
+
self.use_sidam = true
|
101
|
+
self.sidam_username = 'm@m.com'
|
102
|
+
self.sidam_password = 'Pa55word11'
|
103
|
+
self.pool_size = 5
|
104
|
+
self.pool_timeout = 30
|
105
|
+
self.proxy = false
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|