final String resourceIdentifier,
final String optionsParamInQuery,
final String topicParamInQuery,
- final Boolean includeDescendants) {
+ final Boolean includeDescendants,
+ final String authorization) {
if (DatastoreType.PASSTHROUGH_OPERATIONAL == DatastoreType.fromDatastoreName(datastoreName)) {
final ResponseEntity<Map<String, Object>> asyncResponse = populateAsyncResponse(topicParamInQuery);
final Map<String, Object> asyncResponseData = asyncResponse.getBody();
@Override
public ResponseEntity<Void> createResourceDataRunningForCmHandle(final String datastoreName, final String cmHandle,
- @NotNull @Valid final String resourceIdentifier,
- @Valid final Object body,
- final String contentType) {
+ @NotNull @Valid final String resourceIdentifier,
+ @Valid final Object body,
+ final String contentType,
+ final String authorization) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
-
+
@Override
public ResponseEntity<Void> deleteResourceDataRunningForCmHandle(final String datastoreName, final String cmHandle,
@NotNull @Valid final String resourceIdentifier,
- final String contentType) {
+ final String contentType,
+ final String authorization) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
@Override
public ResponseEntity<Object> executeDataOperationForCmHandles(final String topicParamInQuery,
- final DataOperationRequest dataOperationRequest) {
+ final DataOperationRequest dataOperationRequest,
+ final String authorization) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
@Override
public ResponseEntity<Object> patchResourceDataRunningForCmHandle(final String datastoreName, final String cmHandle,
- @NotNull @Valid final String resourceIdentifier,
- @Valid final Object body,
- final String contentType) {
+ @NotNull @Valid final String resourceIdentifier,
+ @Valid final Object body,
+ final String contentType,
+ final String authorization) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
-
+
@Override
public ResponseEntity<Object> queryResourceDataForCmHandle(final String datastoreName, final String cmHandle,
@Valid final String cpsPath, @Valid final String options,
}
@Override
- public ResponseEntity<Object> updateResourceDataRunningForCmHandle(final String datastoreName,
- final String cmHandle,
- @NotNull @Valid final String resourceIdentifier,
+ public ResponseEntity<Object> updateResourceDataRunningForCmHandle(final String datastoreName,
+ final String cmHandle,
+ @NotNull @Valid final String resourceIdentifier,
@Valid final Object body,
- final String contentType) {
+ final String contentType,
+ final String authorization) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
type: string
default: application/json
example: application/yang-data+json
+ authorizationParamInHeader:
+ name: Authorization
+ in: header
+ required: false
+ description: Authorization parameter for request.
+ schema:
+ type: string
datastoreName:
name: datastore-name
in: path
- $ref: 'components.yaml#/components/parameters/optionsParamInQuery'
- $ref: 'components.yaml#/components/parameters/topicParamInQuery'
- $ref: 'components.yaml#/components/parameters/includeDescendantsOptionInQuery'
+ - $ref: 'components.yaml#/components/parameters/authorizationParamInHeader'
responses:
200:
description: OK
- $ref: 'components.yaml#/components/parameters/cmHandleInPath'
- $ref: 'components.yaml#/components/parameters/resourceIdentifierInQuery'
- $ref: 'components.yaml#/components/parameters/contentParamInHeader'
+ - $ref: 'components.yaml#/components/parameters/authorizationParamInHeader'
requestBody:
required: true
content:
- $ref: 'components.yaml#/components/parameters/cmHandleInPath'
- $ref: 'components.yaml#/components/parameters/resourceIdentifierInQuery'
- $ref: 'components.yaml#/components/parameters/contentParamInHeader'
+ - $ref: 'components.yaml#/components/parameters/authorizationParamInHeader'
requestBody:
required: true
content:
- $ref: 'components.yaml#/components/parameters/cmHandleInPath'
- $ref: 'components.yaml#/components/parameters/resourceIdentifierInQuery'
- $ref: 'components.yaml#/components/parameters/contentParamInHeader'
+ - $ref: 'components.yaml#/components/parameters/authorizationParamInHeader'
requestBody:
required: true
content:
- $ref: 'components.yaml#/components/parameters/cmHandleInPath'
- $ref: 'components.yaml#/components/parameters/resourceIdentifierInQuery'
- $ref: 'components.yaml#/components/parameters/contentParamInHeader'
+ - $ref: 'components.yaml#/components/parameters/authorizationParamInHeader'
responses:
204:
$ref: 'components.yaml#/components/responses/NoContent'
operationId: executeDataOperationForCmHandles
parameters:
- $ref: 'components.yaml#/components/parameters/requiredTopicParamInQuery'
+ - $ref: 'components.yaml#/components/parameters/authorizationParamInHeader'
requestBody:
required: true
content:
500:
$ref: 'components.yaml#/components/responses/InternalServerError'
502:
- $ref: 'components.yaml#/components/responses/BadGateway'
\ No newline at end of file
+ $ref: 'components.yaml#/components/responses/BadGateway'
* @param optionsParamInQuery options query parameter
* @param topicParamInQuery topic query parameter
* @param includeDescendants whether to include descendants or not
+ * @param authorization contents of Authorization header, or null if not present
* @return {@code ResponseEntity} response from dmi plugin
*/
@Override
final String resourceIdentifier,
final String optionsParamInQuery,
final String topicParamInQuery,
- final Boolean includeDescendants) {
+ final Boolean includeDescendants,
+ final String authorization) {
final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler = getNcmpDatastoreRequestHandler(datastoreName);
return ncmpDatastoreRequestHandler.executeRequest(datastoreName, cmHandle, resourceIdentifier,
- optionsParamInQuery, topicParamInQuery, includeDescendants);
+ optionsParamInQuery, topicParamInQuery, includeDescendants, authorization);
}
@Override
public ResponseEntity<Object> executeDataOperationForCmHandles(final String topicParamInQuery,
- final DataOperationRequest
- dataOperationRequest) {
+ final DataOperationRequest dataOperationRequest,
+ final String authorization) {
return ncmpPassthroughResourceRequestHandler.executeRequest(topicParamInQuery,
dataOperationRequestMapper.toDataOperationRequest(dataOperationRequest));
}
* @param resourceIdentifier resource identifier
* @param requestBody the request body
* @param contentType content type of body
+ * @param authorization contents of Authorization header, or null if not present
* @return {@code ResponseEntity} response from dmi plugin
*/
final String cmHandle,
final String resourceIdentifier,
final Object requestBody,
- final String contentType) {
+ final String contentType,
+ final String authorization) {
validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
final Object responseObject = networkCmProxyDataService
.writeResourceDataPassThroughRunningForCmHandle(
cmHandle, resourceIdentifier, PATCH,
- jsonObjectMapper.asJsonString(requestBody), contentType);
+ jsonObjectMapper.asJsonString(requestBody), contentType, authorization);
return ResponseEntity.ok(responseObject);
}
* @param resourceIdentifier resource identifier
* @param requestBody the request body
* @param contentType content type of body
+ * @param authorization contents of Authorization header, or null if not present
* @return {@code ResponseEntity} response from dmi plugin
*/
@Override
final String cmHandle,
final String resourceIdentifier,
final Object requestBody,
- final String contentType) {
-
+ final String contentType,
+ final String authorization) {
validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
- resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType);
+ resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType, authorization);
return new ResponseEntity<>(HttpStatus.CREATED);
}
* @param resourceIdentifier resource identifier
* @param requestBody the request body
* @param contentType content type of the body
+ * @param authorization contents of Authorization header, or null if not present
* @return response entity
*/
final String cmHandle,
final String resourceIdentifier,
final Object requestBody,
- final String contentType) {
+ final String contentType,
+ final String authorization) {
validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
- resourceIdentifier, UPDATE, jsonObjectMapper.asJsonString(requestBody), contentType);
+ resourceIdentifier, UPDATE, jsonObjectMapper.asJsonString(requestBody), contentType, authorization);
return new ResponseEntity<>(HttpStatus.OK);
}
* @param cmHandle cm handle identifier
* @param resourceIdentifier resource identifier
* @param contentType content type of the body
+ * @param authorization contents of Authorization header, or null if not present
* @return response entity no content if request is successful
*/
@Override
public ResponseEntity<Void> deleteResourceDataRunningForCmHandle(final String datastoreName,
final String cmHandle,
final String resourceIdentifier,
- final String contentType) {
+ final String contentType,
+ final String authorization) {
validateDataStore(PASSTHROUGH_RUNNING, datastoreName);
networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
- resourceIdentifier, DELETE, NO_BODY, contentType);
+ resourceIdentifier, DELETE, NO_BODY, contentType, authorization);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
final String optionsParamInQuery,
final String topicParamInQuery,
final String requestId,
- final boolean includeDescendants) {
+ final boolean includeDescendants,
+ final String authorization) {
final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendants);
* @param optionsParamInQuery the options param in query
* @param topicParamInQuery the topic param in query
* @param includeDescendants whether include descendants
+ * @param authorization contents of Authorization header, or null if not present
* @return the response entity
*/
public ResponseEntity<Object> executeRequest(final String datastoreName,
final String resourceIdentifier,
final String optionsParamInQuery,
final String topicParamInQuery,
- final boolean includeDescendants) {
+ final boolean includeDescendants,
+ final String authorization) {
final boolean asyncResponseRequested = topicParamInQuery != null;
if (asyncResponseRequested && notificationFeatureEnabled) {
return executeAsyncTaskAndGetResponseEntity(datastoreName, cmHandleId, resourceIdentifier,
- optionsParamInQuery, topicParamInQuery, includeDescendants);
+ optionsParamInQuery, topicParamInQuery, includeDescendants, authorization);
}
if (asyncResponseRequested) {
+ "will use synchronous operation.");
}
final Supplier<Object> taskSupplier = getTaskSupplierForGetRequest(datastoreName, cmHandleId,
- resourceIdentifier, optionsParamInQuery, NO_TOPIC, NO_REQUEST_ID, includeDescendants);
+ resourceIdentifier, optionsParamInQuery, NO_TOPIC, NO_REQUEST_ID, includeDescendants, authorization);
return executeTaskSync(taskSupplier);
}
final String resourceIdentifier,
final String optionsParamInQuery,
final String topicParamInQuery,
- final boolean includeDescendants) {
+ final boolean includeDescendants,
+ final String authorization) {
final String requestId = UUID.randomUUID().toString();
final Supplier<Object> taskSupplier = getTaskSupplierForGetRequest(datastoreName, cmHandleId,
- resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId, includeDescendants);
+ resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId, includeDescendants,
+ authorization);
return executeTaskAsync(topicParamInQuery, requestId, taskSupplier);
}
final String optionsParamInQuery,
final String topicParamInQuery,
final String requestId,
- final boolean includeDescendant);
+ final boolean includeDescendant,
+ final String authorization);
}
final String optionsParamInQuery,
final String topicParamInQuery,
final String requestId,
- final boolean includeDescendants) {
+ final boolean includeDescendants,
+ final String authorization) {
return () -> networkCmProxyDataService.getResourceDataForCmHandle(
- datastoreName, cmHandleId, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId);
+ datastoreName, cmHandleId, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId,
+ authorization);
}
private ResponseEntity<Object> getRequestIdAndSendDataOperationRequestToDmiService(final String topicParamInQuery,
@Shared
def NO_TOPIC = null
def NO_REQUEST_ID = null
+ def NO_AUTH_HEADER = null
def TIMOUT_FOR_TEST = 1234
def logger = Spy(ListAppender<ILoggingEvent>)
).andReturn().response
then: 'the NCMP data service is called with getResourceDataOperationalForCmHandle'
1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(PASSTHROUGH_OPERATIONAL.datastoreName, 'testCmHandle',
- 'parent/child','(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID)
+ 'parent/child','(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER)
and: 'response status is Ok'
response.status == HttpStatus.OK.value()
}
"?resourceIdentifier=" + resourceIdentifier + "&options=(a=1,b=2)"
and: 'ncmp service returns json object'
mockNetworkCmProxyDataService.getResourceDataForCmHandle(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle',
- resourceIdentifier,'(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID) >> '{valid-json}'
+ resourceIdentifier,'(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER) >> '{valid-json}'
when: 'get data resource request is performed'
def response = mvc.perform(
get(getUrl)
).andReturn().response
then: 'ncmp service method to update resource is called'
1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
- 'parent/child', UPDATE, requestBody, 'application/json;charset=UTF-8')
+ 'parent/child', UPDATE, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
and: 'the response status is OK'
response.status == HttpStatus.OK.value()
}
).andReturn().response
then: 'ncmp service method to create resource called'
1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
- 'parent/child', CREATE, requestBody, 'application/json;charset=UTF-8')
+ 'parent/child', CREATE, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
and: 'resource is created'
response.status == HttpStatus.CREATED.value()
}
).andReturn().response
then: 'ncmp service method to update resource is called'
1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
- 'parent/child', PATCH, requestBody, 'application/json;charset=UTF-8')
+ 'parent/child', PATCH, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
and: 'the response status is OK'
response.status == HttpStatus.OK.value()
}
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andReturn().response
then: 'the ncmp service method to delete resource is called (with null as body)'
1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
- 'parent/child', DELETE, null, 'application/json;charset=UTF-8')
+ 'parent/child', DELETE, null, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
and: 'the response is No Content'
response.status == HttpStatus.NO_CONTENT.value()
}
def objectUnderTest = new NcmpPassthroughResourceRequestHandler(spiedCpsNcmpTaskExecutor, mockNetworkCmProxyDataService)
+ def NO_AUTH_HEADER = null
+
def setup() {
objectUnderTest.timeOutInMilliSeconds = 100
}
and: 'a flag to track the network service call'
def networkServiceMethodCalled = false
and: 'the (mocked) service will use the flag to indicate if it is called'
- mockNetworkCmProxyDataService.getResourceDataForCmHandle('ds', 'ch1', 'resource1', 'options', _, _) >> {
+ mockNetworkCmProxyDataService.getResourceDataForCmHandle('ds', 'ch1', 'resource1', 'options', _, _, NO_AUTH_HEADER) >> {
networkServiceMethodCalled = true
}
when: 'get request is executed with topic = #topic'
- objectUnderTest.executeRequest('ds', 'ch1', 'resource1', 'options', topic, false)
+ objectUnderTest.executeRequest('ds', 'ch1', 'resource1', 'options', topic, false, NO_AUTH_HEADER)
then: 'the task is executed in an async fashion or not'
expectedCalls * spiedCpsNcmpTaskExecutor.executeTask(*_)
and: 'the service request is invoked'
* @param optionsParamInQuery options query
* @param topicParamInQuery topic name for (triggering) async responses
* @param requestId unique requestId for async request
+ * @param authorization contents of Authorization header, or null if not present
* @return {@code Object} resource data
*/
Object getResourceDataForCmHandle(String datastoreName,
String resourceIdentifier,
String optionsParamInQuery,
String topicParamInQuery,
- String requestId);
+ String requestId,
+ String authorization);
/**
* Get resource data for operational.
* @param operationType required operation type
* @param requestBody request body to create resource
* @param contentType content type in body
+ * @param authorization contents of Authorization header, or null if not present
* @return {@code Object} return data
*/
Object writeResourceDataPassThroughRunningForCmHandle(String cmHandleId,
String resourceIdentifier,
OperationType operationType,
String requestBody,
- String contentType);
+ String contentType,
+ String authorization);
/**
* Retrieve module references for the given cm handle.
final String resourceIdentifier,
final String optionsParamInQuery,
final String topicParamInQuery,
- final String requestId) {
+ final String requestId,
+ final String authorization) {
final ResponseEntity<?> responseEntity = dmiDataOperations.getResourceDataFromDmi(datastoreName, cmHandleId,
resourceIdentifier,
optionsParamInQuery,
topicParamInQuery,
- requestId);
+ requestId,
+ authorization);
return responseEntity.getBody();
}
final String resourceIdentifier,
final OperationType operationType,
final String requestData,
- final String dataType) {
+ final String dataType,
+ final String authorization) {
return dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier,
- operationType, requestData, dataType);
+ operationType, requestData, dataType, authorization);
}
@Override
package org.onap.cps.ncmp.api.impl.client;
import com.fasterxml.jackson.databind.JsonNode;
+import java.util.Locale;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration.DmiProperties;
* @param dmiResourceUrl dmi resource url
* @param requestBodyAsJsonString json data body
* @param operationType the type of operation being executed (for error reporting only)
+ * @param authorization contents of Authorization header, or null if not present
* @return response entity of type String
*/
public ResponseEntity<Object> postOperationWithJsonData(final String dmiResourceUrl,
final String requestBodyAsJsonString,
- final OperationType operationType) {
- final var httpEntity = new HttpEntity<>(requestBodyAsJsonString, configureHttpHeaders(new HttpHeaders()));
+ final OperationType operationType,
+ final String authorization) {
+ final var httpEntity = new HttpEntity<>(requestBodyAsJsonString, configureHttpHeaders(new HttpHeaders(),
+ authorization));
try {
return restTemplate.postForEntity(dmiResourceUrl, httpEntity, Object.class);
} catch (final HttpStatusCodeException httpStatusCodeException) {
* @return plugin health status ("UP" is all OK, "" (not-specified) in case of any exception)
*/
public String getDmiHealthStatus(final String dmiPluginBaseUrl) {
- final HttpEntity<Object> httpHeaders = new HttpEntity<>(configureHttpHeaders(new HttpHeaders()));
+ final HttpEntity<Object> httpHeaders = new HttpEntity<>(configureHttpHeaders(new HttpHeaders(), null));
try {
final JsonNode responseHealthStatus =
restTemplate.getForObject(dmiPluginBaseUrl + HEALTH_CHECK_URL_EXTENSION,
}
}
- private HttpHeaders configureHttpHeaders(final HttpHeaders httpHeaders) {
+ private HttpHeaders configureHttpHeaders(final HttpHeaders httpHeaders, final String authorization) {
if (dmiProperties.isDmiBasicAuthEnabled()) {
httpHeaders.setBasicAuth(dmiProperties.getAuthUsername(), dmiProperties.getAuthPassword());
+ } else if (authorization != null && authorization.toLowerCase(Locale.getDefault()).startsWith("bearer ")) {
+ httpHeaders.add(HttpHeaders.AUTHORIZATION, authorization);
}
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
return httpHeaders;
* @param optionsParamInQuery options query
* @param topicParamInQuery topic name for (triggering) async responses
* @param requestId requestId for async responses
+ * @param authorization contents of Authorization header, or null if not present
* @return {@code ResponseEntity} response entity
*/
@Timed(value = "cps.ncmp.dmi.get",
final String resourceId,
final String optionsParamInQuery,
final String topicParamInQuery,
- final String requestId) {
+ final String requestId,
+ final String authorization) {
final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmHandleId);
final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState();
validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState);
yangModelCmHandle);
final String dmiResourceDataUrl = getDmiRequestUrl(dataStoreName, cmHandleId, resourceId, optionsParamInQuery,
topicParamInQuery, yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA));
- return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonRequestBody, READ);
+ return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonRequestBody, READ, authorization);
}
/**
yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA));
final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState();
validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState);
- return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonRequestBody, READ);
+ return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonRequestBody, READ, null);
}
/**
* @param operationType operation enum
* @param requestData the request data
* @param dataType data type
+ * @param authorization contents of Authorization header, or null if not present
* @return {@code ResponseEntity} response entity
*/
public ResponseEntity<Object> writeResourceDataPassThroughRunningFromDmi(final String cmHandleId,
final String resourceId,
final OperationType operationType,
final String requestData,
- final String dataType) {
+ final String dataType,
+ final String authorization) {
final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmHandleId);
final String jsonRequestBody = getDmiRequestBody(operationType, null, requestData, dataType,
yangModelCmHandle);
yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA));
final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState();
validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState);
- return dmiRestClient.postOperationWithJsonData(dmiUrl, jsonRequestBody, operationType);
+ return dmiRestClient.postOperationWithJsonData(dmiUrl, jsonRequestBody, operationType, authorization);
}
private YangModelCmHandle getYangModelCmHandle(final String cmHandleId) {
final String dmiDataOperationRequestAsJsonString =
jsonObjectMapper.asJsonString(dmiDataOperationRequest);
TaskExecutor.executeTask(() -> dmiRestClient.postOperationWithJsonData(dataOperationResourceUrl,
- dmiDataOperationRequestAsJsonString, READ),
+ dmiDataOperationRequestAsJsonString, READ, null),
DEFAULT_ASYNC_TASK_EXECUTOR_TIMEOUT_IN_MILLISECONDS)
.whenCompleteAsync((response, throwable) -> handleTaskCompletionException(throwable,
dataOperationResourceUrl, dmiDataOperationRequestBodies));
final String resourceName) {
final String dmiResourceDataUrl = getDmiResourceUrl(dmiServiceName, cmHandle, resourceName);
return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonRequestBody,
- OperationType.READ);
+ OperationType.READ, null);
}
private static String getRequestBodyToFetchYangResources(final Collection<ModuleReference> newModuleReferences,
def NO_TOPIC = null
def NO_REQUEST_ID = null
+ def NO_AUTH_HEADER = null
def OPTIONS_PARAM = '(a=1,b=2)'
def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: 'test-cm-handle-id')
when: 'write resource data is called'
objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
'testResourceId', CREATE,
- '{some-json}', 'application/json')
+ '{some-json}', 'application/json', null)
then: 'DMI called with correct data'
1 * mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle', 'testResourceId',
- CREATE, '{some-json}', 'application/json')
+ CREATE, '{some-json}', 'application/json', null)
>> { new ResponseEntity<>(HttpStatus.CREATED) }
}
given: 'cpsDataService returns valid data node'
mockDataNode()
and: 'get resource data from DMI is called'
- mockDmiDataOperations.getResourceDataFromDmi(PASSTHROUGH_OPERATIONAL.datastoreName,'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID) >>
+ mockDmiDataOperations.getResourceDataFromDmi(PASSTHROUGH_OPERATIONAL.datastoreName,'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER) >>
new ResponseEntity<>('dmi-response', HttpStatus.OK)
when: 'get resource data operational for cm-handle is called'
- def response = objectUnderTest.getResourceDataForCmHandle(PASSTHROUGH_OPERATIONAL.datastoreName, 'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID)
+ def response = objectUnderTest.getResourceDataForCmHandle(PASSTHROUGH_OPERATIONAL.datastoreName, 'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER)
then: 'DMI returns a json response'
assert response == 'dmi-response'
}
given: 'cpsDataService returns valid data node'
mockDataNode()
and: 'DMI returns valid response and data'
- mockDmiDataOperations.getResourceDataFromDmi(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID) >>
+ mockDmiDataOperations.getResourceDataFromDmi(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER) >>
new ResponseEntity<>('{dmi-response}', HttpStatus.OK)
when: 'get resource data is called'
- def response = objectUnderTest.getResourceDataForCmHandle(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID)
+ def response = objectUnderTest.getResourceDataForCmHandle(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER)
then: 'get resource data returns expected response'
assert response == '{dmi-response}'
}
when: 'get resource data is called'
objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
'testResourceId', UPDATE,
- '{some-json}', 'application/json')
+ '{some-json}', 'application/json', NO_AUTH_HEADER)
then: 'DMI called with correct data'
1 * mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle', 'testResourceId',
- UPDATE, '{some-json}', 'application/json')
+ UPDATE, '{some-json}', 'application/json', NO_AUTH_HEADER)
>> { new ResponseEntity<>(HttpStatus.OK) }
}
@ContextConfiguration(classes = [DmiProperties, DmiRestClient, ObjectMapper])
class DmiRestClientSpec extends Specification {
+ static final NO_AUTH_HEADER = null
+ static final BASIC_AUTH_HEADER = 'Basic c29tZS11c2VyOnNvbWUtcGFzc3dvcmQ='
+ static final BEARER_AUTH_HEADER = 'Bearer my-bearer-token'
+
@SpringBean
RestTemplate mockRestTemplate = Mock(RestTemplate)
given: 'the rest template returns a valid response entity for the expected parameters'
mockRestTemplate.postForEntity('my url', _ as HttpEntity, Object.class) >> responseFromRestTemplate
when: 'POST operation is invoked'
- def result = objectUnderTest.postOperationWithJsonData('my url', 'some json', READ)
+ def result = objectUnderTest.postOperationWithJsonData('my url', 'some json', READ, null)
then: 'the output of the method is equal to the output from the test template'
result == responseFromRestTemplate
}
def httpServerErrorException = new HttpServerErrorException(HttpStatus.FORBIDDEN, 'status text', serverResponse, null)
mockRestTemplate.postForEntity(*_) >> { throw httpServerErrorException }
when: 'POST operation is invoked'
- def result = objectUnderTest.postOperationWithJsonData('some url', 'some json', operation)
+ def result = objectUnderTest.postOperationWithJsonData('some url', 'some json', operation, null)
then: 'a Http Client Exception is thrown'
def thrown = thrown(HttpClientRequestException)
and: 'the exception has the relevant details from the error response'
'exception' | {throw new Exception()}
}
- def 'Basic auth header #scenario'() {
+ def 'DMI auth header #scenario'() {
when: 'Specific dmi properties are provided'
dmiProperties.dmiBasicAuthEnabled = authEnabled
then: 'http headers to conditionally have Authorization header'
- assert (objectUnderTest.configureHttpHeaders(new HttpHeaders()).get('Authorization') != null) == isPresentInHttpHeader
+ def authHeaderValues = objectUnderTest.configureHttpHeaders(new HttpHeaders(), ncmpAuthHeader).getOrEmpty('Authorization')
+ def outputAuthHeader = (authHeaderValues == null ? null : authHeaderValues[0])
+ assert outputAuthHeader == expectedAuthHeader
where: 'the following configurations are used'
- scenario | authEnabled || isPresentInHttpHeader
- 'auth enabled' | true || true
- 'auth disabled' | false || false
+ scenario | authEnabled | ncmpAuthHeader || expectedAuthHeader
+ 'DMI basic auth enabled, no NCMP bearer token' | true | NO_AUTH_HEADER || BASIC_AUTH_HEADER
+ 'DMI basic auth enabled, with NCMP bearer token' | true | BEARER_AUTH_HEADER || BASIC_AUTH_HEADER
+ 'DMI basic auth disabled, no NCMP bearer token' | false | NO_AUTH_HEADER || NO_AUTH_HEADER
+ 'DMI basic auth disabled, with NCMP bearer token' | false | BEARER_AUTH_HEADER || BEARER_AUTH_HEADER
+ 'DMI basic auth disabled, with NCMP basic auth' | false | BASIC_AUTH_HEADER || NO_AUTH_HEADER
}
}
def dmiServiceBaseUrl = "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/data/ds/ncmp-datastore:"
def NO_TOPIC = null
def NO_REQUEST_ID = null
+ def NO_AUTH_HEADER = null
@Shared
def OPTIONS_PARAM = '(a=1,b=2)'
and: 'a positive response from DMI service when it is called with the expected parameters'
def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK)
def expectedUrl = dmiServiceBaseUrl + "${expectedDatastoreInUrl}?resourceIdentifier=${resourceIdentifier}${expectedOptionsInUrl}"
- mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson, READ) >> responseFromDmi
+ mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson, READ, NO_AUTH_HEADER) >> responseFromDmi
dmiServiceUrlBuilder.getDmiDatastoreUrl(_, _) >> expectedUrl
when: 'get resource data is invoked'
def result = objectUnderTest.getResourceDataFromDmi(dataStore.datastoreName, cmHandleId, resourceIdentifier,
- options, NO_TOPIC, NO_REQUEST_ID)
+ options, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER)
then: 'the result is the response from the DMI service'
assert result == responseFromDmi
where: 'the following parameters are used'
def responseFromDmi = new ResponseEntity<Object>(HttpStatus.ACCEPTED)
def expectedDmiBatchResourceDataUrl = "ncmp/v1/data/topic=my-topic-name"
def expectedBatchRequestAsJson = '{"operations":[{"operation":"read","operationId":"operational-14","datastore":"ncmp-datastore:passthrough-operational","options":"some option","resourceIdentifier":"some resource identifier","cmHandles":[{"id":"some-cm-handle","cmHandleProperties":{"prop1":"val1"}}]}]}'
- mockDmiRestClient.postOperationWithJsonData(expectedDmiBatchResourceDataUrl, _, READ.operationName) >> responseFromDmi
+ mockDmiRestClient.postOperationWithJsonData(expectedDmiBatchResourceDataUrl, _, READ.operationName, NO_AUTH_HEADER) >> responseFromDmi
dmiServiceUrlBuilder.getDataOperationRequestUrl(_, _) >> expectedDmiBatchResourceDataUrl
and: ' a flag to track the post operation call'
def postOperationWithJsonDataMethodCalled = false
and: 'the (mocked) dmi rest client will use the flag to indicate it is called and capture the request body'
- mockDmiRestClient.postOperationWithJsonData(expectedDmiBatchResourceDataUrl, expectedBatchRequestAsJson, READ) >> {
+ mockDmiRestClient.postOperationWithJsonData(expectedDmiBatchResourceDataUrl, expectedBatchRequestAsJson, READ, null) >> {
postOperationWithJsonDataMethodCalled = true
}
when: 'get resource data for group of cm handles are invoked'
and: 'a positive response from DMI service when it is called with the expected parameters'
def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK)
def expectedUrl = dmiServiceBaseUrl + "passthrough-operational?resourceIdentifier=/"
- mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}', READ) >> responseFromDmi
+ mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}', READ, null) >> responseFromDmi
dmiServiceUrlBuilder.getDmiDatastoreUrl(_, _) >> expectedUrl
when: 'get resource data is invoked'
def result = objectUnderTest.getResourceDataFromDmi( PASSTHROUGH_OPERATIONAL.datastoreName, cmHandleId, NO_REQUEST_ID)
def expectedJson = '{"operation":"' + expectedOperationInUrl + '","dataType":"some data type","data":"requestData","cmHandleProperties":{"prop1":"val1"}}'
def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK)
dmiServiceUrlBuilder.getDmiDatastoreUrl(_, _) >> expectedUrl
- mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson, operation) >> responseFromDmi
+ mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson, operation, NO_AUTH_HEADER) >> responseFromDmi
when: 'write resource method is invoked'
- def result = objectUnderTest.writeResourceDataPassThroughRunningFromDmi(cmHandleId, 'parent/child', operation, 'requestData', 'some data type')
+ def result = objectUnderTest.writeResourceDataPassThroughRunningFromDmi(cmHandleId, 'parent/child', operation, 'requestData', 'some data type', NO_AUTH_HEADER)
then: 'the result is the response from the DMI service'
assert result == responseFromDmi
where: 'the following operation is performed'
@SpringBean
JsonObjectMapper spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
+ def NO_AUTH_HEADER = null
+
def 'Retrieving module references.'() {
given: 'a cm handle'
mockYangModelCmHandleRetrieval([])
def moduleReferencesAsLisOfMaps = [[moduleName: 'mod1', revision: 'A'], [moduleName: 'mod2', revision: 'X']]
def expectedUrl = "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules"
def responseFromDmi = new ResponseEntity([schemas: moduleReferencesAsLisOfMaps], HttpStatus.OK)
- mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"cmHandleProperties":{}}', READ)
+ mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"cmHandleProperties":{}}', READ, NO_AUTH_HEADER)
>> responseFromDmi
when: 'get module references is called'
def result = objectUnderTest.getModuleReferences(yangModelCmHandle)
and: 'a positive response from DMI service when it is called with tha expected parameters'
def responseFromDmi = new ResponseEntity<String>(HttpStatus.OK)
mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules",
- '{"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}', READ) >> responseFromDmi
+ '{"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}', READ, NO_AUTH_HEADER) >> responseFromDmi
when: 'a get module references is called'
def result = objectUnderTest.getModuleReferences(yangModelCmHandle)
then: 'the result is the response from DMI service'
[moduleName: 'mod2', revision: 'C', yangSource: 'other yang source']], HttpStatus.OK)
def expectedModuleReferencesInRequest = '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}'
mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
- '{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":{}}', READ) >> responseFromDmi
+ '{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":{}}', READ, NO_AUTH_HEADER) >> responseFromDmi
when: 'get new yang resources from DMI service'
def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences)
then: 'the result has the 2 expected yang (re)sources (order is not guaranteed)'
and: 'a positive response from DMI service when it is called with the expected parameters'
def responseFromDmi = new ResponseEntity<>([[moduleName: 'mod1', revision: 'A', yangSource: 'some yang source']], HttpStatus.OK)
mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
- '{"data":{"modules":[{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}]},"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}', READ) >> responseFromDmi
+ '{"data":{"modules":[{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}]},"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}',
+ READ, NO_AUTH_HEADER) >> responseFromDmi
when: 'get new yang resources from DMI service'
def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences)
then: 'the result is the response from DMI service'
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
}
/**
- * Get resource data from passthrough operational or running for a cm handle.
+ * Create resource data from passthrough operational or running for a cm handle.
*
* @param cmHandleId The identifier for a network function, network element, subnetwork,
* or any other cm object by managed Network CM Proxy
@PathVariable("datastoreName") final String datastoreName,
@RequestParam(value = "resourceIdentifier") final String resourceIdentifier,
@RequestParam(value = "options", required = false) final String options,
- @RequestParam(value = "topic", required = false) final String topic) {
+ @RequestParam(value = "topic", required = false) final String topic,
+ @RequestHeader(value = "Authorization", required = false) final String authorization) {
+ log.info("DMI AUTH HEADER: {}", authorization);
delay(dataForCmHandleDelayMs);
final String sampleJson = ResourceFileReaderUtil.getResourceFileContent(applicationContext.getResource(
ResourceLoader.CLASSPATH_URL_PREFIX + "data/operational/ietf-network-topology-sample-rfc8345.json"));