Skip to content

Commit 6e383cb

Browse files
committed
Fixing merge conflicts to resolve build failures
Signed-off-by: ngsupta1 <guptaneha.e@gmail.com>
1 parent cff5d5d commit 6e383cb

4 files changed

Lines changed: 54 additions & 17 deletions

File tree

data-prepper-plugins/saas-source-plugins/crowdstrike-source/src/main/java/org/opensearch/dataprepper/plugins/source/crowdstrike/CrowdStrikeSourceConfig.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
*/
1414
@Getter
1515
public class CrowdStrikeSourceConfig implements CrawlerSourceConfig {
16-
/**
17-
* Batch size for fetching Threat Intel Feeds
18-
*/
19-
private static final int DEFAULT_IOC_FETCH_BATCH_SIZE = 10000;
16+
2017
private static final int DEFAULT_NUMBER_OF_WORKERS = 5;
2118

2219
@JsonProperty("authentication")
@@ -32,9 +29,4 @@ public class CrowdStrikeSourceConfig implements CrawlerSourceConfig {
3229
@Valid
3330
private int numWorkers = DEFAULT_NUMBER_OF_WORKERS;
3431

35-
@Override
36-
public int getBatchSize() {
37-
return DEFAULT_IOC_FETCH_BATCH_SIZE;
38-
}
39-
4032
}

data-prepper-plugins/saas-source-plugins/crowdstrike-source/src/main/java/org/opensearch/dataprepper/plugins/source/crowdstrike/rest/CrowdStrikeAuthClient.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public class CrowdStrikeAuthClient {
3535
RestTemplate restTemplate = new RestTemplate();
3636
private static final Logger log = LoggerFactory.getLogger(CrowdStrikeAuthClient.class);
3737
private static final String OAUTH_TOKEN_URL = "https://api.crowdstrike.com/oauth2/token";
38+
private static final String ACCESS_TOKEN = "access_token";
39+
private static final String EXPIRE_IN = "expires_in";
40+
3841

3942

4043
public CrowdStrikeAuthClient(final CrowdStrikeSourceConfig sourceConfig) {
@@ -66,10 +69,10 @@ private void getAuthToken() {
6669
HttpEntity<String> request = new HttpEntity<>(headers);
6770
try {
6871
ResponseEntity<Map> response = restTemplate.postForEntity(OAUTH_TOKEN_URL, request, Map.class);
69-
Map<String, Object> tokenData = response.getBody();
70-
this.bearerToken = (String) tokenData.get("access_token");
71-
this.expireTime = Instant.now().plusSeconds((Integer) tokenData.get("expires_in"));
72-
log.info("Access token acquired successfully, expires in {} seconds", tokenData.get("expires_in"));
72+
Map tokenData = response.getBody();
73+
this.bearerToken = (String) tokenData.get(ACCESS_TOKEN);
74+
this.expireTime = Instant.now().plusSeconds((Integer) tokenData.get(EXPIRE_IN));
75+
log.info("Access token acquired successfully");
7376
} catch (HttpClientErrorException ex) {
7477
this.expireTime = Instant.ofEpochMilli(0);
7578
HttpStatus statusCode = ex.getStatusCode();
@@ -87,6 +90,6 @@ public boolean isTokenExpired() {
8790
* Refreshes the bearer token by retrieving a new one from CrowdStrike.
8891
*/
8992
public void refreshToken() {
90-
//getAuthenticationToken();
93+
9194
}
9295
}

data-prepper-plugins/saas-source-plugins/crowdstrike-source/src/test/java/org/opensearch/dataprepper/plugins/source/crowdstrike/CrowdStrikeSourceConfigTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class CrowdStrikeSourceConfigTest {
1313
private static final ObjectMapper objectMapper = new ObjectMapper();
1414
private CrowdStrikeSourceConfig config;
1515

16-
private static final int DEFAULT_BATCH_SIZE = 10000;
1716
private static final int DEFAULT_WORKERS = 5;
1817

1918
@BeforeEach
@@ -23,7 +22,6 @@ void setup() {
2322

2423
@Test
2524
void testDefaultValues() {
26-
assertEquals(DEFAULT_BATCH_SIZE, config.getBatchSize());
2725
assertEquals(DEFAULT_WORKERS, config.getNumWorkers());
2826
assertFalse(config.isAcknowledgments());
2927
}
@@ -44,7 +42,6 @@ void testDeserializationWithValues() throws Exception {
4442
assertNotNull(loadedConfig.getAuthenticationConfig());
4543
assertTrue(loadedConfig.isAcknowledgments());
4644
assertEquals(10, loadedConfig.getNumWorkers());
47-
assertEquals(DEFAULT_BATCH_SIZE, loadedConfig.getBatchSize());
4845
}
4946

5047
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,49 @@
11
package org.opensearch.dataprepper.plugins.source.crowdstrike.configuration;
22

3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertFalse;
12+
import static org.junit.jupiter.api.Assertions.assertNotNull;
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
315
public class AuthenticationConfigTest {
16+
17+
private final ObjectMapper objectMapper = new ObjectMapper();
18+
19+
@Test
20+
void testValidConfigWithClientIdAndSecret() throws JsonProcessingException {
21+
Map<String, Object> yamlConfig = new HashMap<>();
22+
yamlConfig.put("client_id", "dummy-client-id");
23+
yamlConfig.put("client_secret", "dummy-client-secret");
24+
25+
String json = objectMapper.writeValueAsString(yamlConfig);
26+
AuthenticationConfig loadedConfig = objectMapper.readValue(json, AuthenticationConfig.class);
27+
28+
assertNotNull(loadedConfig.getClientId());
29+
assertEquals("dummy-client-id", loadedConfig.getClientId());
30+
assertEquals("dummy-client-secret", loadedConfig.getClientSecret());
31+
assertTrue(loadedConfig.isValidConfig(), "Expected config to be valid when both clientId and clientSecret are set");
32+
}
33+
34+
@Test
35+
void testInvalidConfigWithMissingClientId() throws JsonProcessingException {
36+
Map<String, Object> yamlConfig = new HashMap<>();
37+
yamlConfig.put("client_id", "dummy-client-id");
38+
String json = objectMapper.writeValueAsString(yamlConfig);
39+
AuthenticationConfig loadedConfig = objectMapper.readValue(json, AuthenticationConfig.class);
40+
assertFalse(loadedConfig.isValidConfig(), "Expected config to be invalid when clientId is missing");
41+
}
42+
43+
44+
@Test
45+
void testInvalidConfigWithNoCredentials() {
46+
AuthenticationConfig config = new AuthenticationConfig();
47+
assertFalse(config.isValidConfig(), "Expected config to be invalid when both clientId and clientSecret are missing");
48+
}
449
}

0 commit comments

Comments
 (0)