diff options
author | danielhanrahan <daniel.hanrahan@est.tech> | 2024-02-29 15:52:46 +0000 |
---|---|---|
committer | danielhanrahan <daniel.hanrahan@est.tech> | 2024-02-29 15:52:46 +0000 |
commit | 0a1b4b12b6c2809d30c4bb1f3e862c855f21a316 (patch) | |
tree | dcfa113dc816940d8fee30ec88d553372b2e875a /cps-ncmp-rest | |
parent | c5222a72ef11bd440f5c2bd017e820922ff6735a (diff) |
Add bearer token to NCMP async batch data passthrough (CPS-2126 #4)
Async processing was not passing bearer token.
Issue-ID: CPS-2128
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: I75da35cce555c49cca638b68f106a9daba79c24a
Diffstat (limited to 'cps-ncmp-rest')
3 files changed, 20 insertions, 15 deletions
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java index 1c6aaf2262..b567ba2e73 100755 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java @@ -116,7 +116,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { final DataOperationRequest dataOperationRequest, final String authorization) { return ncmpPassthroughResourceRequestHandler.executeRequest(topicParamInQuery, - dataOperationRequestMapper.toDataOperationRequest(dataOperationRequest)); + dataOperationRequestMapper.toDataOperationRequest(dataOperationRequest), authorization); } /** diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java index 5da8c91207..430b749eff 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java @@ -61,17 +61,19 @@ public class NcmpPassthroughResourceRequestHandler extends NcmpDatastoreRequestH * * @param topicParamInQuery the topic param in query * @param dataOperationRequest data operation request details for resource data + * @param authorization contents of Authorization header, or null if not present * @return the response entity */ public ResponseEntity<Object> executeRequest(final String topicParamInQuery, - final DataOperationRequest - dataOperationRequest) { + final DataOperationRequest dataOperationRequest, + final String authorization) { validateDataOperationRequest(topicParamInQuery, dataOperationRequest); if (!notificationFeatureEnabled) { return ResponseEntity.ok(Map.of("status", "Asynchronous request is unavailable as notification feature is currently disabled.")); } - return getRequestIdAndSendDataOperationRequestToDmiService(topicParamInQuery, dataOperationRequest); + return getRequestIdAndSendDataOperationRequestToDmiService(topicParamInQuery, dataOperationRequest, + authorization); } @Override @@ -89,12 +91,13 @@ public class NcmpPassthroughResourceRequestHandler extends NcmpDatastoreRequestH authorization); } - private ResponseEntity<Object> getRequestIdAndSendDataOperationRequestToDmiService(final String topicParamInQuery, - final DataOperationRequest - dataOperationRequest) { + private ResponseEntity<Object> getRequestIdAndSendDataOperationRequestToDmiService( + final String topicParamInQuery, + final DataOperationRequest dataOperationRequest, + final String authorization) { final String requestId = UUID.randomUUID().toString(); cpsNcmpTaskExecutor.executeTask( - getTaskSupplierForDataOperationRequest(topicParamInQuery, dataOperationRequest, requestId), + getTaskSupplierForDataOperationRequest(topicParamInQuery, dataOperationRequest, requestId, authorization), timeOutInMilliSeconds); return ResponseEntity.ok(Map.of("requestId", requestId)); } @@ -116,11 +119,13 @@ public class NcmpPassthroughResourceRequestHandler extends NcmpDatastoreRequestH private Supplier<Object> getTaskSupplierForDataOperationRequest(final String topicParamInQuery, final DataOperationRequest dataOperationRequest, - final String requestId) { + final String requestId, + final String authorization) { return () -> { networkCmProxyDataService.executeDataOperationForCmHandles(topicParamInQuery, dataOperationRequest, - requestId); + requestId, + authorization); return noReturn; }; } diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy index 328a85e714..ddeac519c3 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy @@ -74,7 +74,7 @@ class NcmpDatastoreRequestHandlerSpec extends Specification { and: 'notification feature is turned on/off' objectUnderTest.notificationFeatureEnabled = notificationFeatureEnabled when: 'data operation request is executed' - objectUnderTest.executeRequest('someTopic', new DataOperationRequest()) + objectUnderTest.executeRequest('someTopic', new DataOperationRequest(), NO_AUTH_HEADER) then: 'the task is executed in an async fashion or not' expectedCalls * spiedCpsNcmpTaskExecutor.executeTask(*_) where: 'the following parameters are used' @@ -92,11 +92,11 @@ class NcmpDatastoreRequestHandlerSpec extends Specification { and: ' a flag to track the network service call' def networkServiceMethodCalled = false and: 'the (mocked) service will use the flag to indicate it is called' - mockNetworkCmProxyDataService.executeDataOperationForCmHandles('myTopic', dataOperationRequest, _) >> { + mockNetworkCmProxyDataService.executeDataOperationForCmHandles('myTopic', dataOperationRequest, _, NO_AUTH_HEADER) >> { networkServiceMethodCalled = true } when: 'data operation request is executed' - objectUnderTest.executeRequest('myTopic', dataOperationRequest) + objectUnderTest.executeRequest('myTopic', dataOperationRequest, NO_AUTH_HEADER) then: 'the task is executed in an async fashion' 1 * spiedCpsNcmpTaskExecutor.executeTask(*_) and: 'the network service is invoked' @@ -114,7 +114,7 @@ class NcmpDatastoreRequestHandlerSpec extends Specification { def dataOperationDefinition = new DataOperationDefinition(operation: 'read', datastore: datastore) when: 'data operation request is executed' def dataOperationRequest = new DataOperationRequest(dataOperationDefinitions: [dataOperationDefinition]) - objectUnderTest.executeRequest('myTopic', dataOperationRequest) + objectUnderTest.executeRequest('myTopic', dataOperationRequest, NO_AUTH_HEADER) then: 'the correct error is thrown' def thrown = thrown(InvalidDatastoreException) assert thrown.message.contains(expectedErrorMessage) @@ -130,7 +130,7 @@ class NcmpDatastoreRequestHandlerSpec extends Specification { and: 'a data operation definition with operation: #operation' def dataOperationDefinition = new DataOperationDefinition(operation: operation, datastore: 'ncmp-datastore:passthrough-running') when: 'bulk request is executed' - objectUnderTest.executeRequest('someTopic', new DataOperationRequest(dataOperationDefinitions:[dataOperationDefinition])) + objectUnderTest.executeRequest('someTopic', new DataOperationRequest(dataOperationDefinitions:[dataOperationDefinition]), NO_AUTH_HEADER) then: 'the expected type of exception is thrown' thrown(expectedException) where: 'the following operations are used' |