Skip to content

Commit

Permalink
feat: add google drive auth url
Browse files Browse the repository at this point in the history
  • Loading branch information
youmts committed Mar 10, 2023
1 parent 551b522 commit 2f714ff
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/client_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ impl ClientBuilder {
})
.collect();

let scopes_str: Vec<&str> = scopes.iter().map(String::as_str).collect();
let scopes_as_str: Vec<&str> = scopes.iter().map(String::as_str).collect();

let sa_auth = ServiceAccountAuthenticator::from_service_account_key(sa_key, &scopes_str).await?;
let sa_auth = ServiceAccountAuthenticator::from_service_account_key(sa_key, &scopes_as_str).await?;

let mut client = Client::from_authenticator(sa_auth);
client.v2_base_url(self.v2_base_url.clone());
Expand All @@ -68,14 +68,20 @@ impl ClientBuilder {
}

pub async fn build_with_workload_identity(&self, readonly: bool) -> Result<Client, BQError> {
// TODO: 直す
let scope = if readonly {
format!("{BIG_QUERY_AUTH_URL}.readonly")
} else {
BIG_QUERY_AUTH_URL.to_string()
};

let sa_auth = ServiceAccountAuthenticator::with_workload_identity(&[&scope]).await?;
let scopes: Vec<String> = vec![BIG_QUERY_AUTH_URL, DRIVE_AUTH_URL]
.iter()
.map(|auth_base_url| {
if readonly {
format!("{auth_base_url}.readonly")
} else {
auth_base_url.to_string()
}
})
.collect();

let scopes_as_str: Vec<&str> = scopes.iter().map(String::as_str).collect();

let sa_auth = ServiceAccountAuthenticator::with_workload_identity(&scopes_as_str).await?;

let mut client = Client::from_authenticator(sa_auth);
client.v2_base_url(self.v2_base_url.clone());
Expand Down

0 comments on commit 2f714ff

Please sign in to comment.