Skip to content

Allow overriding the project id for a given TokenProvider #117

Open
@MJDSys

Description

@MJDSys

In my company's application, we have created different GCP resources in different GCP projects, to allow us to more easily isolate what applications can access which services. We then wish to have our rust application use a service account with credentials acquired from the metadata service access resources in a different project. Similarly, we'd like the option to have our developers use their local credentials to access different projects for development purposes.

Currently, we are using our own local wrapper to provide this functionality, which looks like this:

pub struct ProviderWrapper<T: TokenProvider + ?Sized> {
    provider: Arc<T>,
    project: String,
}

#[async_trait]
impl<T: TokenProvider + ?Sized> TokenProvider for ProviderWrapper<T> {
    async fn token(&self, scopes: &[&str]) -> Result<Arc<Token>, gcp_auth::Error> {
        self.provider.token(scopes).await
    }
    async fn project_id(&self) -> Result<Arc<str>, gcp_auth::Error> {
        Ok(Arc::from(self.project.clone()))
    }
}

As we found this useful, would a PR implementing this solution on the TokenProvider trait be useful to this project? I'm thinking it would be a new method, override_project(self, project_id: String) -> impl TokenProvider, that would return a similar ProviderWrapper.

Thanks for providing this crate!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions