From 74a37b2e621c77307aef7e81fa5501b72455eaad Mon Sep 17 00:00:00 2001 From: Dominik Przybysz <132913826+sfc-gh-dprzybysz@users.noreply.github.com> Date: Thu, 18 Jul 2024 09:38:22 +0200 Subject: [PATCH] SNOW-1454348: Remove duplicated consts (#1827) --- .../snowflake/client/core/SessionUtil.java | 24 +++++++------ .../net/snowflake/client/core/StmtUtil.java | 35 +++++++------------ 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/SessionUtil.java b/src/main/java/net/snowflake/client/core/SessionUtil.java index 63cdbe14c..6a9db988f 100644 --- a/src/main/java/net/snowflake/client/core/SessionUtil.java +++ b/src/main/java/net/snowflake/client/core/SessionUtil.java @@ -72,12 +72,11 @@ public class SessionUtil { public static final String SF_QUERY_SESSION_DELETE = "delete"; // Headers - public static final String SF_HEADER_AUTHORIZATION = HttpHeaders.AUTHORIZATION; + @Deprecated + public static final String SF_HEADER_AUTHORIZATION = SFSession.SF_HEADER_AUTHORIZATION; // Authentication type private static final String SF_HEADER_BASIC_AUTHTYPE = "Basic"; - private static final String SF_HEADER_SNOWFLAKE_AUTHTYPE = "Snowflake"; - private static final String SF_HEADER_TOKEN_TAG = "Token"; private static final String CLIENT_STORE_TEMPORARY_CREDENTIAL = "CLIENT_STORE_TEMPORARY_CREDENTIAL"; private static final String CLIENT_REQUEST_MFA_TOKEN = "CLIENT_REQUEST_MFA_TOKEN"; @@ -644,7 +643,7 @@ private static SFLoginOutput newSession( * HttpClient should take authorization header from char[] instead of * String. */ - postRequest.setHeader(SF_HEADER_AUTHORIZATION, SF_HEADER_BASIC_AUTHTYPE); + postRequest.setHeader(SFSession.SF_HEADER_AUTHORIZATION, SF_HEADER_BASIC_AUTHTYPE); setServiceNameHeader(loginInput, postRequest); @@ -1032,8 +1031,13 @@ private static SFLoginOutput tokenRequest(SFLoginInput loginInput, TokenRequestT postRequest.addHeader("accept", "application/json"); postRequest.setHeader( - SF_HEADER_AUTHORIZATION, - SF_HEADER_SNOWFLAKE_AUTHTYPE + " " + SF_HEADER_TOKEN_TAG + "=\"" + headerToken + "\""); + SFSession.SF_HEADER_AUTHORIZATION, + SFSession.SF_HEADER_SNOWFLAKE_AUTHTYPE + + " " + + SFSession.SF_HEADER_TOKEN_TAG + + "=\"" + + headerToken + + "\""); setServiceNameHeader(loginInput, postRequest); @@ -1126,10 +1130,10 @@ static void closeSession(SFLoginInput loginInput) throws SFException, SnowflakeS postRequest, loginInput.getAdditionalHttpHeadersForSnowsight()); postRequest.setHeader( - SF_HEADER_AUTHORIZATION, - SF_HEADER_SNOWFLAKE_AUTHTYPE + SFSession.SF_HEADER_AUTHORIZATION, + SFSession.SF_HEADER_SNOWFLAKE_AUTHTYPE + " " - + SF_HEADER_TOKEN_TAG + + SFSession.SF_HEADER_TOKEN_TAG + "=\"" + loginInput.getSessionToken() + "\""); @@ -1331,7 +1335,7 @@ private static void federatedFlowStep2(SFLoginInput loginInput, String tokenUrl, null, ErrorCode.IDP_CONNECTION_ERROR.getMessageCode(), SqlState.SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION - /* session = */ ); + /* session= */ ); } } catch (MalformedURLException ex) { handleFederatedFlowError(loginInput, ex); diff --git a/src/main/java/net/snowflake/client/core/StmtUtil.java b/src/main/java/net/snowflake/client/core/StmtUtil.java index 3566ea225..96fefe5dc 100644 --- a/src/main/java/net/snowflake/client/core/StmtUtil.java +++ b/src/main/java/net/snowflake/client/core/StmtUtil.java @@ -23,7 +23,6 @@ import net.snowflake.client.log.SFLoggerFactory; import net.snowflake.client.util.SecretDetector; import net.snowflake.common.api.QueryInProgressResponse; -import org.apache.http.HttpHeaders; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpRequestBase; @@ -43,18 +42,8 @@ public class StmtUtil { private static final String SF_PATH_QUERY_RESULT = "/queries/%s/result"; - static final String SF_QUERY_REQUEST_ID = "requestId"; - private static final String SF_QUERY_COMBINE_DESCRIBE_EXECUTE = "combinedDescribe"; - private static final String SF_QUERY_CONTEXT = "queryContext"; - - private static final String SF_HEADER_AUTHORIZATION = HttpHeaders.AUTHORIZATION; - - private static final String SF_HEADER_SNOWFLAKE_AUTHTYPE = "Snowflake"; - - private static final String SF_HEADER_TOKEN_TAG = "Token"; - static final String SF_MEDIA_TYPE = "application/snowflake"; // we don't want to retry canceling forever so put a limit which is @@ -315,7 +304,7 @@ public static StmtOutput execute(StmtInput stmtInput, ExecTimeTelemetryData exec URIBuilder uriBuilder = new URIBuilder(stmtInput.serverUrl); uriBuilder.setPath(SF_PATH_QUERY_V1); - uriBuilder.addParameter(SF_QUERY_REQUEST_ID, stmtInput.requestId); + uriBuilder.addParameter(SFSession.SF_QUERY_REQUEST_ID, stmtInput.requestId); if (stmtInput.combineDescribe) { uriBuilder.addParameter(SF_QUERY_COMBINE_DESCRIBE_EXECUTE, Boolean.TRUE.toString()); @@ -376,10 +365,10 @@ public static StmtOutput execute(StmtInput stmtInput, ExecTimeTelemetryData exec httpRequest.addHeader("accept", stmtInput.mediaType); httpRequest.setHeader( - SF_HEADER_AUTHORIZATION, - SF_HEADER_SNOWFLAKE_AUTHTYPE + SFSession.SF_HEADER_AUTHORIZATION, + SFSession.SF_HEADER_SNOWFLAKE_AUTHTYPE + " " - + SF_HEADER_TOKEN_TAG + + SFSession.SF_HEADER_TOKEN_TAG + "=\"" + stmtInput.sessionToken + "\""); @@ -613,7 +602,7 @@ protected static String getQueryResult(String getResultPath, StmtInput stmtInput uriBuilder.setPath(getResultPath); - uriBuilder.addParameter(SF_QUERY_REQUEST_ID, UUIDUtils.getUUID().toString()); + uriBuilder.addParameter(SFSession.SF_QUERY_REQUEST_ID, UUIDUtils.getUUID().toString()); httpRequest = new HttpGet(uriBuilder.build()); // Add custom headers before adding common headers @@ -623,10 +612,10 @@ protected static String getQueryResult(String getResultPath, StmtInput stmtInput httpRequest.addHeader("accept", stmtInput.mediaType); httpRequest.setHeader( - SF_HEADER_AUTHORIZATION, - SF_HEADER_SNOWFLAKE_AUTHTYPE + SFSession.SF_HEADER_AUTHORIZATION, + SFSession.SF_HEADER_SNOWFLAKE_AUTHTYPE + " " - + SF_HEADER_TOKEN_TAG + + SFSession.SF_HEADER_TOKEN_TAG + "=\"" + stmtInput.sessionToken + "\""); @@ -717,7 +706,7 @@ public static void cancel(StmtInput stmtInput) throws SFException, SnowflakeSQLE uriBuilder.setPath(SF_PATH_ABORT_REQUEST_V1); - uriBuilder.addParameter(SF_QUERY_REQUEST_ID, UUIDUtils.getUUID().toString()); + uriBuilder.addParameter(SFSession.SF_QUERY_REQUEST_ID, UUIDUtils.getUUID().toString()); httpRequest = new HttpPost(uriBuilder.build()); // Add custom headers before adding common headers @@ -742,10 +731,10 @@ public static void cancel(StmtInput stmtInput) throws SFException, SnowflakeSQLE httpRequest.addHeader("accept", stmtInput.mediaType); httpRequest.setHeader( - SF_HEADER_AUTHORIZATION, - SF_HEADER_SNOWFLAKE_AUTHTYPE + SFSession.SF_HEADER_AUTHORIZATION, + SFSession.SF_HEADER_SNOWFLAKE_AUTHTYPE + " " - + SF_HEADER_TOKEN_TAG + + SFSession.SF_HEADER_TOKEN_TAG + "=\"" + stmtInput.sessionToken + "\"");