standard-ai / ya-gcp

Apache License 2.0
7 stars 8 forks source link

Update yup-oauth and add support for service account impersonation #25

Closed matthew-healy closed 1 year ago

matthew-healy commented 1 year ago

Note: this PR was originally opened as #21, however since that was a PR from @xlambein's fork of this repo I had to move the branch over to this repo in order to push new changes. I'm reopening the PR exactly as before, but with this note & a commit which makes tokio a required dependency.

Original description

This PR's aim was to add service account impersonation as an authentication method, but in order to do this I had to update the version of yup-oauth to 8.1, which required quite a lot of changes.

The main one is that I removed the concept of TokenSource from this repository, for two reasons:

Since version 6, the library has added many new authenticators, covering (I think) the use cases that TokenSource was covering. Instead of a token source, AuthGrpcService now carries an authenticator and a list of scopes.

Updating yup-oauth also required replacing the C: crate::Connect + Clone + Send + Sync + 'static bounds with the following mouthful:

C: tower::Service<http::Uri> + Clone + Send + Sync + 'static,
C::Response: hyper::client::connect::Connection
    + tokio::io::AsyncRead
    + tokio::io::AsyncWrite
    + Send
    + Unpin
    + 'static,
C::Future: Send + Unpin + 'static,
C::Error: Into<Box<dyn std::error::Error + Send + Sync>>,

the reason being that hyper::Connect is actually a private trait that cannot be implemented, and so yup-oauth changed at some point to the bounds above, which are equivalent, albeit annoying.