Skip to content

Commit

Permalink
SNOW-1454348: Remove duplicated consts (#1827)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz authored Jul 18, 2024
1 parent 1c0f40a commit 74a37b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
24 changes: 14 additions & 10 deletions src/main/java/net/snowflake/client/core/SessionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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()
+ "\"");
Expand Down Expand Up @@ -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);
Expand Down
35 changes: 12 additions & 23 deletions src/main/java/net/snowflake/client/core/StmtUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
+ "\"");
Expand Down Expand Up @@ -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
Expand All @@ -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
+ "\"");
Expand Down Expand Up @@ -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
Expand All @@ -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
+ "\"");
Expand Down

0 comments on commit 74a37b2

Please sign in to comment.