lquerel / gcp-bigquery-client

GCP BigQuery Client (Rust)
Apache License 2.0
97 stars 67 forks source link

struct ServiceAccount is used but not available #75

Closed debrutal closed 3 weeks ago

debrutal commented 9 months ago

Hi, this might be an issue on my side understanding the whole situation but i ran into an issue using service-account keys.

Authenticating a client using

    /// Constructs a new BigQuery client from a [`ServiceAccountKey`].
    /// # Argument
    /// * `sa_key` - A GCP Service Account Key `yup-oauth2` object.
    /// * `readonly` - A boolean setting whether the acquired token scope should be readonly.
    ///
    /// [`ServiceAccountKey`]: https://docs.rs/yup-oauth2/*/yup_oauth2/struct.ServiceAccountKey.html
    pub async fn from_service_account_key(sa_key: ServiceAccountKey, readonly: bool) -> Result<Self, BQError> {
        ClientBuilder::new()
            .build_from_service_account_key(sa_key, readonly)
            .await
    }

refrences the struct ServiceAccountKey (Struct origins at yup-oauth2@8.3.2)

While using the default features inside this crate, i cannot find the ServiceAccountKey. So i cannot create a struct which es needed as a parameter.

I am not sure how to manage this and if it is even related to this crate, since i don't know the responsibilities on who has to include what. Any hint highly appreciated.

Workaround

A workaround for me is to read the key-file of the service account and use

from_service_account_key_file(sa_key_file: &str) -> Result<Self, BQError>

Nice lib btw!

haxorcize commented 8 months ago

I added yup-oauth2 to my Cargo.toml (Saw in cargo.lock what version my gcp-bigquery-client depended on) and then simply did: let sa_key: ServiceAccountKey = serde_json::from_str(service_account_key_json_string)?; (replace service_account_key_json_string with your &str of choice)

serprex commented 5 months ago

note that yup-oauth2 is now reexported by gcp-bigquery-client, so no longer need to add it to your own Cargo.toml