Skip to content

Commit 2da109e

Browse files
algolia-botFluf22millotp
committed
feat(clients): helper to switch API key in use (generated)
algolia/api-clients-automation#3616 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Thomas Raffray <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent ba7afea commit 2da109e

12 files changed

+133
-12
lines changed

algoliasearch/Clients/AbtestingClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public interface IAbtestingClient
324324
/// </summary>
325325
public partial class AbtestingClient : IAbtestingClient
326326
{
327-
private readonly HttpTransport _transport;
327+
internal HttpTransport _transport;
328328
private readonly ILogger<AbtestingClient> _logger;
329329

330330
/// <summary>
@@ -382,6 +382,17 @@ public AbtestingClient(AbtestingConfig config, IHttpRequester httpRequester, ILo
382382
}
383383
}
384384

385+
/// <summary>
386+
/// Helper to switch the API key sent with each request
387+
/// </summary>
388+
/// <param name="apiKey">Your new API Key</param>
389+
/// <returns></returns>
390+
public void SetClientApiKey(string apiKey)
391+
{
392+
_transport._algoliaConfig.SetClientApiKey(apiKey);
393+
}
394+
395+
385396

386397
/// <inheritdoc />
387398
public async Task<ABTestResponse> AddABTestsAsync(AddABTestsRequest addABTestsRequest, RequestOptions options = null, CancellationToken cancellationToken = default)

algoliasearch/Clients/AlgoliaConfig.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected AlgoliaConfig(string appId, string apiKey, string clientName, string c
4545
/// The admin API Key
4646
/// </summary>
4747
/// <returns></returns>
48-
public string ApiKey { get; }
48+
public string ApiKey { get; set; }
4949

5050
/// <summary>
5151
/// Configurations hosts
@@ -97,5 +97,16 @@ internal Dictionary<string, string> BuildHeaders()
9797
DefaultHeaders[Defaults.UserAgentHeader.ToLowerInvariant()] = UserAgent.ToString();
9898
return DefaultHeaders;
9999
}
100+
101+
/// <summary>
102+
/// Helper to switch the API key sent with each request
103+
/// </summary>
104+
/// <param name="apiKey">Your API Key</param>
105+
/// <returns></returns>
106+
public void SetClientApiKey(string apiKey)
107+
{
108+
ApiKey = apiKey;
109+
DefaultHeaders[Defaults.AlgoliaApiKeyHeader.ToLowerInvariant()] = apiKey;
110+
}
100111
}
101112
}

algoliasearch/Clients/AnalyticsClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ public interface IAnalyticsClient
906906
/// </summary>
907907
public partial class AnalyticsClient : IAnalyticsClient
908908
{
909-
private readonly HttpTransport _transport;
909+
internal HttpTransport _transport;
910910
private readonly ILogger<AnalyticsClient> _logger;
911911

912912
/// <summary>
@@ -964,6 +964,17 @@ public AnalyticsClient(AnalyticsConfig config, IHttpRequester httpRequester, ILo
964964
}
965965
}
966966

967+
/// <summary>
968+
/// Helper to switch the API key sent with each request
969+
/// </summary>
970+
/// <param name="apiKey">Your new API Key</param>
971+
/// <returns></returns>
972+
public void SetClientApiKey(string apiKey)
973+
{
974+
_transport._algoliaConfig.SetClientApiKey(apiKey);
975+
}
976+
977+
967978

968979
/// <inheritdoc />
969980
public async Task<object> CustomDeleteAsync(string path, Dictionary<string, object> parameters = default, RequestOptions options = null, CancellationToken cancellationToken = default)

algoliasearch/Clients/IngestionClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ public interface IIngestionClient
20402040
/// </summary>
20412041
public partial class IngestionClient : IIngestionClient
20422042
{
2043-
private readonly HttpTransport _transport;
2043+
internal HttpTransport _transport;
20442044
private readonly ILogger<IngestionClient> _logger;
20452045

20462046
/// <summary>
@@ -2098,6 +2098,17 @@ public IngestionClient(IngestionConfig config, IHttpRequester httpRequester, ILo
20982098
}
20992099
}
21002100

2101+
/// <summary>
2102+
/// Helper to switch the API key sent with each request
2103+
/// </summary>
2104+
/// <param name="apiKey">Your new API Key</param>
2105+
/// <returns></returns>
2106+
public void SetClientApiKey(string apiKey)
2107+
{
2108+
_transport._algoliaConfig.SetClientApiKey(apiKey);
2109+
}
2110+
2111+
21012112

21022113
/// <inheritdoc />
21032114
public async Task<AuthenticationCreateResponse> CreateAuthenticationAsync(AuthenticationCreate authenticationCreate, RequestOptions options = null, CancellationToken cancellationToken = default)

algoliasearch/Clients/InsightsClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public interface IInsightsClient
186186
/// </summary>
187187
public partial class InsightsClient : IInsightsClient
188188
{
189-
private readonly HttpTransport _transport;
189+
internal HttpTransport _transport;
190190
private readonly ILogger<InsightsClient> _logger;
191191

192192
/// <summary>
@@ -244,6 +244,17 @@ public InsightsClient(InsightsConfig config, IHttpRequester httpRequester, ILogg
244244
}
245245
}
246246

247+
/// <summary>
248+
/// Helper to switch the API key sent with each request
249+
/// </summary>
250+
/// <param name="apiKey">Your new API Key</param>
251+
/// <returns></returns>
252+
public void SetClientApiKey(string apiKey)
253+
{
254+
_transport._algoliaConfig.SetClientApiKey(apiKey);
255+
}
256+
257+
247258

248259
/// <inheritdoc />
249260
public async Task<object> CustomDeleteAsync(string path, Dictionary<string, object> parameters = default, RequestOptions options = null, CancellationToken cancellationToken = default)

algoliasearch/Clients/MonitoringClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public interface IMonitoringClient
350350
/// </summary>
351351
public partial class MonitoringClient : IMonitoringClient
352352
{
353-
private readonly HttpTransport _transport;
353+
internal HttpTransport _transport;
354354
private readonly ILogger<MonitoringClient> _logger;
355355

356356
/// <summary>
@@ -408,6 +408,17 @@ public MonitoringClient(MonitoringConfig config, IHttpRequester httpRequester, I
408408
}
409409
}
410410

411+
/// <summary>
412+
/// Helper to switch the API key sent with each request
413+
/// </summary>
414+
/// <param name="apiKey">Your new API Key</param>
415+
/// <returns></returns>
416+
public void SetClientApiKey(string apiKey)
417+
{
418+
_transport._algoliaConfig.SetClientApiKey(apiKey);
419+
}
420+
421+
411422

412423
/// <inheritdoc />
413424
public async Task<object> CustomDeleteAsync(string path, Dictionary<string, object> parameters = default, RequestOptions options = null, CancellationToken cancellationToken = default)

algoliasearch/Clients/PersonalizationClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public interface IPersonalizationClient
256256
/// </summary>
257257
public partial class PersonalizationClient : IPersonalizationClient
258258
{
259-
private readonly HttpTransport _transport;
259+
internal HttpTransport _transport;
260260
private readonly ILogger<PersonalizationClient> _logger;
261261

262262
/// <summary>
@@ -314,6 +314,17 @@ public PersonalizationClient(PersonalizationConfig config, IHttpRequester httpRe
314314
}
315315
}
316316

317+
/// <summary>
318+
/// Helper to switch the API key sent with each request
319+
/// </summary>
320+
/// <param name="apiKey">Your new API Key</param>
321+
/// <returns></returns>
322+
public void SetClientApiKey(string apiKey)
323+
{
324+
_transport._algoliaConfig.SetClientApiKey(apiKey);
325+
}
326+
327+
317328

318329
/// <inheritdoc />
319330
public async Task<object> CustomDeleteAsync(string path, Dictionary<string, object> parameters = default, RequestOptions options = null, CancellationToken cancellationToken = default)

algoliasearch/Clients/QuerySuggestionsClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public interface IQuerySuggestionsClient
348348
/// </summary>
349349
public partial class QuerySuggestionsClient : IQuerySuggestionsClient
350350
{
351-
private readonly HttpTransport _transport;
351+
internal HttpTransport _transport;
352352
private readonly ILogger<QuerySuggestionsClient> _logger;
353353

354354
/// <summary>
@@ -406,6 +406,17 @@ public QuerySuggestionsClient(QuerySuggestionsConfig config, IHttpRequester http
406406
}
407407
}
408408

409+
/// <summary>
410+
/// Helper to switch the API key sent with each request
411+
/// </summary>
412+
/// <param name="apiKey">Your new API Key</param>
413+
/// <returns></returns>
414+
public void SetClientApiKey(string apiKey)
415+
{
416+
_transport._algoliaConfig.SetClientApiKey(apiKey);
417+
}
418+
419+
409420

410421
/// <inheritdoc />
411422
public async Task<BaseResponse> CreateConfigAsync(ConfigurationWithIndex configurationWithIndex, RequestOptions options = null, CancellationToken cancellationToken = default)

algoliasearch/Clients/RecommendClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public interface IRecommendClient
304304
/// </summary>
305305
public partial class RecommendClient : IRecommendClient
306306
{
307-
private readonly HttpTransport _transport;
307+
internal HttpTransport _transport;
308308
private readonly ILogger<RecommendClient> _logger;
309309

310310
/// <summary>
@@ -362,6 +362,17 @@ public RecommendClient(RecommendConfig config, IHttpRequester httpRequester, ILo
362362
}
363363
}
364364

365+
/// <summary>
366+
/// Helper to switch the API key sent with each request
367+
/// </summary>
368+
/// <param name="apiKey">Your new API Key</param>
369+
/// <returns></returns>
370+
public void SetClientApiKey(string apiKey)
371+
{
372+
_transport._algoliaConfig.SetClientApiKey(apiKey);
373+
}
374+
375+
365376

366377
/// <inheritdoc />
367378
public async Task<object> CustomDeleteAsync(string path, Dictionary<string, object> parameters = default, RequestOptions options = null, CancellationToken cancellationToken = default)

algoliasearch/Clients/SearchClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,7 @@ public partial interface ISearchClient
19501950
/// </summary>
19511951
public partial class SearchClient : ISearchClient
19521952
{
1953-
private readonly HttpTransport _transport;
1953+
internal HttpTransport _transport;
19541954
private readonly ILogger<SearchClient> _logger;
19551955

19561956
/// <summary>
@@ -2008,6 +2008,17 @@ public SearchClient(SearchConfig config, IHttpRequester httpRequester, ILoggerFa
20082008
}
20092009
}
20102010

2011+
/// <summary>
2012+
/// Helper to switch the API key sent with each request
2013+
/// </summary>
2014+
/// <param name="apiKey">Your new API Key</param>
2015+
/// <returns></returns>
2016+
public void SetClientApiKey(string apiKey)
2017+
{
2018+
_transport._algoliaConfig.SetClientApiKey(apiKey);
2019+
}
2020+
2021+
20112022

20122023
/// <inheritdoc />
20132024
public async Task<AddApiKeyResponse> AddApiKeyAsync(ApiKey apiKey, RequestOptions options = null, CancellationToken cancellationToken = default)

algoliasearch/Clients/UsageClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public interface IUsageClient
200200
/// </summary>
201201
public partial class UsageClient : IUsageClient
202202
{
203-
private readonly HttpTransport _transport;
203+
internal HttpTransport _transport;
204204
private readonly ILogger<UsageClient> _logger;
205205

206206
/// <summary>
@@ -258,6 +258,17 @@ public UsageClient(UsageConfig config, IHttpRequester httpRequester, ILoggerFact
258258
}
259259
}
260260

261+
/// <summary>
262+
/// Helper to switch the API key sent with each request
263+
/// </summary>
264+
/// <param name="apiKey">Your new API Key</param>
265+
/// <returns></returns>
266+
public void SetClientApiKey(string apiKey)
267+
{
268+
_transport._algoliaConfig.SetClientApiKey(apiKey);
269+
}
270+
271+
261272

262273
/// <inheritdoc />
263274
public async Task<object> CustomDeleteAsync(string path, Dictionary<string, object> parameters = default, RequestOptions options = null, CancellationToken cancellationToken = default)

algoliasearch/Transport/HttpTransport.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal class HttpTransport
2424
private readonly IHttpRequester _httpClient;
2525
private readonly ISerializer _serializer;
2626
private readonly RetryStrategy _retryStrategy;
27-
private readonly AlgoliaConfig _algoliaConfig;
27+
internal AlgoliaConfig _algoliaConfig;
2828
private string _errorMessage;
2929
private readonly ILogger<HttpTransport> _logger;
3030

0 commit comments

Comments
 (0)