Skip to content

Commit

Permalink
chore: bump gcp_auth to 0.12.2 (#76)
Browse files Browse the repository at this point in the history
* chore: bump arduino/setup-protoc GH action

The version of protoc used in v1 doesn't seem to exist anymore, as can
be seen by a failing CI run:

https://github.com/liufuyang/bigtable_rs/actions/runs/9357260352/job/25756593924

```
Run arduino/setup-protoc@v1
Getting protoc version: v3.20.3
Downloading archive: https://github.com/protocolbuffers/protobuf/releases/download/v3.20.3/protoc-3.20.3-osx-aarch_64.zip
Error: Error: Failed to download version v3.20.3: Error, Unexpected HTTP response: 404 - 404
```

* chore: bump gcp_auth to 0.12.2

gcp_auth changed their AuthenticationManager API
in djc/gcp_auth#108.

gcp_auth::provider() now returns a Arc<dyn TokenProvider>,
rather than a AuthenticationManager, and AuthenticationManager is gone.

This updates references in bigtable_rs codebase to follow.

Closes #75.
  • Loading branch information
flokli authored Jul 1, 2024
1 parent d1e9cd5 commit 5c5107a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
with:
submodules: 'true'
- name: Install Protoc
uses: arduino/setup-protoc@v1
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Check fmt
Expand Down
2 changes: 1 addition & 1 deletion bigtable_rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ prost-wkt-types = "0.5.0"
serde = { version = "1.0.192", features = ["derive"] }
serde_with = { version = "3.4.0", features = ["base64"] }
# end of above part
gcp_auth = "0.10.0"
gcp_auth = "0.12.2"
log = "0.4.20"
thiserror = "1.0.50"

Expand Down
12 changes: 6 additions & 6 deletions bigtable_rs/src/auth_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};

use gcp_auth::AuthenticationManager;
use gcp_auth::TokenProvider;
use http::{HeaderValue, Request, Response};
use log::debug;
use tonic::body::BoxBody;
Expand All @@ -14,19 +14,19 @@ use tower::Service;
#[derive(Clone)]
pub struct AuthSvc {
inner: Channel,
authentication_manager: Option<Arc<AuthenticationManager>>,
token_provider: Option<Arc<dyn TokenProvider>>,
scopes: String,
}

impl AuthSvc {
pub fn new(
inner: Channel,
authentication_manager: Option<Arc<AuthenticationManager>>,
authentication_manager: Option<Arc<dyn TokenProvider>>,
scopes: String,
) -> Self {
AuthSvc {
inner,
authentication_manager,
token_provider: authentication_manager,
scopes,
}
}
Expand All @@ -48,12 +48,12 @@ impl Service<Request<BoxBody>> for AuthSvc {
// for details on why this is necessary
let clone = self.inner.clone();
let mut inner = std::mem::replace(&mut self.inner, clone);
let authentication_manager = self.authentication_manager.clone();
let token_provider = self.token_provider.clone();
let scopes = self.scopes.clone();

Box::pin(async move {
let scopes = &[scopes.as_ref()];
let token_f_opt = authentication_manager.as_ref().map(|m| m.get_token(scopes));
let token_f_opt = token_provider.as_ref().map(|m| m.token(scopes));

return match token_f_opt {
None => {
Expand Down
20 changes: 10 additions & 10 deletions bigtable_rs/src/bigtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
use std::sync::Arc;
use std::time::Duration;

use gcp_auth::AuthenticationManager;
use gcp_auth::TokenProvider;
use log::info;
use thiserror::Error;
use tokio::net::UnixStream;
Expand Down Expand Up @@ -228,14 +228,14 @@ impl BigTableConnection {
),

Err(_) => {
let authentication_manager = AuthenticationManager::new().await?;
Self::new_with_auth_manager(
let token_provider = gcp_auth::provider().await?;
Self::new_with_token_provider(
project_id,
instance_name,
is_read_only,
channel_size,
timeout,
authentication_manager,
token_provider,
)
}
}
Expand All @@ -258,13 +258,13 @@ impl BigTableConnection {
/// https://docs.rs/tokio/latest/tokio/attr.main.html, but it might be a very different case for
/// different applications.
///
pub fn new_with_auth_manager(
pub fn new_with_token_provider(
project_id: &str,
instance_name: &str,
is_read_only: bool,
channel_size: usize,
timeout: Option<Duration>,
authentication_manager: AuthenticationManager,
token_provider: Arc<dyn TokenProvider>,
) -> Result<Self> {
match std::env::var("BIGTABLE_EMULATOR_HOST") {
Ok(endpoint) => Self::new_with_emulator(
Expand Down Expand Up @@ -316,9 +316,9 @@ impl BigTableConnection {
// construct a channel, by balancing over all endpoints.
let channel = Channel::balance_list(endpoints.into_iter());

let auth_manager = Some(Arc::new(authentication_manager));
let token_provider = Some(token_provider);
Ok(Self {
client: create_client(channel, auth_manager, is_read_only),
client: create_client(channel, token_provider, is_read_only),
table_prefix: Arc::new(table_prefix),
timeout: Arc::new(timeout),
})
Expand Down Expand Up @@ -403,7 +403,7 @@ impl BigTableConnection {
/// from a channel.
fn create_client(
channel: Channel,
authentication_manager: Option<Arc<AuthenticationManager>>,
token_provider: Option<Arc<dyn TokenProvider>>,
read_only: bool,
) -> BigtableClient<AuthSvc> {
let scopes = if read_only {
Expand All @@ -413,7 +413,7 @@ fn create_client(
};

let auth_svc = ServiceBuilder::new()
.layer_fn(|c| AuthSvc::new(c, authentication_manager.clone(), scopes.to_string()))
.layer_fn(|c| AuthSvc::new(c, token_provider.clone(), scopes.to_string()))
.service(channel);
return BigtableClient::new(auth_svc);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ log = "0.4.20"
warp = "0.3.6"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
gcp_auth = "0.10.0"
gcp_auth = "0.12.0"
7 changes: 4 additions & 3 deletions examples/src/custom_path_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use bigtable_rs::google::bigtable::v2::{
MutateRowRequest, Mutation, ReadRowsRequest, RowFilter, RowSet,
};
use env_logger;
use gcp_auth::{AuthenticationManager, CustomServiceAccount};
use gcp_auth::CustomServiceAccount;
use std::error::Error;
use std::sync::Arc;
use std::time::Duration;

#[tokio::main]
Expand All @@ -24,13 +25,13 @@ async fn main() -> Result<(), Box<dyn Error>> {

let json_path: &str = "examples/src/custom_path_fake_key.json";
// make a bigtable client
let connection = bigtable::BigTableConnection::new_with_auth_manager(
let connection = bigtable::BigTableConnection::new_with_token_provider(
project_id,
instance_name,
false,
channel_size,
Some(timeout),
AuthenticationManager::from(CustomServiceAccount::from_file(json_path).unwrap()),
Arc::new(CustomServiceAccount::from_file(json_path).unwrap()),
)?;
let mut bigtable = connection.client();

Expand Down

0 comments on commit 5c5107a

Please sign in to comment.