Skip to content

Commit

Permalink
Merge pull request #1145 from IABTechLab/ian-find-participants-on-old…
Browse files Browse the repository at this point in the history
…-sdks

find participants on old sdks
  • Loading branch information
Ian-Nara authored Nov 7, 2024
2 parents 645ba1c + aae3f73 commit d99c64d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [pull_request, push, workflow_dispatch]

jobs:
build:
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-build-and-test.yaml@v2
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-build-and-test.yaml@v3
with:
java_version: 21
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/publish-all-operators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
fetch-depth: 0

- name: Scan vulnerabilities
uses: IABTechLab/uid2-shared-actions/actions/vulnerability_scan_filesystem@v2
uses: IABTechLab/uid2-shared-actions/actions/vulnerability_scan_filesystem@v3
with:
scan_severity: HIGH,CRITICAL
failure_severity: CRITICAL
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/validate-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ on:

jobs:
build-publish-docker-default:
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v3
with:
failure_severity: ${{ inputs.failure_severity || 'CRITICAL,HIGH' }}
fail_on_error: ${{ inputs.fail_on_error || true }}
cloud_provider: 'default'
java_version: 21
secrets: inherit
build-publish-docker-aws:
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v3
with:
failure_severity: ${{ inputs.failure_severity || 'CRITICAL,HIGH' }}
fail_on_error: ${{ inputs.fail_on_error || true }}
Expand All @@ -36,7 +36,7 @@ jobs:
secrets: inherit
needs: [build-publish-docker-default]
build-publish-docker-gcp:
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v3
with:
failure_severity: ${{ inputs.failure_severity || 'CRITICAL,HIGH' }}
fail_on_error: ${{ inputs.fail_on_error || true }}
Expand All @@ -45,7 +45,7 @@ jobs:
secrets: inherit
needs: [build-publish-docker-aws]
build-publish-docker-azure:
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v3
with:
failure_severity: ${{ inputs.failure_severity || 'CRITICAL,HIGH' }}
fail_on_error: ${{ inputs.fail_on_error || true }}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<enclave-aws.version>2.1.0</enclave-aws.version>
<enclave-azure.version>2.1.0</enclave-azure.version>
<enclave-gcp.version>2.1.0</enclave-gcp.version>
<uid2-shared.version>7.20.0</uid2-shared.version>
<uid2-shared.version>7.20.4</uid2-shared.version>
<image.version>${project.version}</image.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
package com.uid2.operator.vertx;

import com.uid2.operator.util.Tuple;
import com.uid2.shared.Const;
import com.uid2.shared.auth.IAuthorizable;
import com.uid2.shared.auth.IAuthorizableProvider;
import com.uid2.shared.middleware.AuthMiddleware;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Metrics;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class ClientVersionCapturingHandler implements Handler<RoutingContext> {
private final Map<String, Counter> _clientVersionCounters = new HashMap<>();
private static final Logger LOGGER = LoggerFactory.getLogger(ClientVersionCapturingHandler.class);
private static final String BEARER_TOKEN_PREFIX = "bearer ";
private final Map<Tuple.Tuple2<String, String>, Counter> _clientVersionCounters = new HashMap<>();
private IAuthorizableProvider authKeyStore;
private final Set<String> versions = new HashSet<>();

public ClientVersionCapturingHandler(String dir, String whitelistGlob) throws IOException {
public ClientVersionCapturingHandler(String dir, String whitelistGlob, IAuthorizableProvider authKeyStore) throws IOException {
this.authKeyStore = authKeyStore;
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(Paths.get(dir), whitelistGlob)) {
dirStream.forEach(path -> {
final String version = getFileNameWithoutExtension(path);
final Counter counter = Counter
.builder("uid2.client_sdk_versions")
.description("counter for how many http requests are processed per each client sdk version")
.tags("client_version", version)
.register(Metrics.globalRegistry);
_clientVersionCounters.put(version, counter);
versions.add(version);
});
}
}
Expand All @@ -36,11 +44,22 @@ public void handle(RoutingContext context) {
if (clientVersion == null) {
clientVersion = !context.queryParam("client").isEmpty() ? context.queryParam("client").get(0) : null;
}
if (clientVersion != null) {
final Counter counter = _clientVersionCounters.get(clientVersion);
if (counter != null) {
counter.increment();
}
String apiContact;
try {
final String authHeaderValue = context.request().getHeader("Authorization");
final String authKey = extractBearerToken(authHeaderValue);
final IAuthorizable profile = this.authKeyStore.get(authKey);
apiContact = profile.getContact();
apiContact = apiContact == null ? "unknown" : apiContact;
} catch (Exception ex) {
apiContact = "unknown";
}
if (clientVersion != null && versions.contains(clientVersion)) {
_clientVersionCounters.computeIfAbsent(new Tuple.Tuple2<>(apiContact, clientVersion), tuple -> Counter
.builder("uid2.client_sdk_versions")
.description("counter for how many http requests are processed per each client sdk version")
.tags("api_contact", tuple.getItem1(), "client_version", tuple.getItem2())
.register(Metrics.globalRegistry)).increment();;
}
context.next();
}
Expand All @@ -49,4 +68,22 @@ private static String getFileNameWithoutExtension(Path path) {
final String fileName = path.getFileName().toString();
return fileName.indexOf(".") > 0 ? fileName.substring(0, fileName.lastIndexOf(".")) : fileName;
}

private static String extractBearerToken(final String headerValue) {
if (headerValue == null) {
return null;
}

final String v = headerValue.trim();
if (v.length() < BEARER_TOKEN_PREFIX.length()) {
return null;
}

final String givenPrefix = v.substring(0, BEARER_TOKEN_PREFIX.length());

if (!BEARER_TOKEN_PREFIX.equals(givenPrefix.toLowerCase())) {
return null;
}
return v.substring(BEARER_TOKEN_PREFIX.length());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private Router createRoutesSetup() throws IOException {

router.allowForward(AllowForwardHeaders.X_FORWARD);
router.route().handler(new RequestCapturingHandler());
router.route().handler(new ClientVersionCapturingHandler("static/js", "*.js"));
router.route().handler(new ClientVersionCapturingHandler("static/js", "*.js", clientKeyProvider));
router.route().handler(CorsHandler.create()
.addRelativeOrigin(".*.")
.allowedMethod(io.vertx.core.http.HttpMethod.GET)
Expand Down

0 comments on commit d99c64d

Please sign in to comment.