Files
octokit.net/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs
Keegan Campbell 131ba87e3f Replay #2221: Implement GitHub Actions Secrets API for both Organization and Repository (#2598)
* created the interface and models for the repository secrets client

* created a repository actions client to sit between repository and secrets for future extensibility

* created the repository secret client and supporting objects to enable data transfer

* created object for create or update secret body and made fixes to pass unit tests

* created repository action unit tests

* created unit tests for RepositorySecretsClient

* removed set from secrets interface

* fixed docs and added observable actions client

* added Actions to repository client

* created IObservable repository secrets client

* fixed property in wrong interface
fixed wrong Ctor unit test

* created repository decrets reactive tests and clients

* created organization actions and scerets classes and made them available through the oprganizations client

* fixed intellisense text

* removed uneeded getall call after return type change

* created organization secret client and classes to support it

* created the observable org secrets client and fixed a typo in a method name

* added more ensure checks

* removed unused xml doc setting

* created the unit tests for the organization secrets client
fixed broken unit test for repository secrets client

* created observable organization actions and secrets client unit tests

* added sodium.core to the integration tests to test secret creation

* fixed keyid type

* added actions client integration test classes (empty since the class currently doesn't have any native methods)

* fixed deserialization issue

* changed property name for deserialization issues

* added doc for repoid on orginzation secrets url generator

* created integration tests for repository and organization secrets

* changed how return occurs for setting list of repos for secret

* fixed some names and removed reset org name

* created integration tests for observable org secrets client

* removed  default org value

* created the integration tests for the observable repository secrets client

* removed default owner project value

* fixed unit tests

* Update links to new docs site

* Update doc links to new docs site

* Update docs links to new docs site

* Fix doc link to point to new docs site

* Update links to new docs site

* Update doc links to new docs site

* Update docs links

* Update docs

* Update docs

* Update doc links

* Update docs

* Update doc links

* Update doc links

* Update doc links

* updated documentation links in actions and secrets clients

* Update Octokit/Models/Response/SecretsPublicKey.cs

Removing line for consistency.

Co-authored-by: Thomas Hughes <iamhughes@github.com>

* Update Octokit/Models/Response/RepositorySecret.cs

Removing line for consistency.

Co-authored-by: Thomas Hughes <iamhughes@github.com>

* set default owner and repo

* switched to using the Helper.Organization from a ORG constant set at the top of the file

* swapped out variable at top of file for the Helper.Organization property

* switched to helper method to create new repositories

* Protected setters --> private setters in response models

* RepositorySecret needs protected setters

Co-authored-by: Mike Tolly <mike.tolly@takeda.com>
Co-authored-by: Thomas Hughes <iamhughes@github.com>
Co-authored-by: mptolly-takeda <61791994+mptolly-takeda@users.noreply.github.com>
2022-10-20 14:59:31 -07:00

219 lines
8.8 KiB
C#

using System;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
public class ObservableOrganizationsClient : IObservableOrganizationsClient
{
readonly IOrganizationsClient _client;
readonly IConnection _connection;
/// <summary>
/// Initializes a new Organization API client.
/// </summary>
/// <param name="client">An <see cref="IGitHubClient" /> used to make the requests</param>
public ObservableOrganizationsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));
Member = new ObservableOrganizationMembersClient(client);
Team = new ObservableTeamsClient(client);
Hook = new ObservableOrganizationHooksClient(client);
OutsideCollaborator = new ObservableOrganizationOutsideCollaboratorsClient(client);
Actions = new ObservableOrganizationActionsClient(client);
_client = client.Organization;
_connection = client.Connection;
}
/// <summary>
/// Returns a client to manage members of an organization.
/// </summary>
public IObservableOrganizationMembersClient Member { get; private set; }
/// <summary>
/// Returns a client to manage teams for an organization.
/// </summary>
public IObservableTeamsClient Team { get; private set; }
/// <summary>
/// A client for GitHub's Organization Hooks API.
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/orgs/hooks/">Hooks API documentation</a> for more information.</remarks>
public IObservableOrganizationHooksClient Hook { get; private set; }
/// <summary>
/// Returns a client to manage outside collaborators of an organization.
/// </summary>
public IObservableOrganizationOutsideCollaboratorsClient OutsideCollaborator { get; private set; }
/// <summary>
/// Returns a client to manage organization actions.
/// </summary>
public IObservableOrganizationActionsClient Actions { get; private set; }
/// <summary>
/// Returns the specified organization.
/// </summary>
/// <param name="org">The login of the specified organization,</param>
/// <returns></returns>
public IObservable<Organization> Get(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
return _client.Get(org).ToObservable();
}
/// <summary>
/// Returns all the organizations for the current user.
/// </summary>
/// <returns></returns>
public IObservable<Organization> GetAllForCurrent()
{
return GetAllForCurrent(ApiOptions.None);
}
/// <summary>
/// Returns all the organizations for the current user.
/// </summary>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
public IObservable<Organization> GetAllForCurrent(ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages<Organization>(ApiUrls.UserOrganizations());
}
/// <summary>
/// Returns all the organizations for the specified user
/// </summary>
/// <param name="user">The login for the user</param>
/// <returns></returns>
public IObservable<Organization> GetAllForUser(string user)
{
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
return _connection.GetAndFlattenAllPages<Organization>(ApiUrls.UserOrganizations(user));
}
/// <summary>
/// Returns all the organizations for the specified user
/// </summary>
/// <param name="user">The login for the user</param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
public IObservable<Organization> GetAllForUser(string user, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages<Organization>(ApiUrls.UserOrganizations(user), options);
}
/// <summary>
/// Returns all the organizations
/// </summary>
/// <returns></returns>
public IObservable<Organization> GetAll()
{
return _connection.GetAndFlattenAllPages<Organization>(ApiUrls.AllOrganizations());
}
/// <summary>
/// Returns all the organizations
/// </summary>
/// <param name="request">Search parameters of the last organization seen</param>
/// <returns></returns>
public IObservable<Organization> GetAll(OrganizationRequest request)
{
Ensure.ArgumentNotNull(request, nameof(request));
var url = ApiUrls.AllOrganizations(request.Since);
return _connection.GetAndFlattenAllPages<Organization>(url);
}
/// <summary>
/// Update the specified organization with data from <see cref="OrganizationUpdate"/>.
/// </summary>
/// <param name="org">The name of the organization to update.</param>
/// <param name="updateRequest"></param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="Organization"/></returns>
public IObservable<Organization> Update(string org, OrganizationUpdate updateRequest)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(updateRequest, nameof(updateRequest));
return _client.Update(org, updateRequest).ToObservable();
}
/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
public IObservable<OrganizationCredential> GetAllAuthorizations(string org)
{
Ensure.ArgumentNotNull(org, nameof(org));
var url = ApiUrls.AllOrganizationCredentials(org);
return _connection.GetAndFlattenAllPages<OrganizationCredential>(url);
}
/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <param name="options">Options for changing the API response</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
public IObservable<OrganizationCredential> GetAllAuthorizations(string org, ApiOptions options)
{
Ensure.ArgumentNotNull(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));
var url = ApiUrls.AllOrganizationCredentials(org);
return _connection.GetAndFlattenAllPages<OrganizationCredential>(url, options);
}
/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <param name="login">Limits the list of credentials authorizations for an organization to a specific login</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
public IObservable<OrganizationCredential> GetAllAuthorizations(string org, string login)
{
Ensure.ArgumentNotNull(org, nameof(org));
Ensure.ArgumentNotNull(login, nameof(login));
var url = ApiUrls.AllOrganizationCredentials(org, login);
return _connection.GetAndFlattenAllPages<OrganizationCredential>(url);
}
/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <param name="login">Limits the list of credentials authorizations for an organization to a specific login</param>
/// <param name="options">Options for changing the API response</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
public IObservable<OrganizationCredential> GetAllAuthorizations(string org, string login, ApiOptions options)
{
Ensure.ArgumentNotNull(org, nameof(org));
Ensure.ArgumentNotNull(login, nameof(login));
Ensure.ArgumentNotNull(options, nameof(options));
var url = ApiUrls.AllOrganizationCredentials(org, login);
return _connection.GetAndFlattenAllPages<OrganizationCredential>(url, options);
}
}
}