Skip to content

Commit

Permalink
chore: refine error message for empty aws auth (#11271)
Browse files Browse the repository at this point in the history
  • Loading branch information
tabVersion authored Jul 28, 2023
1 parent 33f0cc2 commit b93354d
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/connector/src/aws_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use anyhow::anyhow;
use aws_config::default_provider::region::DefaultRegionChain;
use aws_config::sts::AssumeRoleProvider;
use aws_credential_types::provider::SharedCredentialsProvider;
Expand Down Expand Up @@ -85,12 +86,20 @@ impl AwsAuthProps {
}
}

fn build_credential_provider(&self) -> SharedCredentialsProvider {
SharedCredentialsProvider::new(aws_credential_types::Credentials::from_keys(
self.access_key.as_ref().unwrap_or(&"".into()),
self.secret_key.as_ref().unwrap_or(&"".into()),
self.session_token.clone(),
))
fn build_credential_provider(&self) -> anyhow::Result<SharedCredentialsProvider> {
if self.access_key.is_some() && self.secret_key.is_some() {
Ok(SharedCredentialsProvider::new(
aws_credential_types::Credentials::from_keys(
self.access_key.as_ref().unwrap(),
self.secret_key.as_ref().unwrap(),
self.session_token.clone(),
),
))
} else {
Err(anyhow!(
"Both \"access_key\" and \"secret_access\" are required."
))
}
}

async fn with_role_provider(
Expand All @@ -114,7 +123,7 @@ impl AwsAuthProps {
pub async fn build_config(&self) -> anyhow::Result<SdkConfig> {
let region = self.build_region().await?;
let credentials_provider = self
.with_role_provider(self.build_credential_provider())
.with_role_provider(self.build_credential_provider()?)
.await?;
let mut config_loader = aws_config::from_env()
.region(region)
Expand Down

0 comments on commit b93354d

Please sign in to comment.