Skip to content
Snippets Groups Projects
Commit 3bc05501 authored by Komal Makkar's avatar Komal Makkar
Browse files

Extracting the core logic in a method

parent 4c581f85
No related branches found
No related tags found
1 merge request!33Core change: Adding case for handshake request header creation
Pipeline #13968 passed with warnings
......@@ -57,27 +57,30 @@ public class CredentialHeadersProvider implements FactoryBean<DpsHeaders> {
switch (requestMethod) {
case POST:
case PUT:
case PATCH: {
if(this.pubsubRequestBodyExtractor.isHandshakeRequest()) {
// The headers are not needed for the handshake requests.
return new DpsHeaders();
}
Map<String, String> attributes = this.pubsubRequestBodyExtractor.extractAttributesFromRequestBody();
try {
//extract headers from pubsub message
String dataPartitionId = attributes.get(DpsHeaders.DATA_PARTITION_ID);
String authToken = this.serviceAccountJwtClient.getIdToken(dataPartitionId);
attributes.put(DpsHeaders.AUTHORIZATION, authToken);
return DpsHeaders.createFromMap(attributes);
} catch (AppException e) {
throw new Exception("Failed to generate headers for register service.");
}
}
case PATCH:
return getDpsHeadersForPostPutPatch();
default: {
return new DpsHeaders();
}
}
}
private DpsHeaders getDpsHeadersForPostPutPatch() throws Exception {
if(this.pubsubRequestBodyExtractor.isHandshakeRequest()) {
// The headers are not needed for the handshake requests.
return new DpsHeaders();
}
Map<String, String> attributes = this.pubsubRequestBodyExtractor.extractAttributesFromRequestBody();
try {
//extract headers from pubsub message
String dataPartitionId = attributes.get(DpsHeaders.DATA_PARTITION_ID);
String authToken = this.serviceAccountJwtClient.getIdToken(dataPartitionId);
attributes.put(DpsHeaders.AUTHORIZATION, authToken);
return DpsHeaders.createFromMap(attributes);
} catch (AppException e) {
throw new Exception("Failed to generate headers for register service.");
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment