|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using DigitalOcean.API.Http; |
| 4 | +using DigitalOcean.API.Models.Responses; |
| 5 | +using RestSharp; |
| 6 | + |
| 7 | +namespace DigitalOcean.API.Clients { |
| 8 | + public class CertificatesClient : ICertificatesClient { |
| 9 | + private readonly IConnection _connection; |
| 10 | + |
| 11 | + public CertificatesClient(IConnection connection) { |
| 12 | + _connection = connection; |
| 13 | + } |
| 14 | + |
| 15 | + /// <summary> |
| 16 | + /// To list all of the certificates available on your account. |
| 17 | + /// </summary> |
| 18 | + public Task<IReadOnlyList<Certificate>> GetAll() { |
| 19 | + return _connection.GetPaginated<Certificate>("certificates", null, "certificates"); |
| 20 | + } |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// To show information about an existing certificate. |
| 24 | + /// </summary> |
| 25 | + public Task<Certificate> Get(string certificateId) { |
| 26 | + var parameters = new List<Parameter> { |
| 27 | + new Parameter { Name = "certificate_id", Value = certificateId, Type = ParameterType.UrlSegment } |
| 28 | + }; |
| 29 | + return _connection.ExecuteRequest<Certificate>("certificates/{certificate_id}", parameters, null, "certificate"); |
| 30 | + } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Create a new Let's Encrypt Certificate: |
| 34 | + /// When using Let's Encrypt to create a certificate, the dns_names attribute must be provided, |
| 35 | + /// and the type must be set to "lets_encrypt". |
| 36 | + /// |
| 37 | + /// Create a new custom Certificate: |
| 38 | + /// When uploading a user-generated certificate, the private_key, leaf_certificate, and optionally the certificate_chain |
| 39 | + /// attributes should be provided. The type must be set to "custom". |
| 40 | + /// </summary> |
| 41 | + public Task<Certificate> Create(Models.Requests.Certificate certificate) { |
| 42 | + return _connection.ExecuteRequest<Certificate>("certificates", null, certificate, "certificate", Method.POST); |
| 43 | + } |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// To delete a specific certificate. |
| 47 | + /// </summary> |
| 48 | + public Task Delete(string certificateId) { |
| 49 | + var parameters = new List<Parameter> { |
| 50 | + new Parameter { Name = "certificate_id", Value = certificateId, Type = ParameterType.UrlSegment } |
| 51 | + }; |
| 52 | + return _connection.ExecuteRaw("certificates/{certificate_id}", parameters, null, Method.DELETE); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments