Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Exposes Google.Apis.Http.IHttpClientFactory in Rest.ClientBuilderBase #464

Merged
merged 2 commits into from
Jun 1, 2021

Conversation

amanda-tarafa
Copy link
Collaborator

See googleapis/google-api-dotnet-client#1864

After this has been merged and release, users can either reference the new Gax version directly or wait for an update Storage release. Then their code should look something like this:

// Users implementation of Google.Apis.Http.IHttpClientFactory.
var proxiedHttpClientFactory = new ProxyHttpClientFactory(proxy);

var scopes = new string[] { "https://www.googleapis.com/auth/devstorage.full_control" };
var serviceCredentialFromFile = (ServiceAccountCredential) GoogleCredential.FromFile(sa_file).UnderlyingCredential;
var initializer = new ServiceAccountCredential.Initializer(serviceCredentialFromFile.Id)
{
    ProjectId = serviceCredentialFromFile.ProjectId,
    Key = serviceCredentialFromFile.Key,
    User = serviceCredentialFromFile.User
    HttpClientFactory = proxiedHttpClientFactory,
    Scopes = scopes
};
var credential = GoogleCredential.FromServiceAccountCredential(new ServiceAccountCredential(initializer));

var clientBuilder = new StorageClientBuilder
{
    Credential = credential,
    // All HTTP client instances for API calls will be obtained from this factory
    HttpClientFactory = proxiedHttpClientFactory
}

var client = clientBuilder.Build();

Notice also that once googleapis/google-api-dotnet-client#1851 is in, setting a proxy for a credential will be much more simple as well.

This is to be able to reference Google.Apis.Http.HttpClientFromMessageHandlerFactory in docs.
Towards googleapis/google-api-dotnet-client#1864
…rBase

This is so that client code can customize HTTP clients used.
Closes googleapis/google-api-dotnet-client#1864
@amanda-tarafa amanda-tarafa requested a review from jskeet June 1, 2021 15:22
@amanda-tarafa amanda-tarafa self-assigned this Jun 1, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Jun 1, 2021
Copy link
Collaborator

@jskeet jskeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I'm impressed it's this simple :)

We may want to think about anything else we want to get into a new GAX release before releasing this... presumably as a workaround, users could create the StorageService themselves and then call the StorageClientImpl constructor, right?

@amanda-tarafa
Copy link
Collaborator Author

Yes, it's good that we really use the client factory for everything :).

And yes, users should be able to create the StorageService and then StorageClientImp themselves while we haven't released this.

@amanda-tarafa amanda-tarafa merged commit 58515ad into googleapis:master Jun 1, 2021
@amanda-tarafa amanda-tarafa deleted the http-factory branch June 1, 2021 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants