yoshidan / google-cloud-rust

Google Cloud Client Libraries for Rust.
MIT License
222 stars 80 forks source link

Support impersonate credentials #150

Closed JoepdeJong closed 1 year ago

JoepdeJong commented 1 year ago

Hi there! 👋

I've implemented the support for impersonating users, but since I'm new to Rust, I'm facing some difficulties in making the sub parameter optional. Could anyone provide me with some suggestions on how to achieve this? I already looked at implementing a set_subject mutator, but that didn't work out, as the create_token_source calls the token() function directly..

What is best practice? Thank you in advance!

yoshidan commented 1 year ago

What errors are you facing? It would be helpful if you could post a stack trace.

JoepdeJong commented 1 year ago

What errors are you facing? It would be helpful if you could post a stack trace.

I am not facing errors at the moment. However, my implementation is not backwards compatible as one needs to define a sub in the Config. I asked around at noticed that backwards compatibility is very difficult to support in Rust.

What are your views on that? If it is not a problem to you, then the PR is ready to be merged.

yoshidan commented 1 year ago

Please run cargo fmt to fix CI.

yoshidan commented 1 year ago

Backward compatibility is not possible because the current Config has exposed fields. It would have been possible if Config's fields were private scoped and implemented to provide new methods, setter/getter, builder patterns, #[non_exhaustive] etc.

yoshidan commented 1 year ago

Please run cargo clippy --fix to fix CI.

JoepdeJong commented 1 year ago

done!

yoshidan commented 1 year ago

The current CI error will be resolved if you implement this correction.

JoepdeJong commented 1 year ago

The current CI error will be resolved if you implement this correction.

I have made the changes again.

I do however get warnings when I run cargo clippy --fix:

error[E0433]: failed to resolve: use of undeclared crate or module `google_cloud_gax`
   --> default/src/lib.rs:176:9
    |
176 |     use google_cloud_gax::conn::Environment;
    |         ^^^^^^^^^^^^^^^^ use of undeclared crate or module `google_cloud_gax`
    |
help: there is a crate or module with a similar name
    |
176 |     use google_cloud_auth::conn::Environment;
    |         ~~~~~~~~~~~~~~~~~

error[E0433]: failed to resolve: use of undeclared crate or module `google_cloud_spanner`
   --> default/src/lib.rs:182:22
    |
182 |         let config = google_cloud_spanner::client::ClientConfig::default()
    |                      ^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `google_cloud_spanner`
    |
help: there is a crate or module with a similar name
    |
182 |         let config = google_cloud_auth::client::ClientConfig::default()
    |                      ~~~~~~~~~~~~~~~~~

error[E0433]: failed to resolve: use of undeclared crate or module `google_cloud_pubsub`
   --> default/src/lib.rs:193:22
    |
193 |         let config = google_cloud_pubsub::client::ClientConfig::default()
    |                      ^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `google_cloud_pubsub`
    |
help: there is a crate or module with a similar name
    |
193 |         let config = google_cloud_auth::client::ClientConfig::default()
    |                      ~~~~~~~~~~~~~~~~~

error[E0433]: failed to resolve: use of undeclared crate or module `google_cloud_storage`
   --> default/src/lib.rs:204:22
    |
204 |         let config = google_cloud_storage::client::ClientConfig::default()
    |                      ^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `google_cloud_storage`

warning: unused import: `crate::WithAuthExt`
   --> default/src/lib.rs:178:9
    |
178 |     use crate::WithAuthExt;
    |         ^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(unused_imports)]` on by default

For more information about this error, try `rustc --explain E0433`.
warning: `google-cloud-default` (lib test) generated 1 warning
error: could not compile `google-cloud-default` due to 4 previous errors; 1 warning emitted
warning: build failed, waiting for other jobs to finish...
yoshidan commented 1 year ago

You need to specify the features.

cd default && cargo clippy --fix  --features=spanner,pubsub,storage
JoepdeJong commented 1 year ago

You need to specify the features.

cd default && cargo clippy --fix  --features=spanner,pubsub,storage

Thanks!

Now it works:

   Compiling proc-macro2 v1.0.58
   Compiling log v0.4.17
   Compiling quote v1.0.27
   Compiling tokio v1.28.1
    Checking tracing-core v0.1.31
   Compiling syn v1.0.109
   Compiling syn v2.0.16
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling prost-derive v0.11.9
    Checking mio v0.8.6
    Checking want v0.3.0
    Checking rustls v0.21.1
   Compiling tokio-macros v2.1.0
   Compiling futures-macro v0.3.28
   Compiling tracing-attributes v0.1.24
   Compiling serde_derive v1.0.163
   Compiling async-trait v0.1.68
   Compiling pin-project-internal v1.1.0
   Compiling thiserror-impl v1.0.40
   Compiling async-stream-impl v0.3.5
   Compiling serial_test_derive v0.9.0
    Checking async-stream v0.3.5
    Checking futures-util v0.3.28
    Checking google-cloud-token v0.1.1 (/Users/joep/Cache/google-cloud-rust/foundation/token)
    Checking prost v0.11.9
    Checking pin-project v1.1.0
    Checking thiserror v1.0.40
    Checking tracing v0.1.37
    Checking serde v1.0.163
    Checking prost-types v0.11.9
    Checking axum-core v0.3.4
    Checking futures-executor v0.3.28
    Checking futures v0.3.28
    Checking serial_test v0.9.0
    Checking tokio-util v0.7.8
    Checking tokio-io-timeout v1.2.0
    Checking tokio-stream v0.1.14
    Checking tokio-rustls v0.24.0
    Checking tokio-native-tls v0.3.1
    Checking tokio-retry v0.3.0
    Checking h2 v0.3.19
    Checking tower v0.4.13
    Checking time v0.3.21
    Checking serde_json v1.0.96
    Checking serde_urlencoded v0.7.1
    Checking simple_asn1 v0.6.2
    Checking jsonwebtoken v8.3.0
    Checking hyper v0.14.26
    Checking axum v0.6.18
    Checking hyper-timeout v0.4.1
    Checking hyper-tls v0.5.0
    Checking reqwest v0.11.18
    Checking google-cloud-metadata v0.3.2 (/Users/joep/Cache/google-cloud-rust/foundation/metadata)
    Checking google-cloud-storage v0.11.1 (/Users/joep/Cache/google-cloud-rust/storage)
    Checking google-cloud-auth v0.9.2 (/Users/joep/Cache/google-cloud-rust/foundation/auth)
    Checking tonic v0.9.2
    Checking google-cloud-gax v0.14.2 (/Users/joep/Cache/google-cloud-rust/foundation/gax)
    Checking google-cloud-googleapis v0.9.0 (/Users/joep/Cache/google-cloud-rust/googleapis)
    Checking google-cloud-longrunning v0.14.0 (/Users/joep/Cache/google-cloud-rust/foundation/longrunning)
    Checking google-cloud-pubsub v0.15.0 (/Users/joep/Cache/google-cloud-rust/pubsub)
    Checking google-cloud-spanner v0.19.0 (/Users/joep/Cache/google-cloud-rust/spanner)
    Checking google-cloud-default v0.3.0 (/Users/joep/Cache/google-cloud-rust/default)
    Finished dev [unoptimized + debuginfo] target(s) in 12.88s
yoshidan commented 1 year ago

Thanks!