-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial port of authentication strategies from branch "feature/auth-s…
- Loading branch information
Showing
31 changed files
with
939 additions
and
214 deletions.
There are no files selected for viewing
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
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
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
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
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
2 changes: 1 addition & 1 deletion
2
src/KubeClient.Extensions.Configuration/KubeClient.Extensions.Configuration.csproj
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
2 changes: 1 addition & 1 deletion
2
src/KubeClient.Extensions.CustomResources/KubeClient.Extensions.CustomResources.csproj
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
2 changes: 1 addition & 1 deletion
2
...ubeClient.Extensions.DependencyInjection/KubeClient.Extensions.DependencyInjection.csproj
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
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
4 changes: 2 additions & 2 deletions
4
src/KubeClient.Extensions.KubeConfig/KubeClient.Extensions.KubeConfig.csproj
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
4 changes: 2 additions & 2 deletions
4
src/KubeClient.Extensions.WebSockets/KubeClient.Extensions.WebSockets.csproj
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
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,83 @@ | ||
using HTTPlease; | ||
using System; | ||
using System.Net.Http; | ||
|
||
namespace KubeClient.Authentication | ||
{ | ||
using MessageHandlers; | ||
|
||
/// <summary> | ||
/// A Kubernetes API authentication strategy that uses HTTP Basic (username / password) authentication. | ||
/// </summary> | ||
public class BasicAuthStrategy | ||
: KubeAuthStrategy | ||
{ | ||
/// <summary> | ||
/// Create a new <see cref="BasicAuthStrategy"/>. | ||
/// </summary> | ||
public BasicAuthStrategy() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// The username for authentication to the Kubernetes API. | ||
/// </summary> | ||
public string UserName { get; set; } | ||
|
||
/// <summary> | ||
/// The password for authentication to the Kubernetes API. | ||
/// </summary> | ||
public string Password { get; set; } | ||
|
||
/// <summary> | ||
/// Validate the authentication strategy's configuration. | ||
/// </summary> | ||
/// <exception cref="KubeClientException"> | ||
/// The authentication strategy's configuration is incomplete or invalid. | ||
/// </exception> | ||
public override void Validate() | ||
{ | ||
if (string.IsNullOrEmpty(UserName)) | ||
throw new KubeClientException("The username for for authentication to the Kubernetes API has not been configured."); | ||
|
||
if (string.IsNullOrEmpty(Password)) | ||
throw new KubeClientException("The password for for authentication to the Kubernetes API has not been configured."); | ||
} | ||
|
||
/// <summary> | ||
/// Configure the <see cref="ClientBuilder"/> used to create <see cref="HttpClient"/>s used by the API client. | ||
/// </summary> | ||
/// <param name="clientBuilder"> | ||
/// The <see cref="ClientBuilder"/> to configure. | ||
/// </param> | ||
/// <returns> | ||
/// The configured <see cref="ClientBuilder"/>. | ||
/// </returns> | ||
public override ClientBuilder Configure(ClientBuilder clientBuilder) | ||
{ | ||
if (clientBuilder == null) | ||
throw new ArgumentNullException(nameof(clientBuilder)); | ||
|
||
Validate(); | ||
|
||
return clientBuilder.AddHandler( | ||
() => new BasicAuthenticationHandler(UserName, Password) | ||
); | ||
} | ||
|
||
/// <summary> | ||
/// Create a deep clone of the authentication strategy. | ||
/// </summary> | ||
/// <returns> | ||
/// The cloned <see cref="KubeAuthStrategy"/>. | ||
/// </returns> | ||
public override KubeAuthStrategy Clone() | ||
{ | ||
return new BasicAuthStrategy | ||
{ | ||
UserName = UserName, | ||
Password = Password | ||
}; | ||
} | ||
} | ||
} |
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,74 @@ | ||
using HTTPlease; | ||
using System; | ||
using System.Net.Http; | ||
|
||
namespace KubeClient.Authentication | ||
{ | ||
using MessageHandlers; | ||
|
||
/// <summary> | ||
/// A Kubernetes API authentication strategy that uses a static access token. | ||
/// </summary> | ||
public class BearerTokenAuthStrategy | ||
: KubeAuthStrategy | ||
{ | ||
/// <summary> | ||
/// Create a new <see cref="BearerTokenAuthStrategy"/>. | ||
/// </summary> | ||
public BearerTokenAuthStrategy() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// The static access token to use. | ||
/// </summary> | ||
public string Token { get; set; } | ||
|
||
/// <summary> | ||
/// Validate the authentication strategy's configuration. | ||
/// </summary> | ||
/// <exception cref="KubeClientException"> | ||
/// The authentication strategy's configuration is incomplete or invalid. | ||
/// </exception> | ||
public override void Validate() | ||
{ | ||
if (string.IsNullOrWhiteSpace(Token)) | ||
throw new KubeClientException("The access token for authentication to the Kubernetes API has not been configured."); | ||
} | ||
|
||
/// <summary> | ||
/// Configure the <see cref="ClientBuilder"/> used to create <see cref="HttpClient"/>s used by the API client. | ||
/// </summary> | ||
/// <param name="clientBuilder"> | ||
/// The <see cref="ClientBuilder"/> to configure. | ||
/// </param> | ||
/// <returns> | ||
/// The configured <see cref="ClientBuilder"/>. | ||
/// </returns> | ||
public override ClientBuilder Configure(ClientBuilder clientBuilder) | ||
{ | ||
if (clientBuilder == null) | ||
throw new ArgumentNullException(nameof(clientBuilder)); | ||
|
||
Validate(); | ||
|
||
return clientBuilder.AddHandler( | ||
() => new StaticBearerTokenHandler(Token) | ||
); | ||
} | ||
|
||
/// <summary> | ||
/// Create a deep clone of the authentication strategy. | ||
/// </summary> | ||
/// <returns> | ||
/// The cloned <see cref="KubeAuthStrategy"/>. | ||
/// </returns> | ||
public override KubeAuthStrategy Clone() | ||
{ | ||
return new BearerTokenAuthStrategy | ||
{ | ||
Token = Token | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.