Skip to content

Commit bd72944

Browse files
committed
Added API docs.
1 parent 135c9c7 commit bd72944

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

src/KubernetesSdk.Client/Authentication/ExternalCredentialTokenProvider.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System;
1+
// Copyright (c) Christian Prochnow and Contributors. All rights reserved.
2+
// Licensed under the Apache-2.0 license. See LICENSE file in the project root for full license information.
3+
4+
using System;
25
using System.Threading;
36
using System.Threading.Tasks;
47
using Kubernetes.Client.KubeConfig;
@@ -7,6 +10,9 @@
710

811
namespace Kubernetes.Client.Authentication;
912

13+
/// <summary>
14+
/// Provides a bearer token from an external credential process.
15+
/// </summary>
1016
public sealed class ExternalCredentialTokenProvider : ITokenProvider
1117
{
1218
private readonly ExternalCredentialProcess _process;
@@ -18,8 +24,16 @@ internal ExternalCredentialTokenProvider(ExternalCredentialProcess process, Exec
1824
_credential = credential;
1925
}
2026

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="ExternalCredentialTokenProvider"/> class.
29+
/// </summary>
30+
/// <param name="credential">The external credential.</param>
31+
/// <param name="serializerFactory">The <see cref="IKubernetesSerializerFactory"/>.</param>
2132
public ExternalCredentialTokenProvider(ExternalCredential credential, IKubernetesSerializerFactory serializerFactory)
2233
{
34+
Ensure.Arg.NotNull(credential);
35+
Ensure.Arg.NotNull(serializerFactory);
36+
2337
_process = new ExternalCredentialProcess(credential, serializerFactory);
2438
}
2539

@@ -34,6 +48,7 @@ private bool NeedsRefresh()
3448
return DateTime.UtcNow.AddSeconds(30) > _credential.Status.ExpirationTimestamp;
3549
}
3650

51+
/// <inheritdoc />
3752
public async Task<string> GetTokenAsync(bool forceRefresh, CancellationToken cancellationToken)
3853
{
3954
if (forceRefresh || NeedsRefresh())
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
using System.Net.Http.Headers;
1+
// Copyright (c) Christian Prochnow and Contributors. All rights reserved.
2+
// Licensed under the Apache-2.0 license. See LICENSE file in the project root for full license information.
3+
24
using System.Threading;
35
using System.Threading.Tasks;
46

57
namespace Kubernetes.Client.Authentication;
68

9+
/// <summary>
10+
/// Represents a bearer authentication token provider.
11+
/// </summary>
712
public interface ITokenProvider
813
{
9-
Task<string> GetTokenAsync(bool forceRefresh, CancellationToken cancellationToken);
14+
/// <summary>
15+
/// Gets the bearer authentication token.
16+
/// </summary>
17+
/// <param name="forceRefresh">Whether to force a refresh.</param>
18+
/// <param name="cancellationToken">Optional cancellation token.</param>
19+
/// <returns>The bearer authentication token.</returns>
20+
Task<string> GetTokenAsync(bool forceRefresh, CancellationToken cancellationToken = default);
1021
}

src/KubernetesSdk.Client/Authentication/ServiceAccountTokenProvider.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
1+
// Copyright (c) Christian Prochnow and Contributors. All rights reserved.
2+
// Licensed under the Apache-2.0 license. See LICENSE file in the project root for full license information.
3+
14
using System;
25
using System.IO;
36
using System.Threading;
47
using System.Threading.Tasks;
58

69
namespace Kubernetes.Client.Authentication
710
{
11+
/// <summary>
12+
/// Provides bearer authentication tokens from a service account token file.
13+
/// </summary>
814
public sealed class ServiceAccountTokenProvider : ITokenProvider
915
{
10-
private readonly string _tokenPath;
16+
private readonly string _tokenFilePath;
1117
private string? _token;
1218
private DateTime _tokenExpiresAt;
1319

14-
public ServiceAccountTokenProvider(string tokenPath)
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="ServiceAccountTokenProvider"/> class.
22+
/// </summary>
23+
/// <param name="tokenFilePath">The path to the service account token file.</param>
24+
public ServiceAccountTokenProvider(string tokenFilePath)
1525
{
16-
_tokenPath = tokenPath;
26+
Ensure.Arg.NotEmpty(tokenFilePath);
27+
_tokenFilePath = tokenFilePath;
1728
}
1829

1930
private async Task<string> ReadTokenAsync()
2031
{
21-
using var reader = new StreamReader(File.OpenRead(_tokenPath));
32+
using var reader = new StreamReader(File.OpenRead(_tokenFilePath));
2233
return (await reader.ReadToEndAsync()
2334
.ConfigureAwait(false)).Trim();
2435
}
2536

37+
/// <inheritdoc />
2638
public async Task<string> GetTokenAsync(bool forceRefresh, CancellationToken cancellationToken)
2739
{
2840
if (forceRefresh || _tokenExpiresAt < DateTime.UtcNow)

0 commit comments

Comments
 (0)