Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.amazonaws.athena.connector.credentials.CredentialsProvider;
import com.amazonaws.athena.connector.credentials.DefaultCredentials;
import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException;
import com.amazonaws.athena.connector.lambda.security.CachableSecretsManager;
import com.amazonaws.athena.connectors.snowflake.utils.SnowflakeAuthType;
import com.amazonaws.athena.connectors.snowflake.utils.SnowflakeAuthUtils;
Expand All @@ -29,6 +30,8 @@
import com.google.common.annotations.VisibleForTesting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.services.glue.model.ErrorDetails;
import software.amazon.awssdk.services.glue.model.FederationSourceErrorCode;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.utils.Validate;

Expand Down Expand Up @@ -261,7 +264,8 @@ private ObjectNode requestToken(String requestBody, String tokenEndpoint, String
.reduce("", (acc, line) -> acc + line);

if (responseCode != 200) {
throw new RuntimeException("Failed: " + responseCode + " - " + response);
LOGGER.error("OAuth token request failed with status: {} - {}", responseCode, response);
throw new AthenaConnectorException("OAuth authentication failed with status: " + responseCode, ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_RESPONSE_EXCEPTION.toString()).build());
}

ObjectNode tokenJson = objectMapper.readValue(response, ObjectNode.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.amazonaws.athena.connectors.snowflake.utils;

import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException;
import com.amazonaws.athena.connectors.snowflake.SnowflakeConstants;
import org.apache.commons.lang3.StringUtils;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
Expand All @@ -30,6 +31,8 @@
import org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.services.glue.model.ErrorDetails;
import software.amazon.awssdk.services.glue.model.FederationSourceErrorCode;

import java.io.StringReader;
import java.security.PrivateKey;
Expand Down Expand Up @@ -105,8 +108,8 @@ public static PrivateKey createPrivateKey(String privateKeyString, String passph
return converter.getPrivateKey(privateKeyInfo);
}
catch (Exception e) {
LOGGER.error("Failed to create private key from string: ", e);
throw new Exception("Invalid private key format: " + e.getMessage(), e);
LOGGER.error("Private key parsing failed: {}", e.getMessage());
throw new AthenaConnectorException("Invalid private key format", ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
}
}

Expand Down