Skip to content

Commit

Permalink
remove credential provider
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKaul committed Dec 8, 2024
1 parent b5433c1 commit 1150d66
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 70 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions iceberg-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ thiserror = { workspace = true }
derive-getters = { workspace = true }
iceberg-rust-spec = { path = "../iceberg-rust-spec", version = "0.5.8" }
smallvec = { version = "1.13.2", features = ["const_generics"] }
aws-config = "1.5.10"
aws-credential-types = "1.2.1"

[dev-dependencies]
chrono = { workspace = true }
Expand Down
69 changes: 3 additions & 66 deletions iceberg-rust/src/object_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
Defining the [Bucket] struct for specifying buckets for the ObjectStore.
*/

use std::{fmt::Display, ops::Deref, path::Path, str::FromStr, sync::Arc, time::SystemTime};
use std::{fmt::Display, path::Path, str::FromStr, sync::Arc};

use async_trait::async_trait;
use aws_config::SdkConfig;
use aws_credential_types::{provider::ProvideCredentials, Credentials};
use futures::lock::Mutex;
use object_store::Error as ObjectStoreError;
use object_store::{
aws::{AmazonS3Builder, AmazonS3ConfigKey, AwsCredential},
aws::{AmazonS3Builder, AmazonS3ConfigKey},
gcp::{GoogleCloudStorageBuilder, GoogleConfigKey},
local::LocalFileSystem,
memory::InMemory,
CredentialProvider, ObjectStore,
ObjectStore,
};

use crate::error::Error;
Expand Down Expand Up @@ -151,61 +146,3 @@ impl ObjectStoreBuilder {
}
}
}

/// AWS Sdk credential provider for object_store
#[derive(Debug)]
#[allow(clippy::type_complexity)]
pub struct AwsCredentialProvider {
config: SdkConfig,
cache: Arc<Mutex<Option<(Option<SystemTime>, Credentials)>>>,
}

#[async_trait]
impl CredentialProvider for AwsCredentialProvider {
type Credential = AwsCredential;

async fn get_credential(&self) -> Result<Arc<Self::Credential>, ObjectStoreError> {
let mut guard = self.cache.lock().await;

let is_valid = if let Some((Some(time), _)) = guard.deref() {
*time >= SystemTime::now()
} else {
false
};

if !is_valid {
let provider = self
.config
.credentials_provider()
.ok_or(ObjectStoreError::NotImplemented)?;

let credentials =
provider
.provide_credentials()
.await
.map_err(|err| ObjectStoreError::Generic {
store: "s3",
source: Box::new(err),
})?;
*guard = Some((credentials.expiry(), credentials));
};

let credentials = &guard.as_ref().unwrap().1;

Ok(Arc::new(AwsCredential {
key_id: credentials.access_key_id().to_string(),
secret_key: credentials.secret_access_key().to_string(),
token: credentials.session_token().map(ToString::to_string),
}))
}
}

impl AwsCredentialProvider {
/// Create new credential provider
pub fn new(config: &SdkConfig) -> Self {
Self {
config: config.clone(),
cache: Arc::new(Mutex::new(None)),
}
}
}

0 comments on commit 1150d66

Please sign in to comment.