Skip to content

Commit

Permalink
Fix parsing accessUrl from response (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
samanehsan authored Jul 8, 2024
1 parent 52778af commit 58ba5ce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ private void addToPropertiesIfPresentInHeader(
public void addResolvedCloudToProperties(
HttpServletResponse response, Map<String, Object> properties) {
Map<String, Object> responseBody = readResponseBody(response);
if (responseBody.containsKey("accessUrl")) {
Map<String, String> accessUrlResponse = (Map<String, String>) responseBody.get("accessUrl");
String accessUrl = accessUrlResponse.get("url");
if (responseBody.get("accessUrl") != null) {
Map<String, String> accessURLResponse = (Map<String, String>) responseBody.get("accessUrl");
String url = accessURLResponse.get("url");
String resolvedCloud = "";
if (accessUrl.contains("windows.net")) {
if (url.contains("windows.net")) {
resolvedCloud = "azure";
} else if (accessUrl.contains("googleapis.com")) {
} else if (url.contains("googleapis.com")) {
resolvedCloud = "gcp";
}
properties.put("resolvedCloud", resolvedCloud);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,27 @@ void testHappyPathEmittingToBardWithResolvedCloudAzure() throws Exception {
TEST_BEARER_TOKEN, EVENT_NAME, expectedBardProperties(List.of("accessUrl"), "azure"));
}

@Test
void testEmittingToBardOn401Error() throws Exception {
mockBardEmissionsEnabled();
mockResolveDrsResponse(null);
postRequest(
REQUEST_URL,
objectMapper.writeValueAsString(
Map.of(
"url",
DRS_URI,
"cloudPlatform",
CloudPlatformEnum.GS,
"fields",
List.of("accessUrl"))))
.andExpect(status().isOk());

verify(trackingService)
.logEvent(
TEST_BEARER_TOKEN, EVENT_NAME, expectedBardProperties(List.of("accessUrl"), null));
}

@Test
void testDoesNotLogWhenBardEmissionsDisabled() throws Exception {
postRequest(
Expand Down Expand Up @@ -181,8 +202,11 @@ private void mockBardEmissionsEnabled() {
}

private void mockResolveDrsResponse(String accessUrl) {
DrsMetadata drsMetadata =
new DrsMetadata.Builder().accessUrl(new AccessURL().url(accessUrl)).build();
AccessURL metadataAccessUrl = null;
if (accessUrl != null) {
metadataAccessUrl = new AccessURL().url(accessUrl);
}
DrsMetadata drsMetadata = new DrsMetadata.Builder().accessUrl(metadataAccessUrl).build();
AnnotatedResourceMetadata metadata =
AnnotatedResourceMetadata.builder()
.requestedFields(List.of("accessUrl"))
Expand Down

0 comments on commit 58ba5ce

Please sign in to comment.