Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gcs): do not skip signing with allow_anonymous #4979

Merged
merged 2 commits into from
Aug 7, 2024
Merged
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
29 changes: 16 additions & 13 deletions core/src/services/gcs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,24 @@ static BACKOFF: Lazy<ExponentialBuilder> =
Lazy::new(|| ExponentialBuilder::default().with_jitter());

impl GcsCore {
async fn load_token(&self) -> Result<GoogleToken> {
async fn load_token(&self) -> Result<Option<GoogleToken>> {
let cred = { || self.token_loader.load() }
.retry(&*BACKOFF)
.await
.map_err(new_request_credential_error)?;

if let Some(cred) = cred {
Ok(cred)
} else {
Err(Error::new(
ErrorKind::ConfigInvalid,
"no valid credential found",
))
return Ok(Some(cred));
}

if self.allow_anonymous {
return Ok(None);
}

Err(Error::new(
ErrorKind::ConfigInvalid,
"no valid credential found",
))
}

fn load_credential(&self) -> Result<Option<GoogleCredential>> {
Expand All @@ -112,14 +116,13 @@ impl GcsCore {
}

pub async fn sign<T>(&self, req: &mut Request<T>) -> Result<()> {
if self.allow_anonymous {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for the quick fix. Could you also help with load_token? I think the logic should be to skip signing if token.is_none(). Additionally, load_token should correctly manage allow_anonymous.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skip signing if token.is_none()

I believe this is for the other PR which introduces the token: Option<String> field?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is for the other PR which introduces the token: Option<String> field?

I mean:

  • load_token() should return Result<Option<GoogleToken>>
  • if self.token is Some(), we should return it first load_token. (this can be done in the other PR)
  • If load_token() returns None, sign should skip it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, I believe we're talking about the same things here.

I pushed 54c1ae8 just as you wrote this. I believe this covers what you mention here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

if let Some(cred) = self.load_token().await? {
self.signer
.sign(req, &cred)
.map_err(new_request_sign_error)?;
} else {
return Ok(());
}
let cred = self.load_token().await?;

self.signer
.sign(req, &cred)
.map_err(new_request_sign_error)?;

// Always remove host header, let users' client to set it based on HTTP
// version.
Expand Down
Loading