Skip to content

Commit a0da30f

Browse files
API Documentation for CDR export download (#1986)
* API Documentation for CDR export download * fix call auth error response
1 parent 332c4d1 commit a0da30f

5 files changed

Lines changed: 44 additions & 19 deletions

File tree

app/controllers/api/rest/customer/v1/call_auth_controller.rb

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,40 @@
33
class Api::Rest::Customer::V1::CallAuthController < Api::Rest::Customer::V1::BaseController
44
include CustomerV1Authorizable
55

6-
def create
7-
error_options = {
8-
status: '500',
9-
code: '500',
10-
title: 'Invalid request'
11-
}
6+
ConfigurationError = Class.new(JSONAPI::Exceptions::Error) do
7+
def initialize(detail)
8+
@detail = detail
9+
super()
10+
end
11+
12+
def errors
13+
[create_error_object(
14+
code: JSONAPI::INTERNAL_SERVER_ERROR,
15+
status: :internal_server_error,
16+
title: 'Internal Server Error',
17+
detail: @detail
18+
)]
19+
end
20+
end
1221

22+
def create
1323
if auth_context.provision_gateway_id.nil?
14-
render status: 500, json: {
15-
errors: [error_options.merge(detail: 'Provisioning Gateway is not found.')]
16-
} and return
24+
raise ConfigurationError, 'Provisioning Gateway is not found.'
1725
end
1826

1927
unless auth_context.provision_gateway.incoming_auth_allow_jwt?
20-
render status: 500, json: {
21-
errors: [error_options.merge(detail: 'Incoming JWT is disabled for Provisioning Gateway.')]
22-
} and return
28+
raise ConfigurationError, 'Incoming JWT is disabled for Provisioning Gateway.'
2329
end
2430

2531
private_key_path = YetiConfig&.api&.customer&.call_jwt_private_key
26-
raise 'Gateway Private key not found' if private_key_path.blank? || !File.exist?(private_key_path)
32+
if private_key_path.blank? || !File.exist?(private_key_path)
33+
raise ConfigurationError, 'Gateway Private key not found.'
34+
end
2735

2836
private_key = OpenSSL::PKey::EC.new(File.read(private_key_path))
2937
lifetime = YetiConfig&.api&.customer&.call_jwt_lifetime.presence
3038
if private_key.blank?
31-
capture_error('Private key is not found.')
32-
render status: 500, json: { errors: [details: 'Internal Server Error'] } and return
39+
raise ConfigurationError, 'Private key is not found.'
3340
end
3441

3542
now = Time.now.to_i
@@ -41,5 +48,7 @@ def create
4148

4249
token = JWT.encode(payload, private_key, JwtToken::ES256)
4350
render json: { jwt: token }, status: 201
51+
rescue StandardError => e
52+
handle_exceptions(e)
4453
end
4554
end

spec/acceptance/rest/admin/api/cdr_exports_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@
8181
end
8282
end
8383

84+
get '/api/rest/admin/cdr-exports/:id/download' do
85+
let(:id) { create(:cdr_export, :completed).id }
86+
87+
example_request 'download cdr export file' do
88+
expect(status).to eq(200)
89+
end
90+
end
91+
8492
delete '/api/rest/admin/cdr-exports/:id' do
8593
let(:id) { create(:cdr_export).id }
8694

spec/acceptance/rest/customer/api/v1/call_auth_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
example_request 'Receive 500 validation error (Gateway is not found)' do
3737
expect(status).to eq(500)
3838
response_json = JSON.parse(response_body, symbolize_names: true)
39-
expect(response_json[:errors]).to contain_exactly code: '500', detail: 'Provisioning Gateway is not found.', status: '500', title: 'Invalid request'
39+
expect(response_json[:errors]).to contain_exactly code: '500', detail: 'Provisioning Gateway is not found.', status: '500', title: 'Internal Server Error'
4040
end
4141
end
4242

@@ -46,7 +46,7 @@
4646
example_request 'Receive 500 validation error (Incoming JWT is disabled for Gateway)' do
4747
expect(status).to eq(500)
4848
response_json = JSON.parse(response_body, symbolize_names: true)
49-
expect(response_json[:errors]).to contain_exactly code: '500', detail: 'Incoming JWT is disabled for Provisioning Gateway.', status: '500', title: 'Invalid request'
49+
expect(response_json[:errors]).to contain_exactly code: '500', detail: 'Incoming JWT is disabled for Provisioning Gateway.', status: '500', title: 'Internal Server Error'
5050
end
5151
end
5252
end

spec/acceptance/rest/customer/api/v1/cdr_exports_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,12 @@
6262
expect(status).to eq(200)
6363
end
6464
end
65+
66+
get '/api/rest/customer/v1/cdr-exports/:id/download' do
67+
let(:id) { create(:cdr_export, :completed, customer_account: customer_acc).reload.uuid }
68+
69+
example_request 'download cdr export file' do
70+
expect(status).to eq(200)
71+
end
72+
end
6573
end

spec/requests/api/rest/customer/v1/call_auth_controller_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
expect(response.status).to eq(500)
143143
expect(response_json).to match(
144144
errors: [
145-
title: 'Invalid request',
145+
title: 'Internal Server Error',
146146
detail: 'Incoming JWT is disabled for Provisioning Gateway.',
147147
code: '500',
148148
status: '500'
@@ -161,7 +161,7 @@
161161
expect(response.status).to eq(500)
162162
expect(response_json).to match(
163163
errors: [
164-
title: 'Invalid request',
164+
title: 'Internal Server Error',
165165
detail: 'Provisioning Gateway is not found.',
166166
code: '500',
167167
status: '500'

0 commit comments

Comments
 (0)