Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
[WIP]Prepend application id to User-Agent header (#859)
Browse files Browse the repository at this point in the history
* Prepend application id to User-Agent header

* shorten UA header application id

* apply the naming convention for UA header application id

* add UA header application id name convention

Co-authored-by: Xiaolu Dai <xiada@microsoft.com>
  • Loading branch information
saragluna and saragluna authored Apr 9, 2020
1 parent 48257f3 commit 4a7fa41
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ public class Constants {

public static final long DEFAULT_REFRESH_INTERVAL_MS = 1800000L;
public static final long TOKEN_ACQUIRE_TIMEOUT_SECS = 60L;

// for the User-Agent header set in track2 SDKs
private static final String SNAPSHOT_VERSION = "snapshot";
private static final String AZURE = "az";
private static final String SPRING = "sp";
private static final String KEY_VAULT = "kv";

public static final String SPRINGBOOT_VERSION = SNAPSHOT_VERSION;
// the max length of application id is 24
public static final String SPRINGBOOT_KEY_VAULT_APPLICATION_ID =
String.join("-", AZURE, SPRING, KEY_VAULT) + "/" + SPRINGBOOT_VERSION;

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.microsoft.azure.keyvault.spring;

import com.azure.core.credential.TokenCredential;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.identity.ClientCertificateCredentialBuilder;
import com.azure.identity.ClientSecretCredential;
import com.azure.identity.ClientSecretCredentialBuilder;
Expand All @@ -15,7 +16,6 @@
import com.azure.security.keyvault.secrets.SecretClientBuilder;
import com.microsoft.azure.telemetry.TelemetrySender;
import lombok.extern.slf4j.Slf4j;

import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.core.env.ConfigurableEnvironment;
Expand All @@ -31,6 +31,7 @@
import java.util.Map;
import java.util.Optional;

import static com.microsoft.azure.keyvault.spring.Constants.SPRINGBOOT_KEY_VAULT_APPLICATION_ID;
import static com.microsoft.azure.telemetry.TelemetryData.SERVICE_NAME;
import static com.microsoft.azure.telemetry.TelemetryData.getClassPackageSimpleName;

Expand Down Expand Up @@ -58,6 +59,7 @@ public void addKeyVaultPropertySource() {
final SecretClient secretClient = new SecretClientBuilder()
.vaultUrl(vaultUri)
.credential(tokenCredential)
.httpLogOptions(new HttpLogOptions().setApplicationId(SPRINGBOOT_KEY_VAULT_APPLICATION_ID))
.buildClient();
try {
final MutablePropertySources sources = this.environment.getPropertySources();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for
* license information.
*/

package com.microsoft.azure.utils;

import org.junit.Assert;
import org.junit.Test;

import static com.microsoft.azure.keyvault.spring.Constants.SPRINGBOOT_KEY_VAULT_APPLICATION_ID;

public class ApplicationIdTest {

@Test
public void maxLength() {
Assert.assertTrue(SPRINGBOOT_KEY_VAULT_APPLICATION_ID.length() <= 24);
}

}

0 comments on commit 4a7fa41

Please sign in to comment.