Skip to content

Commit

Permalink
fix(config): fix hash algo config (#11191)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-leifker authored Aug 16, 2024
1 parent 0e04543 commit 12b3da3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ElasticSearchSystemMetadataService
private final IndexConvention _indexConvention;
private final ESSystemMetadataDAO _esDAO;
private final ESIndexBuilder _indexBuilder;
@Nonnull private final String elasticIdHashAlgo;

private static final String DOC_DELIMETER = "--";
public static final String INDEX_NAME = "system_metadata_service_v1";
Expand Down Expand Up @@ -86,10 +87,9 @@ private String toDocument(SystemMetadata systemMetadata, String urn, String aspe

private String toDocId(@Nonnull final String urn, @Nonnull final String aspect) {
String rawDocId = urn + DOC_DELIMETER + aspect;
String hashAlgo = System.getenv("ELASTIC_ID_HASH_ALGO");
try {
byte[] bytesOfRawDocID = rawDocId.getBytes(StandardCharsets.UTF_8);
MessageDigest md = MessageDigest.getInstance(hashAlgo);
MessageDigest md = MessageDigest.getInstance(elasticIdHashAlgo);
byte[] thedigest = md.digest(bytesOfRawDocID);
return Base64.getEncoder().encodeToString(thedigest);
} catch (NoSuchAlgorithmException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private ElasticSearchSystemMetadataService buildService() {
ESSystemMetadataDAO dao =
new ESSystemMetadataDAO(getSearchClient(), _indexConvention, getBulkProcessor(), 1);
return new ElasticSearchSystemMetadataService(
getBulkProcessor(), _indexConvention, dao, getIndexBuilder());
getBulkProcessor(), _indexConvention, dao, getIndexBuilder(), "MD5");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javax.annotation.Nonnull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand All @@ -19,7 +20,8 @@ public class ElasticSearchSystemMetadataServiceFactory {

@Bean(name = "elasticSearchSystemMetadataService")
@Nonnull
protected ElasticSearchSystemMetadataService getInstance() {
protected ElasticSearchSystemMetadataService getInstance(
@Value("${elasticsearch.idHashAlgo}") final String elasticIdHashAlgo) {
return new ElasticSearchSystemMetadataService(
components.getBulkProcessor(),
components.getIndexConvention(),
Expand All @@ -28,6 +30,7 @@ protected ElasticSearchSystemMetadataService getInstance() {
components.getIndexConvention(),
components.getBulkProcessor(),
components.getNumRetries()),
components.getIndexBuilder());
components.getIndexBuilder(),
elasticIdHashAlgo);
}
}

0 comments on commit 12b3da3

Please sign in to comment.