Commit 663e128b authored by Komal Makkar's avatar Komal Makkar
Browse files

minor changes

parent 24258eb9
Pipeline #29020 failed with stage
in 9 seconds
......@@ -310,7 +310,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
</plugin>
<!--<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.version}</version>
......@@ -331,7 +331,7 @@
</goals>
</execution>
</executions>
</plugin>-->
</plugin>
</plugins>
</build>
</project>
......@@ -59,15 +59,13 @@ import java.util.List;
@Component
public class EventGridTopicStore {
private static final Logger LOGGER = LoggerFactory.getLogger(CosmosStoreBulkOperations.class.getName());
@Autowired
private IEventGridTopicClientFactory eventGridTopicClientFactory;
@Autowired
private ILogger logger;
@Autowired
private PartitionServiceEventGridClient eventGridPartitionClient;
private static final Logger LOGGER = LoggerFactory.getLogger(CosmosStoreBulkOperations.class.getName());
/**
* @param dataPartitionId Data partition id
......@@ -78,7 +76,7 @@ public class EventGridTopicStore {
public void publishToEventGridTopic(final String dataPartitionId, final String topicName, final List<EventGridEvent> eventsList) {
EventGridTopicPartitionInfoAzure eventGridTopicPartitionInfoAzure = this.eventGridPartitionClient.getEventGridTopicInPartition(dataPartitionId, topicName);
String endpoint ;
String endpoint;
try {
endpoint = String.format("https://%s/", new URI(eventGridTopicPartitionInfoAzure.getTopicName()).getHost());
} catch (URISyntaxException e) {
......
......@@ -18,7 +18,6 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.opengroup.osdu.core.common.partition.Property;
/**
* Azure event grid topic data partition variables.
......
......@@ -19,7 +19,6 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.azure.KeyVaultFacade;
import org.opengroup.osdu.azure.cosmosdb.CosmosStoreBulkOperations;
import org.opengroup.osdu.azure.util.AzureServicePrincipleTokenService;
import org.opengroup.osdu.common.Validators;
import org.opengroup.osdu.core.common.model.http.AppException;
......@@ -47,7 +46,7 @@ import java.util.StringTokenizer;
public class PartitionServiceEventGridClient {
private static final String ACCESS_KEY_REGEX = "^eventgrid-([a-zA-Z0-9]*)topic-accesskey$";
private static final String TOPIC_NAME_REGEX = "^eventgrid-([a-zA-Z0-9]*)topic$";
private static final Logger LOGGER = LoggerFactory.getLogger(CosmosStoreBulkOperations.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(PartitionServiceEventGridClient.class.getName());
private final Gson gson = new Gson();
@Autowired
......@@ -174,11 +173,16 @@ public class PartitionServiceEventGridClient {
}
}
private String getSecretValue(Map.Entry<String, Property> property) {
/**
* Get the secret value from KeyVault.
* @param property property
* @return secret
*/
private String getSecretValue(final Map.Entry<String, Property> property) {
JsonElement jsonElement = gson.toJsonTree(property.getValue());
Property p = gson.fromJson(jsonElement, Property.class);
if (p.isSensitive()) {
return getSecretFromKeyVault(p);
return KeyVaultFacade.getSecretWithValidation(this.secretClient, String.valueOf(p.getValue()));
}
return String.valueOf(p.getValue());
}
......@@ -192,9 +196,5 @@ public class PartitionServiceEventGridClient {
this.headers.put(DpsHeaders.AUTHORIZATION, "Bearer " + this.tokenService.getAuthorizationToken());
return this.partitionFactory.create(headers);
}
private String getSecretFromKeyVault(final Property p) {
return KeyVaultFacade.getSecretWithValidation(this.secretClient, String.valueOf(p.getValue()));
}
}
/*
// Copyright © Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
......@@ -78,8 +78,8 @@ class EventGridTopicClientFactoryImplTest {
// Setup
when(this.partitionService.getEventGridTopicInPartition(VALID_DATA_PARTIION_ID, "validtopic")).thenReturn(
EventGridTopicPartitionInfoAzure.builder()
.topicName(Property.builder().value(VALID_TOPIC_NAME).build())
.topicAccessKey(Property.builder().value(VALID_TOPICKEY_NAME).build()).build());
.topicName(VALID_TOPIC_NAME)
.topicAccessKey(VALID_TOPICKEY_NAME).build());
when(this.clientCache.containsKey(any())).thenReturn(false);
......@@ -91,4 +91,4 @@ class EventGridTopicClientFactoryImplTest {
verify(this.clientCache, times(1)).put(any(), any());
}
}
*/
......@@ -27,7 +27,6 @@ import org.opengroup.osdu.azure.partition.PartitionServiceEventGridClient;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.partition.PartitionException;
import org.opengroup.osdu.core.common.partition.Property;
import java.util.ArrayList;
......@@ -41,6 +40,7 @@ class EventGridTopicStoreTest {
private static final String VALID_DATA_PARTIION_ID = "validDataPartitionId";
private static final String VALID_TOPIC = "validTopic";
private static final String INVALID_URI = "://invalidUri";
private static final String VALID_KEY = "validkey";
@Mock
EventGridTopicClientFactoryImpl eventGridTopicClientFactory;
@Mock
......@@ -57,11 +57,11 @@ class EventGridTopicStoreTest {
initMocks(this);
}
/* @Test
@Test
public void should_throwException_given_invalidURI() throws PartitionException {
doReturn(EventGridTopicPartitionInfoAzure.builder()
.topicName(Property.builder().value(INVALID_URI).build())
.topicAccessKey(Property.builder().value("validkey").build()).build())
.topicName(INVALID_URI)
.topicAccessKey(VALID_KEY).build())
.when(this.partitionService).getEventGridTopicInPartition(anyString(), anyString());
......@@ -70,19 +70,19 @@ class EventGridTopicStoreTest {
assertEquals("PartitionInfo for Event Grid Topic " + VALID_TOPIC, appException.getError().getMessage());
verify(this.eventGridClient, times(0)).publishEvents(any(), any());
}*/
}
/*@Test
@Test
public void should_should_invoke_publishEvents() throws PartitionException {
doReturn(EventGridTopicPartitionInfoAzure.builder()
.topicName(String.builder().value(VALID_TOPIC).build())
.topicAccessKey(Property.builder().value("validkey").build()).build())
.topicName(VALID_TOPIC)
.topicAccessKey(VALID_KEY).build())
.when(this.partitionService).getEventGridTopicInPartition(anyString(), anyString());
when(this.eventGridTopicClientFactory.getClient(VALID_DATA_PARTIION_ID, "validTopic")).thenReturn(this.eventGridClient);
this.sut.publishToEventGridTopic(VALID_DATA_PARTIION_ID, "validTopic", new ArrayList<>());
verify(this.eventGridClient, times(1)).publishEvents(any(), any());
}*/
}
}
/*
// Copyright © Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
......@@ -86,10 +85,10 @@ public class PartitionServiceEventGridClientTest {
assertTrue(eventGridTopicPartitionInfoAzureMap.containsKey(topicId2));
// Validate that the EventGridTopicPartitionInfo is mapped correctly.
assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId1).getTopicName().getValue(), eventGridTopicName1);
assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId1).getTopicAccessKey().getValue(), eventGridTopicAccessKey1);
assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId2).getTopicName().getValue(), eventGridTopicName2);
assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId2).getTopicAccessKey().getValue(), eventGridTopicAccessKey2);
assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId1).getTopicName(), eventGridTopicName1);
assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId1).getTopicAccessKey(), eventGridTopicAccessKey1);
assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId2).getTopicName(), eventGridTopicName2);
assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId2).getTopicAccessKey(), eventGridTopicAccessKey2);
}
@Test
......@@ -112,12 +111,11 @@ public class PartitionServiceEventGridClientTest {
partitionServiceClientSpy.getEventGridTopicInPartition("tenant1", "recordstopic");
// Assert
assertEquals(eventGridTopicPartitionInfoAzure.getTopicName().getValue(), eventGridTopicName1);
assertEquals(eventGridTopicPartitionInfoAzure.getTopicAccessKey().getValue(), eventGridTopicAccessKey1);
assertEquals(eventGridTopicPartitionInfoAzure.getTopicName(), eventGridTopicName1);
assertEquals(eventGridTopicPartitionInfoAzure.getTopicAccessKey(), eventGridTopicAccessKey1);
// Assert negative
AppException exception = assertThrows(AppException.class, () -> partitionServiceClientSpy.getEventGridTopicInPartition("tenant1", "recordschangedtopic"));
assertEquals(500, exception.getError().getCode());
}
}
*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment