Skip to content

Commit d99c64d

Browse files
authored
Merge pull request #1145 from IABTechLab/ian-find-participants-on-old-sdks
find participants on old sdks
2 parents 645ba1c + aae3f73 commit d99c64d

File tree

6 files changed

+58
-21
lines changed

6 files changed

+58
-21
lines changed

.github/workflows/build-and-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on: [pull_request, push, workflow_dispatch]
33

44
jobs:
55
build:
6-
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-build-and-test.yaml@v2
6+
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-build-and-test.yaml@v3
77
with:
88
java_version: 21
99
secrets: inherit

.github/workflows/publish-all-operators.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
fetch-depth: 0
5656

5757
- name: Scan vulnerabilities
58-
uses: IABTechLab/uid2-shared-actions/actions/vulnerability_scan_filesystem@v2
58+
uses: IABTechLab/uid2-shared-actions/actions/vulnerability_scan_filesystem@v3
5959
with:
6060
scan_severity: HIGH,CRITICAL
6161
failure_severity: CRITICAL

.github/workflows/validate-image.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ on:
1919

2020
jobs:
2121
build-publish-docker-default:
22-
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2
22+
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v3
2323
with:
2424
failure_severity: ${{ inputs.failure_severity || 'CRITICAL,HIGH' }}
2525
fail_on_error: ${{ inputs.fail_on_error || true }}
2626
cloud_provider: 'default'
2727
java_version: 21
2828
secrets: inherit
2929
build-publish-docker-aws:
30-
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2
30+
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v3
3131
with:
3232
failure_severity: ${{ inputs.failure_severity || 'CRITICAL,HIGH' }}
3333
fail_on_error: ${{ inputs.fail_on_error || true }}
@@ -36,7 +36,7 @@ jobs:
3636
secrets: inherit
3737
needs: [build-publish-docker-default]
3838
build-publish-docker-gcp:
39-
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2
39+
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v3
4040
with:
4141
failure_severity: ${{ inputs.failure_severity || 'CRITICAL,HIGH' }}
4242
fail_on_error: ${{ inputs.fail_on_error || true }}
@@ -45,7 +45,7 @@ jobs:
4545
secrets: inherit
4646
needs: [build-publish-docker-aws]
4747
build-publish-docker-azure:
48-
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2
48+
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v3
4949
with:
5050
failure_severity: ${{ inputs.failure_severity || 'CRITICAL,HIGH' }}
5151
fail_on_error: ${{ inputs.fail_on_error || true }}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<enclave-aws.version>2.1.0</enclave-aws.version>
2323
<enclave-azure.version>2.1.0</enclave-azure.version>
2424
<enclave-gcp.version>2.1.0</enclave-gcp.version>
25-
<uid2-shared.version>7.20.0</uid2-shared.version>
25+
<uid2-shared.version>7.20.4</uid2-shared.version>
2626
<image.version>${project.version}</image.version>
2727
<maven.compiler.source>21</maven.compiler.source>
2828
<maven.compiler.target>21</maven.compiler.target>
Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
11
package com.uid2.operator.vertx;
22

3+
import com.uid2.operator.util.Tuple;
34
import com.uid2.shared.Const;
5+
import com.uid2.shared.auth.IAuthorizable;
6+
import com.uid2.shared.auth.IAuthorizableProvider;
7+
import com.uid2.shared.middleware.AuthMiddleware;
48
import io.micrometer.core.instrument.Counter;
59
import io.micrometer.core.instrument.Metrics;
610
import io.vertx.core.Handler;
711
import io.vertx.ext.web.RoutingContext;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
814

915
import java.io.IOException;
1016
import java.nio.file.DirectoryStream;
1117
import java.nio.file.Files;
1218
import java.nio.file.Path;
1319
import java.nio.file.Paths;
1420
import java.util.HashMap;
21+
import java.util.HashSet;
1522
import java.util.Map;
23+
import java.util.Set;
1624

1725
public class ClientVersionCapturingHandler implements Handler<RoutingContext> {
18-
private final Map<String, Counter> _clientVersionCounters = new HashMap<>();
26+
private static final Logger LOGGER = LoggerFactory.getLogger(ClientVersionCapturingHandler.class);
27+
private static final String BEARER_TOKEN_PREFIX = "bearer ";
28+
private final Map<Tuple.Tuple2<String, String>, Counter> _clientVersionCounters = new HashMap<>();
29+
private IAuthorizableProvider authKeyStore;
30+
private final Set<String> versions = new HashSet<>();
1931

20-
public ClientVersionCapturingHandler(String dir, String whitelistGlob) throws IOException {
32+
public ClientVersionCapturingHandler(String dir, String whitelistGlob, IAuthorizableProvider authKeyStore) throws IOException {
33+
this.authKeyStore = authKeyStore;
2134
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(Paths.get(dir), whitelistGlob)) {
2235
dirStream.forEach(path -> {
2336
final String version = getFileNameWithoutExtension(path);
24-
final Counter counter = Counter
25-
.builder("uid2.client_sdk_versions")
26-
.description("counter for how many http requests are processed per each client sdk version")
27-
.tags("client_version", version)
28-
.register(Metrics.globalRegistry);
29-
_clientVersionCounters.put(version, counter);
37+
versions.add(version);
3038
});
3139
}
3240
}
@@ -36,11 +44,22 @@ public void handle(RoutingContext context) {
3644
if (clientVersion == null) {
3745
clientVersion = !context.queryParam("client").isEmpty() ? context.queryParam("client").get(0) : null;
3846
}
39-
if (clientVersion != null) {
40-
final Counter counter = _clientVersionCounters.get(clientVersion);
41-
if (counter != null) {
42-
counter.increment();
43-
}
47+
String apiContact;
48+
try {
49+
final String authHeaderValue = context.request().getHeader("Authorization");
50+
final String authKey = extractBearerToken(authHeaderValue);
51+
final IAuthorizable profile = this.authKeyStore.get(authKey);
52+
apiContact = profile.getContact();
53+
apiContact = apiContact == null ? "unknown" : apiContact;
54+
} catch (Exception ex) {
55+
apiContact = "unknown";
56+
}
57+
if (clientVersion != null && versions.contains(clientVersion)) {
58+
_clientVersionCounters.computeIfAbsent(new Tuple.Tuple2<>(apiContact, clientVersion), tuple -> Counter
59+
.builder("uid2.client_sdk_versions")
60+
.description("counter for how many http requests are processed per each client sdk version")
61+
.tags("api_contact", tuple.getItem1(), "client_version", tuple.getItem2())
62+
.register(Metrics.globalRegistry)).increment();;
4463
}
4564
context.next();
4665
}
@@ -49,4 +68,22 @@ private static String getFileNameWithoutExtension(Path path) {
4968
final String fileName = path.getFileName().toString();
5069
return fileName.indexOf(".") > 0 ? fileName.substring(0, fileName.lastIndexOf(".")) : fileName;
5170
}
71+
72+
private static String extractBearerToken(final String headerValue) {
73+
if (headerValue == null) {
74+
return null;
75+
}
76+
77+
final String v = headerValue.trim();
78+
if (v.length() < BEARER_TOKEN_PREFIX.length()) {
79+
return null;
80+
}
81+
82+
final String givenPrefix = v.substring(0, BEARER_TOKEN_PREFIX.length());
83+
84+
if (!BEARER_TOKEN_PREFIX.equals(givenPrefix.toLowerCase())) {
85+
return null;
86+
}
87+
return v.substring(BEARER_TOKEN_PREFIX.length());
88+
}
5289
}

src/main/java/com/uid2/operator/vertx/UIDOperatorVerticle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private Router createRoutesSetup() throws IOException {
221221

222222
router.allowForward(AllowForwardHeaders.X_FORWARD);
223223
router.route().handler(new RequestCapturingHandler());
224-
router.route().handler(new ClientVersionCapturingHandler("static/js", "*.js"));
224+
router.route().handler(new ClientVersionCapturingHandler("static/js", "*.js", clientKeyProvider));
225225
router.route().handler(CorsHandler.create()
226226
.addRelativeOrigin(".*.")
227227
.allowedMethod(io.vertx.core.http.HttpMethod.GET)

0 commit comments

Comments
 (0)