using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using InfluxDB.Client.Api.Domain;
using InfluxDB.Client.Api.Service;
using InfluxDB.Client.Core;
namespace InfluxDB.Client
{
public interface IOrganizationsApi
{
///
/// Creates a new organization and sets with the new identifier.
///
///
/// Cancellation token
/// Created organization
Task CreateOrganizationAsync(string name, CancellationToken cancellationToken = default);
///
/// Creates a new organization and sets with the new identifier.
///
/// the organization to create
/// Cancellation token
/// created organization
Task CreateOrganizationAsync(Organization organization,
CancellationToken cancellationToken = default);
///
/// Update an organization.
///
/// organization update to apply
/// Cancellation token
/// updated organization
Task UpdateOrganizationAsync(Organization organization,
CancellationToken cancellationToken = default);
///
/// Delete an organization.
///
/// ID of organization to delete
/// Cancellation token
/// delete has been accepted
Task DeleteOrganizationAsync(string orgId, CancellationToken cancellationToken = default);
///
/// Delete an organization.
///
/// organization to delete
/// Cancellation token
/// delete has been accepted
Task DeleteOrganizationAsync(Organization organization, CancellationToken cancellationToken = default);
///
/// Clone an organization.
///
/// name of cloned organization
/// ID of organization to clone
/// Cancellation token
/// cloned organization
Task CloneOrganizationAsync(string clonedName, string orgId,
CancellationToken cancellationToken = default);
///
/// Clone an organization.
///
/// name of cloned organization
/// organization to clone
/// Cancellation token
/// cloned organization
Task CloneOrganizationAsync(string clonedName, Organization organization,
CancellationToken cancellationToken = default);
///
/// Retrieve an organization.
///
/// ID of organization to get
/// Cancellation token
/// organization details
Task FindOrganizationByIdAsync(string orgId, CancellationToken cancellationToken = default);
///
/// List all organizations.
///
/// (optional, default to 20)
/// (optional)
/// (optional, default to false)
/// Filter organizations to a specific organization name. (optional)
/// Filter organizations to a specific organization ID. (optional)
/// Filter organizations to a specific user ID. (optional)
/// Cancellation token
/// List all organizations
Task> FindOrganizationsAsync(int? limit = null, int? offset = null,
bool? descending = null, string org = null, string orgID = null, string userID = null,
CancellationToken cancellationToken = default);
///
/// List of secret keys the are stored for Organization. For example:
///
/// github_api_key,
/// some_other_key,
/// a_secret_key
///
///
/// the organization for get secrets
/// Cancellation token
/// the secret keys
Task> GetSecretsAsync(Organization organization,
CancellationToken cancellationToken = default);
///
/// List of secret keys the are stored for Organization. For example:
///
/// github_api_key,
/// some_other_key,
/// a_secret_key
///
///
/// the organization for get secrets
/// Cancellation token
/// the secret keys
Task> GetSecretsAsync(string orgId, CancellationToken cancellationToken = default);
///
/// Patches all provided secrets and updates any previous values.
///
/// secrets to update/add
/// the organization for put secrets
/// Cancellation token
///
Task PutSecretsAsync(Dictionary secrets, Organization organization,
CancellationToken cancellationToken = default);
///
/// Patches all provided secrets and updates any previous values.
///
/// secrets to update/add
/// the organization for put secrets
/// Cancellation token
///
Task PutSecretsAsync(Dictionary secrets, string orgId,
CancellationToken cancellationToken = default);
///
/// Delete provided secrets.
///
/// secrets to delete
/// the organization for delete secrets
/// Cancellation token
/// keys successfully patched
Task DeleteSecretsAsync(List secrets, Organization organization,
CancellationToken cancellationToken = default);
///
/// Delete provided secrets.
///
/// secrets to delete
/// the organization for delete secrets
/// Cancellation token
/// keys successfully patched
Task DeleteSecretsAsync(List secrets, string orgId,
CancellationToken cancellationToken = default);
///
/// Delete provided secrets.
///
/// secrets to delete
/// the organization for delete secrets
/// Cancellation token
/// keys successfully patched
Task DeleteSecretsAsync(SecretKeys secrets, string orgId, CancellationToken cancellationToken = default);
///
/// List all members of an organization.
///
/// organization of the members
/// Cancellation token
/// the List all members of an organization
Task> GetMembersAsync(Organization organization,
CancellationToken cancellationToken = default);
///
/// List all members of an organization.
///
/// ID of organization to get members
/// Cancellation token
/// the List all members of an organization
Task> GetMembersAsync(string orgId,
CancellationToken cancellationToken = default);
///
/// Add organization member.
///
/// the member of an organization
/// the organization of a member
/// Cancellation token
/// created mapping
Task AddMemberAsync(User member, Organization organization,
CancellationToken cancellationToken = default);
///
/// Add organization member.
///
/// the ID of a member
/// the ID of an organization
/// Cancellation token
/// created mapping
Task AddMemberAsync(string memberId, string orgId,
CancellationToken cancellationToken = default);
///
/// Removes a member from an organization.
///
/// the member of an organization
/// the organization of a member
/// Cancellation token
///
Task DeleteMemberAsync(User member, Organization organization,
CancellationToken cancellationToken = default);
///
/// Removes a member from an organization.
///
/// the ID of a member
/// the ID of an organization
/// Cancellation token
///
Task DeleteMemberAsync(string memberId, string orgId, CancellationToken cancellationToken = default);
///
/// List all owners of an organization.
///
/// organization of the owners
/// Cancellation token
/// the List all owners of an organization
Task> GetOwnersAsync(Organization organization,
CancellationToken cancellationToken = default);
///
/// List all owners of an organization.
///
/// ID of organization to get owners
/// Cancellation token
/// the List all owners of an organization
Task> GetOwnersAsync(string orgId,
CancellationToken cancellationToken = default);
///
/// Add organization owner.
///
/// the owner of an organization
/// the organization of a owner
/// Cancellation token
/// created mapping
Task AddOwnerAsync(User owner, Organization organization,
CancellationToken cancellationToken = default);
///
/// Add organization owner.
///
/// the ID of a owner
/// the ID of an organization
/// Cancellation token
/// created mapping
Task AddOwnerAsync(string ownerId, string orgId,
CancellationToken cancellationToken = default);
///
/// Removes a owner from an organization.
///
/// the owner of an organization
/// the organization of a owner
/// Cancellation token
///
Task DeleteOwnerAsync(User owner, Organization organization,
CancellationToken cancellationToken = default);
///
/// Removes a owner from an organization.
///
/// the ID of a owner
/// the ID of an organization
/// Cancellation token
///
Task DeleteOwnerAsync(string ownerId, string orgId, CancellationToken cancellationToken = default);
}
public class OrganizationsApi : IOrganizationsApi
{
private readonly OrganizationsService _service;
private readonly SecretsService _secretsService;
protected internal OrganizationsApi(OrganizationsService service, SecretsService secretsService)
{
Arguments.CheckNotNull(service, nameof(service));
Arguments.CheckNotNull(secretsService, nameof(secretsService));
_service = service;
_secretsService = secretsService;
}
///
/// Creates a new organization and sets with the new identifier.
///
///
/// Cancellation token
/// Created organization
public Task CreateOrganizationAsync(string name, CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(name, nameof(name));
var organization = new Organization(null, name);
return CreateOrganizationAsync(organization, cancellationToken);
}
///
/// Creates a new organization and sets with the new identifier.
///
/// the organization to create
/// Cancellation token
/// created organization
public Task CreateOrganizationAsync(Organization organization,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(organization, nameof(organization));
var request = new PostOrganizationRequest(organization.Name, organization.Description);
return _service.PostOrgsAsync(request, cancellationToken: cancellationToken);
}
///
/// Update an organization.
///
/// organization update to apply
/// Cancellation token
/// updated organization
public Task UpdateOrganizationAsync(Organization organization,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(organization, nameof(organization));
var request = new PatchOrganizationRequest(organization.Name, organization.Description);
return _service.PatchOrgsIDAsync(organization.Id, request, cancellationToken: cancellationToken);
}
///
/// Delete an organization.
///
/// ID of organization to delete
/// Cancellation token
/// delete has been accepted
public Task DeleteOrganizationAsync(string orgId, CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(orgId, nameof(orgId));
return _service.DeleteOrgsIDAsync(orgId, cancellationToken: cancellationToken);
}
///
/// Delete an organization.
///
/// organization to delete
/// Cancellation token
/// delete has been accepted
public Task DeleteOrganizationAsync(Organization organization, CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(organization, nameof(organization));
return DeleteOrganizationAsync(organization.Id, cancellationToken);
}
///
/// Clone an organization.
///
/// name of cloned organization
/// ID of organization to clone
/// Cancellation token
/// cloned organization
public async Task CloneOrganizationAsync(string clonedName, string orgId,
CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(clonedName, nameof(clonedName));
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
var org = await FindOrganizationByIdAsync(orgId, cancellationToken).ConfigureAwait(false);
return await CloneOrganizationAsync(clonedName, org, cancellationToken).ConfigureAwait(false);
}
///
/// Clone an organization.
///
/// name of cloned organization
/// organization to clone
/// Cancellation token
/// cloned organization
public Task CloneOrganizationAsync(string clonedName, Organization organization,
CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(clonedName, nameof(clonedName));
Arguments.CheckNotNull(organization, nameof(organization));
var cloned = new Organization(null, clonedName);
return CreateOrganizationAsync(cloned, cancellationToken);
}
///
/// Retrieve an organization.
///
/// ID of organization to get
/// Cancellation token
/// organization details
public Task FindOrganizationByIdAsync(string orgId, CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
return _service.GetOrgsIDAsync(orgId, cancellationToken: cancellationToken);
}
///
/// List all organizations.
///
/// (optional, default to 20)
/// (optional)
/// (optional, default to false)
/// Filter organizations to a specific organization name. (optional)
/// Filter organizations to a specific organization ID. (optional)
/// Filter organizations to a specific user ID. (optional)
/// Cancellation token
/// List all organizations
public async Task> FindOrganizationsAsync(int? limit = null, int? offset = null,
bool? descending = null, string org = null, string orgID = null, string userID = null,
CancellationToken cancellationToken = default)
{
var response = await _service.GetOrgsAsync(limit: limit, offset: offset, descending: descending, org: org,
orgID: orgID, userID: userID, cancellationToken: cancellationToken).ConfigureAwait(false);
return response.Orgs;
}
///
/// List of secret keys the are stored for Organization. For example:
///
/// github_api_key,
/// some_other_key,
/// a_secret_key
///
///
/// the organization for get secrets
/// Cancellation token
/// the secret keys
public Task> GetSecretsAsync(Organization organization,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(organization, nameof(organization));
return GetSecretsAsync(organization.Id, cancellationToken);
}
///
/// List of secret keys the are stored for Organization. For example:
///
/// github_api_key,
/// some_other_key,
/// a_secret_key
///
///
/// the organization for get secrets
/// Cancellation token
/// the secret keys
public async Task> GetSecretsAsync(string orgId, CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
var response = await _secretsService.GetOrgsIDSecretsAsync(orgId, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return response.Secrets;
}
///
/// Patches all provided secrets and updates any previous values.
///
/// secrets to update/add
/// the organization for put secrets
/// Cancellation token
///
public Task PutSecretsAsync(Dictionary secrets, Organization organization,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(secrets, nameof(secrets));
Arguments.CheckNotNull(organization, nameof(organization));
return PutSecretsAsync(secrets, organization.Id, cancellationToken);
}
///
/// Patches all provided secrets and updates any previous values.
///
/// secrets to update/add
/// the organization for put secrets
/// Cancellation token
///
public Task PutSecretsAsync(Dictionary secrets, string orgId,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(secrets, nameof(secrets));
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
return _secretsService.PatchOrgsIDSecretsAsync(orgId, secrets, cancellationToken: cancellationToken);
}
///
/// Delete provided secrets.
///
/// secrets to delete
/// the organization for delete secrets
/// Cancellation token
/// keys successfully patched
public Task DeleteSecretsAsync(List secrets, Organization organization,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(secrets, nameof(secrets));
Arguments.CheckNotNull(organization, nameof(organization));
return DeleteSecretsAsync(secrets, organization.Id, cancellationToken);
}
///
/// Delete provided secrets.
///
/// secrets to delete
/// the organization for delete secrets
/// Cancellation token
/// keys successfully patched
public Task DeleteSecretsAsync(List secrets, string orgId,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(secrets, nameof(secrets));
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
return DeleteSecretsAsync(new SecretKeys(secrets), orgId, cancellationToken);
}
///
/// Delete provided secrets.
///
/// secrets to delete
/// the organization for delete secrets
/// Cancellation token
/// keys successfully patched
public Task DeleteSecretsAsync(SecretKeys secrets, string orgId, CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(secrets, nameof(secrets));
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
return _secretsService.PostOrgsIDSecretsAsync(orgId, secrets, cancellationToken: cancellationToken);
}
///
/// List all members of an organization.
///
/// organization of the members
/// Cancellation token
/// the List all members of an organization
public Task> GetMembersAsync(Organization organization,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(organization, nameof(organization));
return GetMembersAsync(organization.Id, cancellationToken);
}
///
/// List all members of an organization.
///
/// ID of organization to get members
/// Cancellation token
/// the List all members of an organization
public async Task> GetMembersAsync(string orgId,
CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
var response = await _service.GetOrgsIDMembersAsync(orgId, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return response.Users;
}
///
/// Add organization member.
///
/// the member of an organization
/// the organization of a member
/// Cancellation token
/// created mapping
public Task AddMemberAsync(User member, Organization organization,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(organization, nameof(organization));
Arguments.CheckNotNull(member, nameof(member));
return AddMemberAsync(member.Id, organization.Id, cancellationToken);
}
///
/// Add organization member.
///
/// the ID of a member
/// the ID of an organization
/// Cancellation token
/// created mapping
public Task AddMemberAsync(string memberId, string orgId,
CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
Arguments.CheckNonEmptyString(memberId, nameof(memberId));
return _service.PostOrgsIDMembersAsync(orgId, new AddResourceMemberRequestBody(memberId),
cancellationToken: cancellationToken);
}
///
/// Removes a member from an organization.
///
/// the member of an organization
/// the organization of a member
/// Cancellation token
///
public Task DeleteMemberAsync(User member, Organization organization,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(organization, nameof(organization));
Arguments.CheckNotNull(member, nameof(member));
return DeleteMemberAsync(member.Id, organization.Id, cancellationToken);
}
///
/// Removes a member from an organization.
///
/// the ID of a member
/// the ID of an organization
/// Cancellation token
///
public Task DeleteMemberAsync(string memberId, string orgId, CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
Arguments.CheckNonEmptyString(memberId, nameof(memberId));
return _service.DeleteOrgsIDMembersIDAsync(memberId, orgId, cancellationToken: cancellationToken);
}
///
/// List all owners of an organization.
///
/// organization of the owners
/// Cancellation token
/// the List all owners of an organization
public Task> GetOwnersAsync(Organization organization,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(organization, nameof(organization));
return GetOwnersAsync(organization.Id, cancellationToken);
}
///
/// List all owners of an organization.
///
/// ID of organization to get owners
/// Cancellation token
/// the List all owners of an organization
public async Task> GetOwnersAsync(string orgId,
CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
var response = await _service.GetOrgsIDOwnersAsync(orgId, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return response.Users;
}
///
/// Add organization owner.
///
/// the owner of an organization
/// the organization of a owner
/// Cancellation token
/// created mapping
public Task AddOwnerAsync(User owner, Organization organization,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(organization, nameof(organization));
Arguments.CheckNotNull(owner, nameof(owner));
return AddOwnerAsync(owner.Id, organization.Id, cancellationToken);
}
///
/// Add organization owner.
///
/// the ID of a owner
/// the ID of an organization
/// Cancellation token
/// created mapping
public Task AddOwnerAsync(string ownerId, string orgId,
CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
Arguments.CheckNonEmptyString(ownerId, nameof(ownerId));
return _service.PostOrgsIDOwnersAsync(orgId, new AddResourceMemberRequestBody(ownerId),
cancellationToken: cancellationToken);
}
///
/// Removes a owner from an organization.
///
/// the owner of an organization
/// the organization of a owner
/// Cancellation token
///
public Task DeleteOwnerAsync(User owner, Organization organization,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(organization, nameof(organization));
Arguments.CheckNotNull(owner, nameof(owner));
return DeleteOwnerAsync(owner.Id, organization.Id, cancellationToken);
}
///
/// Removes a owner from an organization.
///
/// the ID of a owner
/// the ID of an organization
/// Cancellation token
///
public Task DeleteOwnerAsync(string ownerId, string orgId, CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
Arguments.CheckNonEmptyString(ownerId, nameof(ownerId));
return _service.DeleteOrgsIDOwnersIDAsync(ownerId, orgId, cancellationToken: cancellationToken);
}
}
}