Skip to content

Commit

Permalink
Apply clippy and fmt suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
dermesser committed Jun 10, 2024
1 parent 8869c87 commit a2ebecd
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/service_account_impersonation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use yup_oauth2::{read_authorized_user_secret, ServiceAccountImpersonationAuthent

#[tokio::main]
async fn main() {
let svc_email = std::env::args().skip(1).next().unwrap();
let svc_email = std::env::args().nth(1).unwrap();
let home = std::env::var("HOME").unwrap();

let user_secret = read_authorized_user_secret(format!(
Expand Down
10 changes: 3 additions & 7 deletions src/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl ServiceAccountAuthenticator {
) -> AuthenticatorBuilder<C, ServiceAccountFlowOpts> {
AuthenticatorBuilder::new(
ServiceAccountFlowOpts {
key: service_account::FlowOptsKey::Key(service_account_key),
key: service_account::FlowOptsKey::Key(Box::new(service_account_key)),
subject: None,
},
client,
Expand Down Expand Up @@ -477,12 +477,7 @@ impl AccessTokenAuthenticator {
access_token: String,
client: C,
) -> AuthenticatorBuilder<C, AccessTokenFlow> {
AuthenticatorBuilder::new(
AccessTokenFlow {
access_token: access_token,
},
client,
)
AuthenticatorBuilder::new(AccessTokenFlow { access_token }, client)
}
}

Expand Down Expand Up @@ -878,6 +873,7 @@ mod private {
use crate::service_account_impersonator::ServiceAccountImpersonationFlow;
use crate::types::{ApplicationSecret, TokenInfo};

#[allow(clippy::enum_variant_names)]
pub enum AuthFlow {
DeviceFlow(DeviceFlow),
InstalledFlow(InstalledFlow),
Expand Down
4 changes: 2 additions & 2 deletions src/installed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ mod tests {
//assert!(response.status().is_success());
}
Result::Err(err) => {
assert!(false, "Failed to request from local server: {:?}", err);
panic!("Failed to request from local server: {:?}", err);
}
}

Expand All @@ -511,7 +511,7 @@ mod tests {
assert!(response.status().is_success());
}
Result::Err(err) => {
assert!(false, "Failed to request from local server: {:?}", err);
panic!("Failed to request from local server: {:?}", err);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/service_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn decode_rsa_key(pem_pkcs8: &str) -> Result<PrivateKeyDer, io::Error> {
let private_key = rustls_pemfile::pkcs8_private_keys(&mut pem_pkcs8.as_bytes()).next();

match private_key {
Some(Ok(key)) => Ok(PrivateKeyDer::Pkcs8(key.into())),
Some(Ok(key)) => Ok(PrivateKeyDer::Pkcs8(key)),
None => Err(io::Error::new(
io::ErrorKind::InvalidInput,
"Not enough private keys in PEM",
Expand Down Expand Up @@ -164,7 +164,7 @@ pub(crate) enum FlowOptsKey {
/// A path at which the key can be read from disk
Path(PathBuf),
/// An already initialized key
Key(ServiceAccountKey),
Key(Box<ServiceAccountKey>),
}

/// ServiceAccountFlow can fetch oauth tokens using a service account.
Expand All @@ -178,7 +178,7 @@ impl ServiceAccountFlow {
pub(crate) async fn new(opts: ServiceAccountFlowOpts) -> Result<Self, io::Error> {
let key = match opts.key {
FlowOptsKey::Path(path) => crate::read_service_account_key(path).await?,
FlowOptsKey::Key(key) => key,
FlowOptsKey::Key(key) => *key,
};

let signer = JWTSigner::new(&key.private_key)?;
Expand Down Expand Up @@ -227,7 +227,7 @@ mod tests {
use crate::helper::read_service_account_key;

// Valid but deactivated key.
const TEST_PRIVATE_KEY_PATH: &'static str = "examples/Sanguine-69411a0c0eea.json";
const TEST_PRIVATE_KEY_PATH: &str = "examples/Sanguine-69411a0c0eea.json";

// Uncomment this test to verify that we can successfully obtain tokens.
// #[tokio::test]
Expand Down Expand Up @@ -301,7 +301,7 @@ mod tests {

let signature = signature.unwrap();
assert_eq!(
signature.split(".").nth(0).unwrap(),
signature.split('.').next().unwrap(),
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9"
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/service_account_impersonator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
Error,
};

const IAM_CREDENTIALS_ENDPOINT: &'static str = "https://iamcredentials.googleapis.com";
const IAM_CREDENTIALS_ENDPOINT: &str = "https://iamcredentials.googleapis.com";

fn uri(email: &str) -> String {
format!(
Expand Down
6 changes: 1 addition & 5 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ pub(crate) struct ScopeSet<'a, T> {
// Clone to be implemented regardless of whether T is Clone or not.
impl<'a, T> Clone for ScopeSet<'a, T> {
fn clone(&self) -> Self {
ScopeSet {
hash: self.hash,
filter: self.filter,
scopes: self.scopes,
}
*self
}
}
impl<'a, T> Copy for ScopeSet<'a, T> {}
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub struct ConsoleApplicationSecret {
pub mod tests {
use super::*;

pub const SECRET: &'static str =
pub const SECRET: &str =
"{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\
\"client_secret\":\"UqkDJd5RFwnHoiG5x5Rub8SI\",\"token_uri\":\"https://accounts.google.\
com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:\
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async fn create_installed_flow_auth(
} else {
// Parse presented url to obtain redirect_uri with location of local
// code-accepting server.
let uri = Uri::from_str(url.as_ref()).unwrap();
let uri = Uri::from_str(url).unwrap();
let query = uri.query().unwrap();
let parsed = form_urlencoded::parse(query.as_bytes()).into_owned();
let mut rduri = None;
Expand Down

0 comments on commit a2ebecd

Please sign in to comment.