Skip to content

Commit

Permalink
move metric enum one level up for public access.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhumin8 committed Oct 16, 2024
1 parent a3314c7 commit 03de3b1
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 43 deletions.
2 changes: 0 additions & 2 deletions credentials/java/com/google/auth/Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ public String getUniverseDomain() throws IOException {
return GOOGLE_DEFAULT_UNIVERSE;
}



/**
* Get the current request metadata, refreshing tokens if required.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import com.google.api.client.http.HttpStatusCodes;
import com.google.api.client.json.JsonObjectParser;
import com.google.api.client.util.GenericData;
import com.google.auth.oauth2.MetricsUtils.CredentialTypeForMetrics;
import com.google.auth.Credentials;
import com.google.auth.Retryable;
import com.google.auth.ServiceAccountSigner;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2024, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.google.auth.oauth2;

/**
* Defines the different types of credentials that can be used for metrics.
*
* <p>Each credential type is associated with a label that is used for reporting purposes. Add new
* enum constant only when corresponding configs established.
*
* <p>Credentials with type {@code CredentialTypeForMetrics.DO_NOT_SEND} is default value for
* credential implementations that do not set type specifically. It is not expected to send metrics.
*
* <p>
*
* @see #getLabel()
*/
public enum CredentialTypeForMetrics {
USER_CREDENTIALS("u"),
SERVICE_ACCOUNT_CREDENTIALS_AT("sa"),
SERVICE_ACCOUNT_CREDENTIALS_JWT("jwt"),
VM_CREDENTIALS("mds"),
IMPERSONATED_CREDENTIALS("imp"),
DO_NOT_SEND("dns");

private final String label;

private CredentialTypeForMetrics(String label) {
this.label = label;
}

public String getLabel() {
return label;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonObjectParser;
import com.google.api.client.util.Preconditions;
import com.google.auth.oauth2.MetricsUtils.CredentialTypeForMetrics;
import com.google.auth.Credentials;
import com.google.auth.http.HttpTransportFactory;
import com.google.common.annotations.VisibleForTesting;
Expand Down
1 change: 0 additions & 1 deletion oauth2_http/java/com/google/auth/oauth2/IamUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import com.google.api.client.json.JsonObjectParser;
import com.google.api.client.util.ExponentialBackOff;
import com.google.api.client.util.GenericData;
import com.google.auth.oauth2.MetricsUtils.CredentialTypeForMetrics;
import com.google.auth.Credentials;
import com.google.auth.ServiceAccountSigner;
import com.google.auth.http.HttpCredentialsAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import com.google.api.client.http.json.JsonHttpContent;
import com.google.api.client.json.JsonObjectParser;
import com.google.api.client.util.GenericData;
import com.google.auth.oauth2.MetricsUtils.CredentialTypeForMetrics;
import com.google.auth.ServiceAccountSigner;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.http.HttpTransportFactory;
Expand Down
34 changes: 1 addition & 33 deletions oauth2_http/java/com/google/auth/oauth2/MetricsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static String getAuthLibraryVersion() {
return version;
}

public enum RequestType {
enum RequestType {
ACCESS_TOKEN_REQUEST("at"),
ID_TOKEN_REQUEST("it"),
METADATA_SERVER_PING("mds"),
Expand Down Expand Up @@ -115,36 +115,4 @@ static String getGoogleCredentialsMetricsHeader(
static void setMetricsHeader(HttpRequest request, String metricsHeader) {
request.getHeaders().set(MetricsUtils.API_CLIENT_HEADER, metricsHeader);
}

/**
* Defines the different types of credentials that can be used for metrics.
*
* <p>Each credential type is associated with a label that is used for reporting purposes. Add new
* enum constant only when corresponding configs established.
*
* <p>Credentials with type {@code CredentialTypeForMetrics.DO_NOT_SEND} is default value for
* credential implementations that do not set type specifically. It is not expected to send metrics.
*
* <p>
*
* @see #getLabel()
*/
public enum CredentialTypeForMetrics {
USER_CREDENTIALS("u"),
SERVICE_ACCOUNT_CREDENTIALS_AT("sa"),
SERVICE_ACCOUNT_CREDENTIALS_JWT("jwt"),
VM_CREDENTIALS("mds"),
IMPERSONATED_CREDENTIALS("imp"),
DO_NOT_SEND("dns");

private final String label;

private CredentialTypeForMetrics(String label) {
this.label = label;
}

public String getLabel() {
return label;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import com.google.api.client.util.GenericData;
import com.google.api.client.util.Joiner;
import com.google.api.client.util.Preconditions;
import com.google.auth.oauth2.MetricsUtils.CredentialTypeForMetrics;
import com.google.auth.Credentials;
import com.google.auth.RequestMetadataCallback;
import com.google.auth.ServiceAccountSigner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import com.google.api.client.json.JsonObjectParser;
import com.google.api.client.util.GenericData;
import com.google.api.client.util.Preconditions;
import com.google.auth.oauth2.MetricsUtils.CredentialTypeForMetrics;
import com.google.auth.http.HttpTransportFactory;
import com.google.auth.oauth2.MetricsUtils.RequestType;
import com.google.common.base.MoreObjects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import static org.junit.Assert.*;

import com.google.auth.oauth2.MetricsUtils.CredentialTypeForMetrics;
import com.google.auth.oauth2.MetricsUtils.RequestType;
import java.util.regex.Pattern;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
import com.google.api.client.util.Clock;
import com.google.api.client.util.Joiner;
import com.google.auth.oauth2.MetricsUtils.CredentialTypeForMetrics;
import com.google.auth.Credentials;
import com.google.auth.RequestMetadataCallback;
import com.google.auth.TestUtils;
Expand Down

0 comments on commit 03de3b1

Please sign in to comment.