-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First attemt to send really collected data to the server
- Loading branch information
Serhii Vydiuk
committed
Dec 23, 2024
1 parent
ef5e3ca
commit e8f660a
Showing
12 changed files
with
88 additions
and
50 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
...a/examples/OwlTestApp/src/main/java/com/readme/example/CustomUserDataCollectorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 21 additions & 6 deletions
27
...-starter/src/main/java/com/readme/starter/datacollection/ServletRequestDataCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,39 @@ | ||
package com.readme.starter.datacollection; | ||
|
||
import com.readme.dataextraction.RequestDataCollector; | ||
import com.readme.domain.UserData; | ||
import com.readme.starter.config.ReadmeConfigurationProperties; | ||
|
||
import com.readme.dataextraction.payload.ApiKeyMasker; | ||
import com.readme.dataextraction.payload.PayloadData; | ||
import com.readme.dataextraction.payload.RequestDataCollector; | ||
import com.readme.dataextraction.user.UserData; | ||
import com.readme.datatransfer.DataSender; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.UUID; | ||
|
||
import static com.readme.dataextraction.payload.ApiKeyMasker.*; | ||
|
||
@Slf4j | ||
@AllArgsConstructor | ||
@Component | ||
public class ServletRequestDataCollector implements RequestDataCollector<ServletDataPayloadAdapter> { | ||
|
||
private ReadmeConfigurationProperties readmeProperties; | ||
private DataSender dataSender; | ||
|
||
@Override | ||
public void collect(ServletDataPayloadAdapter dataPayload, UserData userData) { | ||
String readmeAPIKey = readmeProperties.getReadmeApiKey(); | ||
String maskedApiKey = mask(userData.getApiKey()); | ||
PayloadData payloadData = PayloadData.builder() | ||
.apiKey(maskedApiKey) | ||
.email(userData.getEmail()) | ||
.label(userData.getLabel()) | ||
.logId(UUID.randomUUID()) | ||
.requestBody(dataPayload.getRequestBody()) | ||
.build(); | ||
|
||
log.info(">>>>>>>> Sending data to the server with key {}", readmeAPIKey); | ||
dataSender.send(payloadData); | ||
log.info(">>>>>>>> Sending data to the server..."); | ||
log.info(">>>>>>>> and user data: {}", userData); | ||
} | ||
} |
10 changes: 4 additions & 6 deletions
10
...er/src/main/java/com/readme/starter/datacollection/userinfo/ServletUserDataCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...oot-starter/src/test/java/com/readme/starter/datacollection/DataCollectionFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...rc/test/java/com/readme/starter/datacollection/userinfo/ServletUserDataCollectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ges/java/readme-metrics/src/main/java/com/readme/dataextraction/payload/ApiKeyMasker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.readme.dataextraction.payload; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.Base64; | ||
|
||
public class ApiKeyMasker { | ||
|
||
public static String mask(String apiKey) { | ||
try { | ||
String base64Hash = Base64.getEncoder() | ||
.encodeToString(MessageDigest | ||
.getInstance("SHA-512") | ||
.digest(apiKey.getBytes(StandardCharsets.UTF_8))); | ||
|
||
String last4Digits = apiKey.substring(apiKey.length() - 4); | ||
return "sha512-" + base64Hash + "?" + last4Digits; | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException("SHA-512 algorithm not available", e); | ||
} catch (StringIndexOutOfBoundsException e) { | ||
throw new IllegalArgumentException("API key must be at least 4 characters long", e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters