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

Tidy/minor code changes #118

Merged
merged 3 commits into from
Jan 4, 2024
Merged

Conversation

i10416
Copy link
Contributor

@i10416 i10416 commented Jan 4, 2024

This commit changes some codes that I found are a bit verbose and complex without changing their logic.

- move quota_project_id lookup to type declaration location  in order to  make control flow cleaner
- use more functional, less verbose syntax
))
})?;
match &url_creds.format {
None | Some(ExternalCredentialUrlFormat::Text) => Ok(response.text().await?.into()),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can merge None case and Some(Text) case in one clause.

})?;
let json_object = json.as_object().ok_or_else(|| {
match &url_creds.format {
None | Some(ExternalCredentialUrlFormat::Text) => Ok(file_content.into()),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -18,6 +18,16 @@ pub enum Credentials {
ExternalAccount(ExternalAccount),
}

impl Credentials {
pub(crate) fn quota_project_id(&self) -> Option<&str> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I usually put this kind of field access in struct impl section.

@@ -166,7 +176,7 @@ mod jwt {
}
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to derive Deserialize.

remove unused derives from private structs and enums
Copy link
Owner

@abdolence abdolence left a comment

Choose a reason for hiding this comment

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

Thanks for clean ups!
There is still some old verbose code around token sources particularly that I clean from time to time myself.

@abdolence abdolence merged commit bb6ef21 into abdolence:master Jan 4, 2024
i10416 added a commit to i10416/gcloud-sdk-rs that referenced this pull request Jan 5, 2024
abdolence pushed a commit that referenced this pull request Jan 8, 2024
* tidy: remove duplicated code

follow up #118

* chore: fix typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants