diff --git a/indexer-service-aws/pom.xml b/indexer-service-aws/pom.xml index 40465e44e05400d86905583025849fa022148d3d..0919b60fd9539a8b6c7de1c47f2332814a51288d 100644 --- a/indexer-service-aws/pom.xml +++ b/indexer-service-aws/pom.xml @@ -92,6 +92,29 @@ <version>7.6.0</version> <scope>compile</scope> </dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>core-lib</artifactId> + <version>0.1.1</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>indexer-search-core-lib</artifactId> + <version>1.0.9</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <version>1</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <version>1</version> + <scope>compile</scope> + </dependency> </dependencies> <build> <plugins> diff --git a/indexer-service-aws/src/main/java/org/opengroup/osdu/.DS_Store b/indexer-service-aws/src/main/java/org/opengroup/osdu/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..72d84d96dd4f2cfdb68f57b26137b65553b59f7f Binary files /dev/null and b/indexer-service-aws/src/main/java/org/opengroup/osdu/.DS_Store differ diff --git a/indexer-service-aws/src/main/java/org/opengroup/osdu/indexer/.DS_Store b/indexer-service-aws/src/main/java/org/opengroup/osdu/indexer/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5478f3fff37cc5282ec30e7223cf1f404fc2d8d3 Binary files /dev/null and b/indexer-service-aws/src/main/java/org/opengroup/osdu/indexer/.DS_Store differ diff --git a/indexer-service-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/HeadersInfoAwsImpl.java b/indexer-service-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/HeadersInfoAwsImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..eaddd8a520d48393e0278aefaed802ba818343ac --- /dev/null +++ b/indexer-service-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/HeadersInfoAwsImpl.java @@ -0,0 +1,121 @@ +// Copyright © Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.indexer.aws.util; + +import lombok.extern.java.Log; +import org.apache.http.HttpStatus; +import org.opengroup.osdu.core.api.DpsHeaders; +import org.opengroup.osdu.is.core.model.SlbHeaders; +import org.opengroup.osdu.is.core.provider.interfaces.util.IHeadersInfo; +import org.opengroup.osdu.is.core.util.AppException; +import org.opengroup.osdu.is.core.util.Preconditions; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +import java.util.HashSet; +import java.util.Map; +import java.util.stream.Collectors; +import javax.inject.Inject; + +@Log +@Component +@RequestScope +public class HeadersInfoAwsImpl implements IHeadersInfo { + + @Inject + private DpsHeaders headersMap; + + + private static final HashSet<String> FORBIDDEN_FROM_LOGGING = new HashSet<>(); + static { + FORBIDDEN_FROM_LOGGING.add(DpsHeaders.AUTHORIZATION); + FORBIDDEN_FROM_LOGGING.add(DpsHeaders.ON_BEHALF_OF); + } + + /** + * Get list of current headers + * @return DpsHeaders headers + */ + @Override + public DpsHeaders getHeaders() { + if (headersMap == null) { + log.warning("Headers Map DpsHeaders is null"); + // throw to prevent null reference exception below + throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Invalid Headers", "Headers Map DpsHeaders is null"); + } + DpsHeaders headers = this.getCoreServiceHeaders(headersMap.getHeaders()); + return headers; + } + + /** + * get current logged in user + * @return userEmail + */ + @Override + public String getUser() { + return getHeaders().getUserEmail(); + } + + /** + * get partition id and fallback to account id + * @return Partition ID + */ + @Override + public String getPartitionId() { + return getHeaders().getPartitionIdWithFallbackToAccountId(); + } + + /** + * get the primary partition id + * @return primaryPartitionID + */ + @Override + public String getPrimaryPartitionId() { + return getHeadersMap().get(SlbHeaders.PRIMARY_PARTITION_ID); + } + + /** + * get map of the current headers + * @return Map<String, String> headers + */ + @Override + public Map<String, String> getHeadersMap() { + return getHeaders().getHeaders(); + } + + /** + * supplement the DPSHeaders with any specific core service headers + * @param input Map<String, String> of core headers + * @return DpsHeaders dpsHeaders + */ + @Override + public DpsHeaders getCoreServiceHeaders(Map<String, String> input) { + Preconditions.checkNotNull(input, "input headers cannot be null"); + + DpsHeaders output = DpsHeaders.createFromMap(input); + + return output; + } + + /** + * create string representing a comma delimited list of the current headers + * @return + */ + @Override + public String toString() { + return this.getHeadersMap().entrySet().stream().filter(map -> !FORBIDDEN_FROM_LOGGING.contains(map.getKey().toLowerCase())).map(Map.Entry::toString).collect(Collectors.joining(" | ")); + } + +} \ No newline at end of file