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

Dev #8

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/ArgoCD.Client/IApplicationSetClient.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,53 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ArgoCD.Client.Models;
using ArgoCD.Client.Models.ApplicationSet.Reponses;
using ArgoCD.Client.Models.ApplicationSet.Requests;
using ArgoCD.Client.Models.GPKKey.Responses;

namespace ArgoCD.Client
{
public interface IApplicationSetClient
{
/// <summary>
/// List returns list of applicationset
/// </summary>
/// <param name="options">Get options <see cref="ApplicationSetListQueryOptions"/></param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
Task<V1alpha1ApplicationSetList> GetListAsync(Action<ApplicationSetListQueryOptions> options, CancellationToken cancellationToken = default);

/// <summary>
/// Get returns an applicationset by name
/// </summary>
/// <param name="name">the applicationsets's name</param>
/// <param name="options">Get options <see cref="ApplicationSetQueryOptions"/></param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
Task<V1alpha1ApplicationSet> GetAsync(string name, Action<ApplicationSetQueryOptions> options, CancellationToken cancellationToken = default);


/// <summary>
/// Create creates an applicationset
/// </summary>
/// <param name="request">Create applicationset request</param>
/// <param name="options">Create options <see cref="UpsertOptions"/></param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
Task<V1alpha1ApplicationSet> CreateApplicationSetAsync(CreateApplicationSetRequest request, Action<UpsertOptions> options, CancellationToken cancellationToken = default);


/// <summary>
/// Delete deletes an application set
/// </summary>
/// <param name="name">the applicationsets's name</param>
/// <param name="options">delete options <see cref="ApplicationSetQueryOptions"/></param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
Task<DeleteApplicationSetResult> DeleteAsync(string name, Action<ApplicationSetQueryOptions> options, CancellationToken cancellationToken = default);

}
}
5 changes: 3 additions & 2 deletions src/ArgoCD.Client/ICertificateClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using ArgoCD.Client.Models.Certificate.Reponses;
using ArgoCD.Client.Models.Certificate.Requests;
using ArgoCD.Client.Models;

namespace ArgoCD.Client
{
Expand All @@ -24,10 +25,10 @@ public interface ICertificateClient
///Creates repository certificates on the server
/// </summary>
/// <param name="request">Create repository certificate request</param>
/// <param name="options">Create options <see cref="CreateCertificateOptions"/></param>
/// <param name="options">Create options <see cref="UpsertOptions"/></param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
Task<RepositoryCertificateList> CreateRepositoryCertificateAsync(CreateRepositoryCertificateRequest request, Action<CreateCertificateOptions> options, CancellationToken cancellationToken = default);
Task<RepositoryCertificateList> CreateRepositoryCertificateAsync(CreateRepositoryCertificateRequest request, Action<UpsertOptions> options, CancellationToken cancellationToken = default);

/// <summary>
/// Delete the certificates that match the RepositoryCertificateQuery
Expand Down
5 changes: 3 additions & 2 deletions src/ArgoCD.Client/IClusterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using ArgoCD.Client.Models.Cluster.Requests;
using ArgoCD.Client.Models.Cluster.Responses;
using ArgoCD.Client.Models;

namespace ArgoCD.Client
{
Expand All @@ -31,10 +32,10 @@ public interface IClusterClient
/// Create creates a cluster
/// </summary>
/// <param name="request">Create cluster request</param>
/// <param name="options">Create options <see cref="CreateClusterOptions"/></param>
/// <param name="options">Create options <see cref="UpsertOptions"/></param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
Task<V1alpha1Cluster> CreateClusterAsync(V1alpha1ClusterRequest request, Action<CreateClusterOptions> options, CancellationToken cancellationToken = default);
Task<V1alpha1Cluster> CreateClusterAsync(V1alpha1ClusterRequest request, Action<UpsertOptions> options, CancellationToken cancellationToken = default);


/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions src/ArgoCD.Client/IGPKKeyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using ArgoCD.Client.Models.GPKKey.Responses;
using ArgoCD.Client.Models.GPKKey.Requests;
using ArgoCD.Client.Internal.Queries;
using ArgoCD.Client.Models;

namespace ArgoCD.Client
{
Expand All @@ -33,10 +34,10 @@ public interface IGPKKeyClient
/// Create one or more GPG public keys in the server's configuration
/// </summary>
/// <param name="request">Create GPKKey request</param>
/// <param name="options">Create options <see cref="CreateGPKKeyOptions"/></param>
/// <param name="options">Create options <see cref="UpsertOptions"/></param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
Task<GnuPGPublicKey> CreateGPKKeyAsync(CreateGPGKeyRequest request, Action<CreateGPKKeyOptions> options, CancellationToken cancellationToken = default);
Task<GnuPGPublicKey> CreateGPKKeyAsync(CreateGPGKeyRequest request, Action<UpsertOptions> options, CancellationToken cancellationToken = default);

/// <summary>
/// Delete specified GPG public key from the server's configuration
Expand Down
5 changes: 3 additions & 2 deletions src/ArgoCD.Client/IRepoCredsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using ArgoCD.Client.Models.RepoCreds.Responses;
using ArgoCD.Client.Models.RepoCreds.Requests;
using ArgoCD.Client.Models;

namespace ArgoCD.Client
{
Expand All @@ -23,10 +24,10 @@ public interface IRepoCredsClient
/// creates a new repository credential set
/// </summary>
/// <param name="request">Create repository credentials request</param>
/// <param name="options">Create options <see cref="CreateRepoCredsOptions"/></param>
/// <param name="options">Create options <see cref="UpsertOptions"/></param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
Task<V1alpha1RepoCreds> CreateRepositoryCredentialsAsync(CreateRepoCredsRequest request, Action<CreateRepoCredsOptions> options, CancellationToken cancellationToken = default);
Task<V1alpha1RepoCreds> CreateRepositoryCredentialsAsync(CreateRepoCredsRequest request, Action<UpsertOptions> options, CancellationToken cancellationToken = default);


/// <summary>
Expand Down
29 changes: 21 additions & 8 deletions src/ArgoCD.Client/Impl/AccountClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading;
using System.Threading.Tasks;
using ArgoCD.Client.Internal.Http;
using ArgoCD.Client.Internal.Utilities;
using ArgoCD.Client.Models.Account.Requests;
using ArgoCD.Client.Models.Account.Responses;

Expand All @@ -22,23 +23,29 @@ public class AccountClient : IAccountClient
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
public async Task<AccountCanI> CheckAccountPermissionAsync(string resource, string action, string subresource, CancellationToken cancellationToken = default) =>
await _httpFacade.GetAsync<AccountCanI>($"account/can-i/{resource}/{action}/{subresource}",cancellationToken).ConfigureAwait(false);
await _httpFacade.GetAsync<AccountCanI>($"account/can-i/{resource}/{action}/{subresource}",cancellationToken).
ConfigureAwait(false);

/// <summary>
/// CreateToken creates a token
/// </summary>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
public async Task<CreateAccountToken> CreateAccountAsync(CreateAccountTokenRequest request, CancellationToken cancellationToken = default) =>
await _httpFacade.PostAsync<CreateAccountToken>($"account/{request.Name}/token",cancellationToken).ConfigureAwait(false);
public async Task<CreateAccountToken> CreateAccountAsync(CreateAccountTokenRequest request, CancellationToken cancellationToken = default)
{
Guard.NotNull(request, nameof(request));
return await _httpFacade.PostAsync<CreateAccountToken>($"account/{request.Name}/token", cancellationToken).
ConfigureAwait(false);
}

/// <summary>
/// DeleteToken deletes a token
/// </summary>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
public async Task DeleteAccountAsync(string name, string id, CancellationToken cancellationToken = default) =>
await _httpFacade.DeleteAsync($"account/{name}/token/{id}",cancellationToken).ConfigureAwait(false);
await _httpFacade.DeleteAsync($"account/{name}/token/{id}",cancellationToken).
ConfigureAwait(false);


/// <summary>
Expand All @@ -47,22 +54,28 @@ public async Task DeleteAccountAsync(string name, string id, CancellationToken c
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
public async Task<Account> GetAccountAsync(string name, CancellationToken cancellationToken = default) =>
await _httpFacade.GetAsync<Account>($"account/{name}",cancellationToken).ConfigureAwait(false);
await _httpFacade.GetAsync<Account>($"account/{name}",cancellationToken).
ConfigureAwait(false);

/// <summary>
/// ListAccounts returns the list of accounts
/// </summary>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
public async Task<AccountList> GetAccountListAsync(CancellationToken cancellationToken = default) =>
await _httpFacade.GetAsync<AccountList>("account",cancellationToken).ConfigureAwait(false);
await _httpFacade.GetAsync<AccountList>("account",cancellationToken).
ConfigureAwait(false);

/// <summary>
/// UpdatePassword updates an account's password to a new value
/// </summary>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
public async Task UpdateAccountPasswordAsync(UpdateAccountPasswordRequest request, CancellationToken cancellationToken = default) =>
await _httpFacade.PutAsync("account/password", request,cancellationToken).ConfigureAwait(false);
public async Task UpdateAccountPasswordAsync(UpdateAccountPasswordRequest request, CancellationToken cancellationToken = default)
{
Guard.NotNull(request, nameof(request));
await _httpFacade.PutAsync("account/password", request, cancellationToken).
ConfigureAwait(false);
}
}
}
98 changes: 96 additions & 2 deletions src/ArgoCD.Client/Impl/ApplicationSetClient.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,105 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using ArgoCD.Client.Models.ApplicationSet.Requests;
using ArgoCD.Client.Models.ApplicationSet.Reponses;
using ArgoCD.Client.Models;
using ArgoCD.Client.Internal.Queries;
using ArgoCD.Client.Internal.Http;
using ArgoCD.Client.Internal.Utilities;
using System.Xml.Linq;

namespace ArgoCD.Client.Impl
{
public class ApplicationSetClient: IApplicationSetClient
public class ApplicationSetClient : IApplicationSetClient
{
public ApplicationSetClient() { }
private readonly IArgoCDHttpFacade _httpFacade;
private readonly UpsertBuilder _upsertBuilder;
private readonly ApplicationSetQueryBuilder _applicationSetQueryBuilder;
private readonly ApplicationSetListQueryBuilder _applicationSetListQueryBuilder;
internal ApplicationSetClient(IArgoCDHttpFacade httpFacade,
UpsertBuilder upsertBuilder,
ApplicationSetQueryBuilder applicationSetQueryBuilder,
ApplicationSetListQueryBuilder applicationSetListQueryBuilder)
{
_httpFacade = httpFacade;
_upsertBuilder = upsertBuilder;
_applicationSetQueryBuilder = applicationSetQueryBuilder;
_applicationSetListQueryBuilder = applicationSetListQueryBuilder;
}

/// <summary>
/// List returns list of applicationset
/// </summary>
/// <param name="options">Get options <see cref="ApplicationSetListQueryOptions"/></param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
public async Task<V1alpha1ApplicationSetList> GetListAsync(Action<ApplicationSetListQueryOptions> options, CancellationToken cancellationToken = default)
{
var queryOptions = new ApplicationSetListQueryOptions();
options?.Invoke(queryOptions);

string url = _applicationSetListQueryBuilder.Build("applicationsets", queryOptions);
return await _httpFacade.GetAsync<V1alpha1ApplicationSetList>(url, cancellationToken).
ConfigureAwait(false);
}

/// <summary>
/// Get returns an applicationset by name
/// </summary>
/// <param name="name">the applicationsets's name</param>
/// <param name="options">Get options <see cref="ApplicationSetQueryOptions"/></param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
public async Task<V1alpha1ApplicationSet> GetAsync(string name, Action<ApplicationSetQueryOptions> options, CancellationToken cancellationToken = default)
{
var queryOptions = new ApplicationSetQueryOptions();
options?.Invoke(queryOptions);

string url = _applicationSetQueryBuilder.Build($"applicationsets/{name}", queryOptions);
return await _httpFacade.GetAsync<V1alpha1ApplicationSet>(url, cancellationToken).
ConfigureAwait(false);
}


/// <summary>
/// Create creates an applicationset
/// </summary>
/// <param name="request">Create applicationset request</param>
/// <param name="options">Create options <see cref="UpsertOptions"/></param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
public async Task<V1alpha1ApplicationSet> CreateApplicationSetAsync(CreateApplicationSetRequest request, Action<UpsertOptions> options, CancellationToken cancellationToken = default)
{
Guard.NotNull(request?.ApplicationSet, nameof(request));

var queryOptions = new UpsertOptions();
options?.Invoke(queryOptions);

string url = _upsertBuilder.Build("applicationsets", queryOptions);
return await _httpFacade.PostAsync<V1alpha1ApplicationSet>(url, request.ApplicationSet, cancellationToken).
ConfigureAwait(false);
}


/// <summary>
/// Delete deletes an application set
/// </summary>
/// <param name="name">the applicationsets's name</param>
/// <param name="options">delete options <see cref="ApplicationSetQueryOptions"/></param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive, notice of cancellation.</param>
/// <returns></returns>
public async Task<DeleteApplicationSetResult> DeleteAsync(string name, Action<ApplicationSetQueryOptions> options, CancellationToken cancellationToken = default)
{
var queryOptions = new ApplicationSetQueryOptions();
options?.Invoke(queryOptions);

string url = _applicationSetQueryBuilder.Build($"applicationsets/{name}", queryOptions);
return await _httpFacade.DeleteAsync<DeleteApplicationSetResult>(url, cancellationToken).
ConfigureAwait(false);

}
}
}
Loading