Skip to content

Commit

Permalink
Merge branch 'enh-pem-cert-chains'
Browse files Browse the repository at this point in the history
  • Loading branch information
benPearce1 committed Apr 30, 2018
2 parents dcf87e5 + 45b8c4a commit 5f0d91b
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ Octopus.Client.Editors.Async
.ctor(Octopus.Client.Repositories.Async.IEnvironmentRepository)
Octopus.Client.Model.EnvironmentResource Instance { get; }
Task<EnvironmentEditor> CreateOrModify(String)
Task<EnvironmentEditor> CreateOrModify(String, String, Boolean)
Task<EnvironmentEditor> CreateOrModify(String, String)
Octopus.Client.Editors.Async.EnvironmentEditor Customize(Action<EnvironmentResource>)
Task<EnvironmentEditor> Save()
Expand Down Expand Up @@ -1112,6 +1113,12 @@ Octopus.Client.Model
String Name { get; set; }
String Thumbprint { get; set; }
}
CertificateExportPemOptions
{
PrimaryOnly = 0
PrimaryAndChain = 1
ChainOnly = 2
}
CertificateFormat
{
Pkcs12 = 0
Expand Down Expand Up @@ -1603,6 +1610,7 @@ Octopus.Client.Model
Octopus.Client.Model.Resource
{
.ctor()
Boolean AllowDynamicInfrastructure { get; set; }
String Description { get; set; }
String Name { get; set; }
Int32 SortOrder { get; set; }
Expand Down Expand Up @@ -4084,6 +4092,7 @@ Octopus.Client.Repositories.Async
{
Task Archive(Octopus.Client.Model.CertificateResource)
Task<Stream> Export(Octopus.Client.Model.CertificateResource, Nullable<CertificateFormat>, String, Boolean)
Task<Stream> ExportAsPem(Octopus.Client.Model.CertificateResource, Boolean, Octopus.Client.Model.CertificateExportPemOptions)
Task<CertificateConfigurationResource> GetOctopusCertificate()
Task<CertificateResource> Replace(Octopus.Client.Model.CertificateResource, String, String)
Task UnArchive(Octopus.Client.Model.CertificateResource)
Expand Down Expand Up @@ -4163,6 +4172,7 @@ Octopus.Client.Repositories.Async
{
Task<EnvironmentEditor> CreateOrModify(String)
Task<EnvironmentEditor> CreateOrModify(String, String)
Task<EnvironmentEditor> CreateOrModify(String, String, Boolean)
Task<List<MachineResource>> GetMachines(Octopus.Client.Model.EnvironmentResource, Nullable<Int32>, Nullable<Int32>, String, String, Nullable<Boolean>, String, String, String, String)
Task Sort(String[])
Task<EnvironmentsSummaryResource> Summary(String, String, String, String, Nullable<Boolean>, String, String, String, String, Nullable<Boolean>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ Octopus.Client.Editors
.ctor(Octopus.Client.Repositories.IEnvironmentRepository)
Octopus.Client.Model.EnvironmentResource Instance { get; }
Octopus.Client.Editors.EnvironmentEditor CreateOrModify(String)
Octopus.Client.Editors.EnvironmentEditor CreateOrModify(String, String, Boolean)
Octopus.Client.Editors.EnvironmentEditor CreateOrModify(String, String)
Octopus.Client.Editors.EnvironmentEditor Customize(Action<EnvironmentResource>)
Octopus.Client.Editors.EnvironmentEditor Save()
Expand Down Expand Up @@ -674,6 +675,7 @@ Octopus.Client.Editors.Async
.ctor(Octopus.Client.Repositories.Async.IEnvironmentRepository)
Octopus.Client.Model.EnvironmentResource Instance { get; }
Task<EnvironmentEditor> CreateOrModify(String)
Task<EnvironmentEditor> CreateOrModify(String, String, Boolean)
Task<EnvironmentEditor> CreateOrModify(String, String)
Octopus.Client.Editors.Async.EnvironmentEditor Customize(Action<EnvironmentResource>)
Task<EnvironmentEditor> Save()
Expand Down Expand Up @@ -1516,6 +1518,12 @@ Octopus.Client.Model
String Name { get; set; }
String Thumbprint { get; set; }
}
CertificateExportPemOptions
{
PrimaryOnly = 0
PrimaryAndChain = 1
ChainOnly = 2
}
CertificateFormat
{
Pkcs12 = 0
Expand Down Expand Up @@ -2007,6 +2015,7 @@ Octopus.Client.Model
Octopus.Client.Model.Resource
{
.ctor()
Boolean AllowDynamicInfrastructure { get; set; }
String Description { get; set; }
String Name { get; set; }
Int32 SortOrder { get; set; }
Expand Down Expand Up @@ -4503,6 +4512,7 @@ Octopus.Client.Repositories
{
void Archive(Octopus.Client.Model.CertificateResource)
Stream Export(Octopus.Client.Model.CertificateResource, Nullable<CertificateFormat>, String, Boolean)
Stream ExportAsPem(Octopus.Client.Model.CertificateResource, Boolean, Octopus.Client.Model.CertificateExportPemOptions)
Octopus.Client.Model.CertificateConfigurationResource GetOctopusCertificate()
Octopus.Client.Model.CertificateResource Replace(Octopus.Client.Model.CertificateResource, String, String)
void UnArchive(Octopus.Client.Model.CertificateResource)
Expand Down Expand Up @@ -4582,6 +4592,7 @@ Octopus.Client.Repositories
{
Octopus.Client.Editors.EnvironmentEditor CreateOrModify(String)
Octopus.Client.Editors.EnvironmentEditor CreateOrModify(String, String)
Octopus.Client.Editors.EnvironmentEditor CreateOrModify(String, String, Boolean)
List<MachineResource> GetMachines(Octopus.Client.Model.EnvironmentResource, Nullable<Int32>, Nullable<Int32>, String, String, Nullable<Boolean>, String, String, String, String)
void Sort(String[])
Octopus.Client.Model.EnvironmentsSummaryResource Summary(String, String, String, String, Nullable<Boolean>, String, String, String, String, Nullable<Boolean>)
Expand Down Expand Up @@ -4969,6 +4980,7 @@ Octopus.Client.Repositories.Async
{
Task Archive(Octopus.Client.Model.CertificateResource)
Task<Stream> Export(Octopus.Client.Model.CertificateResource, Nullable<CertificateFormat>, String, Boolean)
Task<Stream> ExportAsPem(Octopus.Client.Model.CertificateResource, Boolean, Octopus.Client.Model.CertificateExportPemOptions)
Task<CertificateConfigurationResource> GetOctopusCertificate()
Task<CertificateResource> Replace(Octopus.Client.Model.CertificateResource, String, String)
Task UnArchive(Octopus.Client.Model.CertificateResource)
Expand Down Expand Up @@ -5048,6 +5060,7 @@ Octopus.Client.Repositories.Async
{
Task<EnvironmentEditor> CreateOrModify(String)
Task<EnvironmentEditor> CreateOrModify(String, String)
Task<EnvironmentEditor> CreateOrModify(String, String, Boolean)
Task<List<MachineResource>> GetMachines(Octopus.Client.Model.EnvironmentResource, Nullable<Int32>, Nullable<Int32>, String, String, Nullable<Boolean>, String, String, String, String)
Task Sort(String[])
Task<EnvironmentsSummaryResource> Summary(String, String, String, String, Nullable<Boolean>, String, String, String, String, Nullable<Boolean>)
Expand Down
3 changes: 2 additions & 1 deletion source/Octopus.Client.Tests/PublicSurfaceAreaFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public void ThePublicSurfaceAreaShouldNotRegress()
var framework = string.Concat(RuntimeInformation.FrameworkDescription.Split(' ').Take(2));
try
{
var recieved = string.Join("\r\n", lines);
this.Assent(
string.Join("\r\n", lines),
recieved,
new Configuration().UsingNamer(new PostfixNamer(framework))
);
}
Expand Down
26 changes: 25 additions & 1 deletion source/Octopus.Client/Editors/Async/EnvironmentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ public async Task<EnvironmentEditor> CreateOrModify(string name)
return this;
}

public async Task<EnvironmentEditor> CreateOrModify(string name, string description, bool allowDynamicInfrastructure = false)
{
var existing = await repository.FindByName(name).ConfigureAwait(false);
if (existing == null)
{
Instance = await repository.Create(new EnvironmentResource
{
Name = name,
Description = description,
AllowDynamicInfrastructure = allowDynamicInfrastructure
}).ConfigureAwait(false);
}
else
{
existing.Name = name;
existing.Description = description;
existing.AllowDynamicInfrastructure = allowDynamicInfrastructure;

Instance = await repository.Modify(existing).ConfigureAwait(false);
}

return this;
}

public async Task<EnvironmentEditor> CreateOrModify(string name, string description)
{
var existing = await repository.FindByName(name).ConfigureAwait(false);
Expand All @@ -44,7 +68,7 @@ public async Task<EnvironmentEditor> CreateOrModify(string name, string descript
Instance = await repository.Create(new EnvironmentResource
{
Name = name,
Description = description
Description = description,
}).ConfigureAwait(false);
}
else
Expand Down
26 changes: 25 additions & 1 deletion source/Octopus.Client/Editors/EnvironmentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ public EnvironmentEditor CreateOrModify(string name)
return this;
}

public EnvironmentEditor CreateOrModify(string name, string description, bool allowDynamicInfrastructure)
{
var existing = repository.FindByName(name);
if (existing == null)
{
Instance = repository.Create(new EnvironmentResource
{
Name = name,
Description = description,
AllowDynamicInfrastructure = allowDynamicInfrastructure
});
}
else
{
existing.Name = name;
existing.Description = description;
existing.AllowDynamicInfrastructure = allowDynamicInfrastructure;

Instance = repository.Modify(existing);
}

return this;
}

public EnvironmentEditor CreateOrModify(string name, string description)
{
var existing = repository.FindByName(name);
Expand All @@ -43,7 +67,7 @@ public EnvironmentEditor CreateOrModify(string name, string description)
Instance = repository.Create(new EnvironmentResource
{
Name = name,
Description = description
Description = description,
});
}
else
Expand Down
9 changes: 9 additions & 0 deletions source/Octopus.Client/Model/CertificateExportPemOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Octopus.Client.Model
{
public enum CertificateExportPemOptions
{
PrimaryOnly,
PrimaryAndChain,
ChainOnly
}
}
6 changes: 6 additions & 0 deletions source/Octopus.Client/Model/EnvironmentResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,11 @@ public class EnvironmentResource : Resource, INamedResource
/// </summary>
[Writeable]
public bool UseGuidedFailure { get; set; }

/// <summary>
/// If set to true, deployments to this environment will be allowed to contain steps that manage infrastructure.
/// </summary>
[Writeable]
public bool AllowDynamicInfrastructure { get; set; }
}
}
16 changes: 16 additions & 0 deletions source/Octopus.Client/Repositories/Async/CertificateRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ public interface ICertificateRepository : IGet<CertificateResource>, IFindByName
/// <param name="includePrivateKey">Specifies whether the certificate private-key (if present) should be included in the exported file. This value is only be used when exporting to PEM format.</param>
/// <returns>The exported certificate data.</returns>
Task<Stream> Export(CertificateResource certificate, CertificateFormat? format = null, string password = null, bool includePrivateKey = false);

/// <summary>
/// Exports the certificate in PEM format
/// </summary>
/// <param name="certificate">The certificate to export.</param>
/// <param name="includePrivateKey">Specifies whether the certificate private-key (if present) should be included in the exported file.</param>
/// <param name="pemOptions">Options specifying which certificates should be included when chain certificates are present</param>
/// <returns>The exported certificate in PEM format</returns>
Task<Stream> ExportAsPem(CertificateResource certificate, bool includePrivateKey = false, CertificateExportPemOptions pemOptions = CertificateExportPemOptions.PrimaryOnly);

/// <summary>
/// Replace with a new certificate.
Expand Down Expand Up @@ -60,6 +69,13 @@ public Task<Stream> Export(CertificateResource certificate, CertificateFormat? f
return Client.GetContent(certificate.Link("Export"), pathParameters);
}

public Task<Stream> ExportAsPem(CertificateResource certificate, bool includePrivateKey = false,
CertificateExportPemOptions pemOptions = CertificateExportPemOptions.PrimaryOnly)
{
var parameters = new { format = CertificateFormat.Pem, includePrivateKey, pemOptions };
return Client.GetContent(certificate.Link("Export"), parameters);
}

public Task<CertificateResource> Replace(CertificateResource certificate, string certificateData, string password)
{
return Client.Post<object, CertificateResource>(certificate.Link("Replace"), new {certificateData = certificateData, password = password});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Task<EnvironmentsSummaryResource> Summary(
Task Sort(string[] environmentIdsInOrder);
Task<EnvironmentEditor> CreateOrModify(string name);
Task<EnvironmentEditor> CreateOrModify(string name, string description);
Task<EnvironmentEditor> CreateOrModify(string name, string description, bool allowDynamicInfrastructure);
}

class EnvironmentRepository : BasicRepository<EnvironmentResource>, IEnvironmentRepository
Expand Down Expand Up @@ -114,5 +115,10 @@ public Task<EnvironmentEditor> CreateOrModify(string name, string description)
{
return new EnvironmentEditor(this).CreateOrModify(name, description);
}

public Task<EnvironmentEditor> CreateOrModify(string name, string description, bool allowDynamicInfrastructure)
{
return new EnvironmentEditor(this).CreateOrModify(name, description, allowDynamicInfrastructure);
}
}
}
16 changes: 16 additions & 0 deletions source/Octopus.Client/Repositories/CertificateRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ public interface ICertificateRepository : IGet<CertificateResource>, IFindByName
/// <returns>The exported certificate data.</returns>
Stream Export(CertificateResource certificate, CertificateFormat? format = null, string password = null, bool includePrivateKey = false);

/// <summary>
/// Exports the certificate in PEM format
/// </summary>
/// <param name="certificate">The certificate to export.</param>
/// <param name="includePrivateKey">Specifies whether the certificate private-key (if present) should be included in the exported file.</param>
/// <param name="pemOptions">Options specifying which certificates should be included when chain certificates are present</param>
/// <returns>The exported certificate in PEM format</returns>
Stream ExportAsPem(CertificateResource certificate, bool includePrivateKey = false, CertificateExportPemOptions pemOptions = CertificateExportPemOptions.PrimaryOnly);

/// <summary>
/// Replace with a new certificate.
/// The certificate is replaced "in-place"; it will retain the same ID and other user properties (Name, Notes, Environments, etc...).
Expand Down Expand Up @@ -59,6 +68,13 @@ public Stream Export(CertificateResource certificate, CertificateFormat? format
var pathParameters = format.HasValue ? new { format= format.Value, password = password, includePrivateKey = includePrivateKey} : null;
return Client.GetContent(certificate.Link("Export"), pathParameters);
}

public Stream ExportAsPem(CertificateResource certificate, bool includePrivateKey = false,
CertificateExportPemOptions pemOptions = CertificateExportPemOptions.PrimaryOnly)
{
var parameters = new { format = CertificateFormat.Pem, includePrivateKey, pemOptions };
return Client.GetContent(certificate.Link("Export"), parameters);
}

public CertificateResource Replace(CertificateResource certificate, string certificateData, string password)
{
Expand Down
6 changes: 6 additions & 0 deletions source/Octopus.Client/Repositories/EnvironmentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ EnvironmentsSummaryResource Summary(
void Sort(string[] environmentIdsInOrder);
EnvironmentEditor CreateOrModify(string name);
EnvironmentEditor CreateOrModify(string name, string description);
EnvironmentEditor CreateOrModify(string name, string description, bool allowDynamicInfrastructure);
}

class EnvironmentRepository : BasicRepository<EnvironmentResource>, IEnvironmentRepository
Expand Down Expand Up @@ -113,5 +114,10 @@ public EnvironmentEditor CreateOrModify(string name, string description)
{
return new EnvironmentEditor(this).CreateOrModify(name, description);
}

public EnvironmentEditor CreateOrModify(string name, string description, bool allowDynamicInfrastructure)
{
return new EnvironmentEditor(this).CreateOrModify(name, description, allowDynamicInfrastructure);
}
}
}

0 comments on commit 5f0d91b

Please sign in to comment.