-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
276 additions
and
24 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
apis/Google.Cloud.BigQuery.V2/Google.Cloud.BigQuery.V2/BigQueryClientBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Google.Api.Gax; | ||
using Google.Api.Gax.Rest; | ||
using Google.Apis.Bigquery.v2; | ||
using Google.Apis.Json; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Google.Cloud.BigQuery.V2 | ||
{ | ||
/// <summary> | ||
/// A builder for <see cref="BigQueryClient"/>, allowing simple client customization. | ||
/// </summary> | ||
public sealed class BigQueryClientBuilder : ClientBuilderBase<BigQueryClient> | ||
{ | ||
/// <summary> | ||
/// The project ID, which must be set before building the client. | ||
/// </summary> | ||
public string ProjectId { get; set; } | ||
|
||
/// <summary> | ||
/// The default location to use for location-specific operations. | ||
/// </summary> | ||
public string DefaultLocation { get; set; } | ||
|
||
/// <inheritdoc /> | ||
public override BigQueryClient Build() | ||
{ | ||
Validate(); | ||
var initializer = CreateServiceInitializer(); | ||
initializer.Serializer = new NewtonsoftJsonSerializer(BigQueryClient.CreateJsonSerializersSettings()); | ||
var service = new BigqueryService(initializer); | ||
return new BigQueryClientImpl(ProjectId, service, DefaultLocation); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override async Task<BigQueryClient> BuildAsync(CancellationToken cancellationToken = default) | ||
{ | ||
Validate(); | ||
var initializer = await CreateServiceInitializerAsync(cancellationToken).ConfigureAwait(false); | ||
initializer.Serializer = new NewtonsoftJsonSerializer(BigQueryClient.CreateJsonSerializersSettings()); | ||
var service = new BigqueryService(initializer); | ||
return new BigQueryClientImpl(ProjectId, service, DefaultLocation); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override string GetDefaultApplicationName() => BigQueryClientImpl.ApplicationName; | ||
|
||
/// <inheritdoc /> | ||
protected override ScopedCredentialProvider GetScopedCredentialProvider() => BigQueryClient.ScopedCredentialProvider; | ||
|
||
/// <inheritdoc /> | ||
protected override void Validate() | ||
{ | ||
base.Validate(); | ||
GaxPreconditions.CheckState(ProjectId != null, "The project ID must be set before building a client."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
apis/Google.Cloud.Storage.V1/Google.Cloud.Storage.V1/StorageClientBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Google.Api.Gax; | ||
using Google.Api.Gax.Rest; | ||
using Google.Apis.Http; | ||
using Google.Apis.Storage.v1; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Google.Cloud.Storage.V1 | ||
{ | ||
/// <summary> | ||
/// A builder for <see cref="StorageClient"/>, allowing simple client customization. | ||
/// </summary> | ||
public sealed class StorageClientBuilder : ClientBuilderBase<StorageClient> | ||
{ | ||
/// <summary> | ||
/// If set to true, no credentials are created when the client is built. | ||
/// </summary> | ||
public bool UnauthenticatedAccess { get; set; } | ||
|
||
/// <summary> | ||
/// The customer-supplied encryption key used by default for all relevant object-based operations. | ||
/// </summary> | ||
public EncryptionKey EncryptionKey { get; set; } | ||
|
||
/// <inheritdoc /> | ||
public override StorageClient Build() | ||
{ | ||
Validate(); | ||
var initializer = CreateServiceInitializer(); | ||
var service = new StorageService(initializer); | ||
return new StorageClientImpl(service, EncryptionKey); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override async Task<StorageClient> BuildAsync(CancellationToken cancellationToken = default) | ||
{ | ||
Validate(); | ||
var initializer = await CreateServiceInitializerAsync(cancellationToken).ConfigureAwait(false); | ||
var service = new StorageService(initializer); | ||
return new StorageClientImpl(service, EncryptionKey); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override IConfigurableHttpClientInitializer GetHttpClientInitializer() => | ||
UnauthenticatedAccess ? null : base.GetHttpClientInitializer(); | ||
|
||
/// <inheritdoc /> | ||
protected override Task<IConfigurableHttpClientInitializer> GetHttpClientInitializerAsync(CancellationToken cancellationToken) => | ||
UnauthenticatedAccess ? Task.FromResult<IConfigurableHttpClientInitializer>(null): base.GetHttpClientInitializerAsync(cancellationToken); | ||
|
||
/// <inheritdoc /> | ||
protected override string GetDefaultApplicationName() => StorageClientImpl.ApplicationName; | ||
|
||
/// <inheritdoc /> | ||
protected override ScopedCredentialProvider GetScopedCredentialProvider() => StorageClient.ScopedCredentialProvider; | ||
|
||
/// <inheritdoc /> | ||
protected override void Validate() | ||
{ | ||
base.Validate(); | ||
GaxPreconditions.CheckState(!UnauthenticatedAccess || (ApiKey == null && Credential == null && CredentialsPath == null && JsonCredentials == null), | ||
"When requesting unauthenticated access, don't specify any other credentials."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...ogle.Cloud.Translation.V2/Google.Cloud.Translation.V2/AdvancedTranslationClientBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Google.Api.Gax.Rest; | ||
using Google.Apis.Translate.v2; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Google.Cloud.Translation.V2 | ||
{ | ||
/// <summary> | ||
/// A builder for <see cref="AdvancedTranslationClient"/>, allowing simple client customization. | ||
/// </summary> | ||
public sealed class AdvancedTranslationClientBuilder : ClientBuilderBase<AdvancedTranslationClient> | ||
{ | ||
/// <summary> | ||
/// The translation model to use. | ||
/// </summary> | ||
public string Model { get; set; } | ||
|
||
/// <inheritdoc /> | ||
public override AdvancedTranslationClient Build() | ||
{ | ||
Validate(); | ||
var initializer = CreateServiceInitializer(); | ||
var service = new TranslateService(initializer); | ||
return new AdvancedTranslationClientImpl(service, Model); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override async Task<AdvancedTranslationClient> BuildAsync(CancellationToken cancellationToken = default) | ||
{ | ||
Validate(); | ||
var initializer = await CreateServiceInitializerAsync(cancellationToken).ConfigureAwait(false); | ||
var service = new TranslateService(initializer); | ||
return new AdvancedTranslationClientImpl(service, Model); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override string GetDefaultApplicationName() => AdvancedTranslationClientImpl.ApplicationName; | ||
|
||
/// <inheritdoc /> | ||
protected override ScopedCredentialProvider GetScopedCredentialProvider() => TranslationClient.ScopedCredentialProvider; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
apis/Google.Cloud.Translation.V2/Google.Cloud.Translation.V2/TranslationClientBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Google.Api.Gax.Rest; | ||
using Google.Apis.Translate.v2; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Google.Cloud.Translation.V2 | ||
{ | ||
/// <summary> | ||
/// A builder for <see cref="TranslationClient"/>, allowing simple client customization. | ||
/// </summary> | ||
public sealed class TranslationClientBuilder : ClientBuilderBase<TranslationClient> | ||
{ | ||
/// <summary> | ||
/// The translation model to use, defaulting to <see cref="TranslationModel.ServiceDefault"/>. | ||
/// </summary> | ||
public TranslationModel TranslationModel { get; set; } = TranslationModel.ServiceDefault; | ||
|
||
/// <inheritdoc /> | ||
public override TranslationClient Build() | ||
{ | ||
Validate(); | ||
var initializer = CreateServiceInitializer(); | ||
var service = new TranslateService(initializer); | ||
return new TranslationClientImpl(service, TranslationModel); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override async Task<TranslationClient> BuildAsync(CancellationToken cancellationToken = default) | ||
{ | ||
Validate(); | ||
var initializer = await CreateServiceInitializerAsync(cancellationToken).ConfigureAwait(false); | ||
var service = new TranslateService(initializer); | ||
return new TranslationClientImpl(service, TranslationModel); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override string GetDefaultApplicationName() => TranslationClientImpl.ApplicationName; | ||
|
||
/// <inheritdoc /> | ||
protected override ScopedCredentialProvider GetScopedCredentialProvider() => TranslationClient.ScopedCredentialProvider; | ||
} | ||
} |