Skip to content

Commit 3a33cd3

Browse files
committed
Rename credential types
1 parent d49c897 commit 3a33cd3

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

src/config_default_credentials.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use serde::Serialize;
1010
use tokio::sync::RwLock;
1111
use tracing::{debug, instrument, Level};
1212

13-
use crate::types::{HttpClient, Token, UserCredentials};
13+
use crate::types::{AuthorizedUserRefreshToken, HttpClient, Token};
1414
use crate::{Error, TokenProvider};
1515

1616
/// A token provider that uses the default user credentials
@@ -20,7 +20,7 @@ use crate::{Error, TokenProvider};
2020
pub struct ConfigDefaultCredentials {
2121
client: HttpClient,
2222
token: RwLock<Arc<Token>>,
23-
credentials: UserCredentials,
23+
credentials: AuthorizedUserRefreshToken,
2424
}
2525

2626
impl ConfigDefaultCredentials {
@@ -37,7 +37,7 @@ impl ConfigDefaultCredentials {
3737

3838
let file = fs::File::open(home)
3939
.map_err(|err| Error::Io("failed to open user credentials path", err))?;
40-
let credentials = serde_json::from_reader::<_, UserCredentials>(file)
40+
let credentials = serde_json::from_reader::<_, AuthorizedUserRefreshToken>(file)
4141
.map_err(|err| Error::Json("failed to deserialize UserCredentials", err))?;
4242

4343
debug!(project = ?credentials.quota_project_id, client = credentials.client_id, "found user credentials");
@@ -50,7 +50,10 @@ impl ConfigDefaultCredentials {
5050
}
5151

5252
#[instrument(level = Level::DEBUG, skip(cred, client))]
53-
async fn fetch_token(cred: &UserCredentials, client: &HttpClient) -> Result<Arc<Token>, Error> {
53+
async fn fetch_token(
54+
cred: &AuthorizedUserRefreshToken,
55+
client: &HttpClient,
56+
) -> Result<Arc<Token>, Error> {
5457
client
5558
.token(
5659
&|| {

src/custom_service_account.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use tokio::sync::RwLock;
1515
use tracing::{debug, instrument, Level};
1616
use url::form_urlencoded;
1717

18-
use crate::types::{ApplicationCredentials, HttpClient, Signer, Token};
18+
use crate::types::{HttpClient, ServiceAccountKey, Signer, Token};
1919
use crate::{Error, TokenProvider};
2020

2121
/// A custom service account containing credentials
@@ -27,7 +27,7 @@ use crate::{Error, TokenProvider};
2727
#[derive(Debug)]
2828
pub struct CustomServiceAccount {
2929
client: HttpClient,
30-
credentials: ApplicationCredentials,
30+
credentials: ServiceAccountKey,
3131
signer: Signer,
3232
tokens: RwLock<HashMap<Vec<String>, Arc<Token>>>,
3333
subject: Option<String>,
@@ -37,20 +37,20 @@ impl CustomServiceAccount {
3737
/// Check `GOOGLE_APPLICATION_CREDENTIALS` environment variable for a path to JSON credentials
3838
pub fn from_env() -> Result<Option<Self>, Error> {
3939
debug!("check for GOOGLE_APPLICATION_CREDENTIALS env var");
40-
match ApplicationCredentials::from_env()? {
40+
match ServiceAccountKey::from_env()? {
4141
Some(credentials) => Self::new(credentials, HttpClient::new()?).map(Some),
4242
None => Ok(None),
4343
}
4444
}
4545

4646
/// Read service account credentials from the given JSON file
4747
pub fn from_file<T: AsRef<Path>>(path: T) -> Result<Self, Error> {
48-
Self::new(ApplicationCredentials::from_file(path)?, HttpClient::new()?)
48+
Self::new(ServiceAccountKey::from_file(path)?, HttpClient::new()?)
4949
}
5050

5151
/// Read service account credentials from the given JSON string
5252
pub fn from_json(s: &str) -> Result<Self, Error> {
53-
Self::new(ApplicationCredentials::from_str(s)?, HttpClient::new()?)
53+
Self::new(ServiceAccountKey::from_str(s)?, HttpClient::new()?)
5454
}
5555

5656
/// Set the `subject` to impersonate a user
@@ -59,7 +59,7 @@ impl CustomServiceAccount {
5959
self
6060
}
6161

62-
fn new(credentials: ApplicationCredentials, client: HttpClient) -> Result<Self, Error> {
62+
fn new(credentials: ServiceAccountKey, client: HttpClient) -> Result<Self, Error> {
6363
debug!(project = ?credentials.project_id, email = credentials.client_email, "found credentials");
6464
Ok(Self {
6565
client,
@@ -156,11 +156,7 @@ pub(crate) struct Claims<'a> {
156156
}
157157

158158
impl<'a> Claims<'a> {
159-
pub(crate) fn new(
160-
key: &'a ApplicationCredentials,
161-
scopes: &[&str],
162-
sub: Option<&'a str>,
163-
) -> Self {
159+
pub(crate) fn new(key: &'a ServiceAccountKey, scopes: &[&str], sub: Option<&'a str>) -> Self {
164160
let mut scope = String::with_capacity(16);
165161
for (i, s) in scopes.iter().enumerate() {
166162
if i != 0 {

src/types.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ where
224224
}
225225

226226
#[derive(Deserialize)]
227-
pub(crate) struct ApplicationCredentials {
227+
pub(crate) struct ServiceAccountKey {
228228
/// project_id
229229
pub(crate) project_id: Option<Arc<str>>,
230230
/// private_key
@@ -235,7 +235,7 @@ pub(crate) struct ApplicationCredentials {
235235
pub(crate) token_uri: String,
236236
}
237237

238-
impl ApplicationCredentials {
238+
impl ServiceAccountKey {
239239
pub(crate) fn from_env() -> Result<Option<Self>, Error> {
240240
env::var_os("GOOGLE_APPLICATION_CREDENTIALS")
241241
.map(|path| {
@@ -256,7 +256,7 @@ impl ApplicationCredentials {
256256
}
257257
}
258258

259-
impl FromStr for ApplicationCredentials {
259+
impl FromStr for ServiceAccountKey {
260260
type Err = Error;
261261

262262
fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -265,7 +265,7 @@ impl FromStr for ApplicationCredentials {
265265
}
266266
}
267267

268-
impl fmt::Debug for ApplicationCredentials {
268+
impl fmt::Debug for ServiceAccountKey {
269269
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
270270
f.debug_struct("ApplicationCredentials")
271271
.field("client_email", &self.client_email)
@@ -275,7 +275,7 @@ impl fmt::Debug for ApplicationCredentials {
275275
}
276276

277277
#[derive(Deserialize)]
278-
pub(crate) struct UserCredentials {
278+
pub(crate) struct AuthorizedUserRefreshToken {
279279
/// Client id
280280
pub(crate) client_id: String,
281281
/// Client secret
@@ -286,7 +286,7 @@ pub(crate) struct UserCredentials {
286286
pub(crate) refresh_token: String,
287287
}
288288

289-
impl fmt::Debug for UserCredentials {
289+
impl fmt::Debug for AuthorizedUserRefreshToken {
290290
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
291291
f.debug_struct("UserCredentials")
292292
.field("client_id", &self.client_id)

0 commit comments

Comments
 (0)