From 85f8dba915fca7a1fa396315a61d8abb7767f969 Mon Sep 17 00:00:00 2001 From: Vojtech Vit Date: Mon, 15 Apr 2019 12:58:09 +0200 Subject: [PATCH 1/2] feat: support for certificate APIs fixes issue Swoogan/Octopus-Cmdlets#16 --- Octopus-Cmdlets.Tests/AddCertificateTests.cs | 123 ++++++++++++++ Octopus-Cmdlets.Tests/GetCertificateTests.cs | 111 +++++++++++++ .../RemoveCertificateTests.cs | 132 +++++++++++++++ Octopus-Cmdlets/AddCertificate.cs | 113 +++++++++++++ Octopus-Cmdlets/GetCertificate.cs | 155 ++++++++++++++++++ Octopus-Cmdlets/Octopus-Cmdlets.psd1 | Bin 6290 -> 6290 bytes Octopus-Cmdlets/RemoveCertificate.cs | 121 ++++++++++++++ Octopus-Cmdlets/Utilities/Cache.cs | 2 + README.md | 2 +- Version.cs | 4 +- 10 files changed, 760 insertions(+), 3 deletions(-) create mode 100644 Octopus-Cmdlets.Tests/AddCertificateTests.cs create mode 100644 Octopus-Cmdlets.Tests/GetCertificateTests.cs create mode 100644 Octopus-Cmdlets.Tests/RemoveCertificateTests.cs create mode 100644 Octopus-Cmdlets/AddCertificate.cs create mode 100644 Octopus-Cmdlets/GetCertificate.cs create mode 100644 Octopus-Cmdlets/RemoveCertificate.cs diff --git a/Octopus-Cmdlets.Tests/AddCertificateTests.cs b/Octopus-Cmdlets.Tests/AddCertificateTests.cs new file mode 100644 index 0000000..f22a80b --- /dev/null +++ b/Octopus-Cmdlets.Tests/AddCertificateTests.cs @@ -0,0 +1,123 @@ +using System.Collections.Generic; +using System.Management.Automation; +using Xunit; +using Moq; +using Octopus.Client.Model; +using Octopus.Client.Repositories; +using System.Text; + +namespace Octopus_Cmdlets.Tests +{ + public class AddCertificateTests + { + private const string CmdletName = "Add-OctoCertificate"; + private PowerShell _ps; + private readonly List _certs = new List(); + + public AddCertificateTests() + { + _ps = Utilities.CreatePowerShell(CmdletName, typeof (AddCertificate)); + var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); + + _certs.Clear(); + + var envRepo = new Mock(); + envRepo.Setup(c => c.Create(It.IsAny(), It.IsAny())) + .Returns((CertificateResource c, object o) => + { + _certs.Add(c); + return c; + }); + + octoRepo.Setup(o => o.Certificates).Returns(envRepo.Object); + } + + [Fact] + public void With_Name() + { + // Execute cmdlet + _ps.AddCommand(CmdletName) + .AddParameter(nameof(AddCertificate.Name), "Octopus_Dev"); + + Assert.Throws(() => _ps.Invoke()); + } + + [Fact] + public void With_CertificateData() + { + // Execute cmdlet + _ps.AddCommand(CmdletName) + .AddParameter(nameof(AddCertificate.CertificateData), "CertData"); + + Assert.Throws(() => _ps.Invoke()); + } + + [Fact] + public void With_Name_And_CertificateData() + { + // Execute cmdlet + _ps.AddCommand(CmdletName) + .AddParameter(nameof(AddCertificate.Name), "Octopus_Dev") + .AddParameter(nameof(AddCertificate.CertificateData), "CertData"); + _ps.Invoke(); + + Assert.Single(_certs); + Assert.Equal("Octopus_Dev", _certs[0].Name); + Assert.Equal("CertData", _certs[0].CertificateData.NewValue); + } + + [Fact] + public void With_Name_And_CertificateData_And_Notes() + { + // Execute cmdlet + _ps.AddCommand(CmdletName) + .AddParameter(nameof(AddCertificate.Name), "Octopus_Dev") + .AddParameter(nameof(AddCertificate.CertificateData), "CertData") + .AddParameter(nameof(AddCertificate.Notes), "Octopus Development certificate"); + _ps.Invoke(); + + Assert.Single(_certs); + Assert.Equal("Octopus_Dev", _certs[0].Name); + Assert.Equal("CertData", _certs[0].CertificateData.NewValue); + Assert.Equal("Octopus Development certificate", _certs[0].Notes); + } + + [Fact] + public void With_Name_And_CertificateData_And_Environments() + { + // Execute cmdlet + _ps.AddCommand(CmdletName) + .AddParameter(nameof(AddCertificate.Name), "Octopus_Dev") + .AddParameter(nameof(AddCertificate.CertificateData), "CertData") + .AddParameter(nameof(AddCertificate.Environments), new[] { "Env1", "Env2" }); + _ps.Invoke(); + + Assert.Single(_certs); + Assert.Equal("Octopus_Dev", _certs[0].Name); + Assert.Equal("CertData", _certs[0].CertificateData.NewValue); + Assert.True(_certs[0].EnvironmentIds.SetEquals(new[] { "Env1", "Env2" })); + } + + [Fact] + public void With_Arguments() + { + // Execute cmdlet + _ps.AddCommand(CmdletName) + .AddArgument("Octopus_Dev") + .AddParameter(nameof(AddCertificate.CertificateData), "CertData"); + _ps.Invoke(); + + Assert.Single(_certs); + Assert.Equal("Octopus_Dev", _certs[0].Name); + Assert.Equal("CertData", _certs[0].CertificateData.NewValue); + } + + [Fact] + public void No_Arguments() + { + // Execute cmdlet + _ps.AddCommand(CmdletName); + Assert.Throws(() => _ps.Invoke()); + } + } +} diff --git a/Octopus-Cmdlets.Tests/GetCertificateTests.cs b/Octopus-Cmdlets.Tests/GetCertificateTests.cs new file mode 100644 index 0000000..1f6957e --- /dev/null +++ b/Octopus-Cmdlets.Tests/GetCertificateTests.cs @@ -0,0 +1,111 @@ +using System.Collections.Generic; +using System.Management.Automation; +using Xunit; +using Octopus.Client.Model; + +namespace Octopus_Cmdlets.Tests +{ + public class GetCertificateTests + { + private const string CmdletName = "Get-OctoCertificate"; + private PowerShell _ps; + + public GetCertificateTests() + { + _ps = Utilities.CreatePowerShell(CmdletName, typeof(GetCertificate)); + + var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); + + // Create some certificates + var certificates = new List + { + new CertificateResource("Octopus", "OctopusData") { Id = "certificates-1", EnvironmentIds = new ReferenceCollection("env1")}, + new CertificateResource("Deploy", "DeployData") { Id = "certificates-2", EnvironmentIds = new ReferenceCollection("env2")}, + new CertificateResource("Automation", "AutomationData") { Id = "certificates-3", EnvironmentIds = new ReferenceCollection("env3")}, + new CertificateResource("Server", "ServerData") { Id = "certificates-4", EnvironmentIds = new ReferenceCollection("env4")}, + }; + octoRepo.Setup(o => o.Certificates.FindAll(null, null)).Returns(certificates); + } + + [Fact] + public void No_Arguments() + { + // Execute cmdlet + _ps.AddCommand(CmdletName); + var certificates = _ps.Invoke(); + + Assert.Equal(4, certificates.Count); + } + + [Fact] + public void With_Name() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddArgument("Octopus"); + var certificates = _ps.Invoke(); + + Assert.Single(certificates); + Assert.Equal("Octopus", certificates[0].Name); + } + + [Fact] + public void With_Invalid_Name() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddArgument("Gibberish"); + var certificates = _ps.Invoke(); + + Assert.Empty(certificates); + } + + [Fact] + public void With_Id() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddParameter("Id", "certificates-1"); + var certificates = _ps.Invoke(); + + Assert.Single(certificates); + Assert.Equal("Octopus", certificates[0].Name); + } + + [Fact] + public void With_Invalid_Id() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddParameter("Id", "Gibberish"); + var certificates = _ps.Invoke(); + + Assert.Empty(certificates); + } + + [Fact] + public void With_Environment() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddParameter("Environment", "env1"); + var certificates = _ps.Invoke(); + + Assert.Single(certificates); + Assert.Equal("Octopus", certificates[0].Name); + } + + [Fact] + public void With_Invalid_EnvironmentValue() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddParameter("Environment", "Gibberish"); + var certificates = _ps.Invoke(); + + Assert.Empty(certificates); + } + + [Fact] + public void With_Id_And_Name() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddParameter("Name", "Name").AddParameter("Id", "Id"); + Assert.Throws(() => _ps.Invoke()); + } + } +} diff --git a/Octopus-Cmdlets.Tests/RemoveCertificateTests.cs b/Octopus-Cmdlets.Tests/RemoveCertificateTests.cs new file mode 100644 index 0000000..b77edfc --- /dev/null +++ b/Octopus-Cmdlets.Tests/RemoveCertificateTests.cs @@ -0,0 +1,132 @@ +using System.Collections.Generic; +using System.Management.Automation; +using Xunit; +using Moq; +using Octopus.Client.Exceptions; +using Octopus.Client.Model; + +namespace Octopus_Cmdlets.Tests +{ + public class RemoveCertificateTests + { + private const string CmdletName = "Remove-OctoCertificate"; + private PowerShell _ps; + private readonly List _certs = new List(); + + private readonly CertificateResource _cert = new CertificateResource("CERT2", "CertData2"); + + public RemoveCertificateTests() + { + _ps = Utilities.CreatePowerShell(CmdletName, typeof(RemoveCertificate)); + + var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); + + // Create some library variable sets + _certs.Clear(); + _certs.Add(new CertificateResource("CERT 1", "CertData1") { Id = "CERT1" }); + _certs.Add(_cert); + _certs.Add(new CertificateResource("CERT 3", "CertData3") { Id = "CERT3" }); + + octoRepo.Setup(o => o.Certificates.Delete(It.IsAny())).Callback( + (CertificateResource set) => + { + if (_certs.Contains(set)) + _certs.Remove(set); + else + throw new KeyNotFoundException("The given key was not present in the dictionary."); + } + ); + + octoRepo.Setup(o => o.Certificates.Get("CERT1")).Returns(_cert); + octoRepo.Setup(o => o.Certificates.Get(It.IsNotIn(new[] { "CERT1" }))) + .Throws(new OctopusResourceNotFoundException("Not Found")); + + octoRepo.Setup(o => o.Certificates.FindByName("CERT 2", It.IsAny(), It.IsAny())).Returns(_cert); + octoRepo.Setup(o => o.Certificates.FindByName("Gibberish", It.IsAny(), It.IsAny())).Returns((CertificateResource) null); + } + + [Fact] + public void No_Arguments() + { + // Execute cmdlet + _ps.AddCommand(CmdletName); + Assert.Throws(() => _ps.Invoke()); + } + + [Fact] + public void With_Id() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddParameter("Id", new [] {"CERT1"}); + _ps.Invoke(); + + Assert.Equal(2, _certs.Count); + Assert.DoesNotContain(_cert, _certs); + } + + [Fact] + public void With_Invalid_Id() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddParameter("Id", new[] {"Gibberish"}); + _ps.Invoke(); + + Assert.Equal(3, _certs.Count); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("A certificate with the id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); + } + + [Fact] + public void With_Name() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddParameter("Name", new[] {"CERT 2"}); + _ps.Invoke(); + + Assert.Equal(2, _certs.Count); + Assert.DoesNotContain(_cert, _certs); + } + + [Fact] + public void With_Invalid_Name() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddParameter("Name", new[] { "Gibberish" }); + _ps.Invoke(); + + Assert.Equal(3, _certs.Count); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("The certificate 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); + } + + [Fact] + public void With_Valid_And_Invalid_Names() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddParameter("Name", new[] { "CERT 2", "Gibberish" }); + _ps.Invoke(); + + Assert.Equal(2, _certs.Count); + Assert.DoesNotContain(_cert, _certs); + } + + [Fact] + public void With_Arguments() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddArgument(new[] { "CERT 2" }); + _ps.Invoke(); + + Assert.Equal(2, _certs.Count); + Assert.DoesNotContain(_cert, _certs); + } + + [Fact] + public void With_Name_And_Id() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddParameter("Name", "Gibberish").AddParameter("Id", "Gibberish"); + Assert.Throws(() => _ps.Invoke()); + } + } +} \ No newline at end of file diff --git a/Octopus-Cmdlets/AddCertificate.cs b/Octopus-Cmdlets/AddCertificate.cs new file mode 100644 index 0000000..14edaca --- /dev/null +++ b/Octopus-Cmdlets/AddCertificate.cs @@ -0,0 +1,113 @@ +#region License +// Copyright 2014 Colin Svingen + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion + +using System.Management.Automation; +using Octopus.Client; +using Octopus.Client.Model; + +namespace Octopus_Cmdlets +{ + /// + /// Add a new certificate to the Octopus Deploy server. + /// The Add-OctoCertificate cmdlet adds a new certificate to the Octopus Deploy server. + /// + /// + /// PS C:\>add-octocertificate CERT1 -FilePath .\cert1.cer + /// + /// Uploads a new certificate named 'CERT1' from file '.\cert1.cer'. + /// + /// + /// + /// PS C:\>add-octocertificate CERT2 -FilePath .\cert1.pfx -Password MyPassword + /// + /// Uploads a new certificate named 'CERT2' from file '.\cert1.pfx' that is encrypted using password 'MyPassword'. + /// + /// + [Cmdlet(VerbsCommon.Add, "Certificate")] + public class AddCertificate : PSCmdlet + { + /// + /// The name of the certificate to create. + /// + [Parameter( + Position = 0, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + public string Name { get; set; } + + /// + /// The certificate data. + /// + [Parameter( + Position = 1, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + public string CertificateData { get; set; } + + /// + /// Notes about the certificate to create. + /// + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true)] + public string Notes { get; set; } + + /// + /// The password protecting the certificate data. + /// + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true)] + public string Password { get; set; } + + /// + /// The environment scopes of the certificate to create. + /// + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true)] + public string[] Environments { get; set; } + + private IOctopusRepository _octopus; + + /// + /// BeginProcessing + /// + protected override void BeginProcessing() + { + _octopus = Session.RetrieveSession(this); + } + + /// + /// ProcessRecord + /// + protected override void ProcessRecord() + { + var certificate = new CertificateResource( + Name, + CertificateData, + Password) + { + Notes = Notes, + EnvironmentIds = new ReferenceCollection(Environments) + }; + + _octopus.Certificates.Create( + certificate, + null); + } + } +} diff --git a/Octopus-Cmdlets/GetCertificate.cs b/Octopus-Cmdlets/GetCertificate.cs new file mode 100644 index 0000000..2627d54 --- /dev/null +++ b/Octopus-Cmdlets/GetCertificate.cs @@ -0,0 +1,155 @@ +#region License +// Copyright 2014 Colin Svingen + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; +using Octopus.Client; +using Octopus.Client.Model; + +namespace Octopus_Cmdlets +{ + /// + /// Gets the certificates in the Octopus Deploy server. + /// The Get-OctoCertificate cmdlet gets the certificates in the Octopus Deploy server. + /// + /// + /// PS C:\>get-octocertificate + /// This command gets all the certificates. + /// + [Cmdlet(VerbsCommon.Get, "Certificate", DefaultParameterSetName = "ByName")] + public class GetCertificate : PSCmdlet + { + /// + /// The name of the certificate to retrieve. + /// + [Parameter( + ParameterSetName = "ByName", + Position = 0, + Mandatory = false, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true)] + public string[] Name { get; set; } + + /// + /// The id of the certificate to retrieve. + /// + [Parameter( + ParameterSetName = "ById", + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [Alias("Id")] + public string[] CertificateId { get; set; } + + /// + /// The environments of the certificates to retrieve. + /// + [Parameter( + ParameterSetName = "ByEnvironment", + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + public string[] Environment { get; set; } + + /// + /// Determines whether to temporarily cache the results or not. + /// + [Parameter(Mandatory = false)] + public SwitchParameter Cache { get; set; } + + private IOctopusRepository _octopus; + private List _certificates; + + /// + /// BeginProcessing + /// + protected override void BeginProcessing() + { + _octopus = Session.RetrieveSession(this); + + WriteDebug("Connection established"); + + if (!Cache || Utilities.Cache.Certificates.IsExpired) + _certificates = _octopus.Certificates.FindAll(); + + if (Cache) + { + if (Utilities.Cache.Certificates.IsExpired) + Utilities.Cache.Certificates.Set(_certificates); + else + _certificates = Utilities.Cache.Certificates.Values; + } + + WriteDebug("Loaded certificates"); + } + + protected override void ProcessRecord() + { + switch (ParameterSetName) + { + case "ByName": + ProcessByName(); + break; + case "ById": + ProcessById(); + break; + case "ByEnvironment": + ProcessByEnvironment(); + break; + default: + throw new Exception("Unknown ParameterSetName: " + ParameterSetName); + } + } + + private void ProcessByEnvironment() + { + var certs = Environment == null + ? _certificates + : (from c in _certificates + from cenv in c.EnvironmentIds + from env in Environment + where cenv == env + select c); + + foreach (var cert in certs) + WriteObject(cert); + } + + private void ProcessByName() + { + var certs = Name == null + ? _certificates + : (from c in _certificates + from n in Name + where c.Name.Equals(n, StringComparison.InvariantCultureIgnoreCase) + select c); + + foreach (var cert in certs) + WriteObject(cert); + } + + private void ProcessById() + { + var certs = from c in _certificates + from id in CertificateId + where id == c.Id + select c; + + foreach (var cert in certs) + WriteObject(cert); + } + } +} diff --git a/Octopus-Cmdlets/Octopus-Cmdlets.psd1 b/Octopus-Cmdlets/Octopus-Cmdlets.psd1 index 8d7ab3668bb1c934080a4041e55de4f517c74571..be5a0fa7ef83f9b1c4597e4d9d49f5848648e37e 100644 GIT binary patch delta 18 ZcmbPaILUB>9TTe=gC2vyW@jdUF#s@}1Z@BS delta 18 ZcmbPaILUB>9TTewgC2v)W@jdUF#s^21aANU diff --git a/Octopus-Cmdlets/RemoveCertificate.cs b/Octopus-Cmdlets/RemoveCertificate.cs new file mode 100644 index 0000000..ce132d5 --- /dev/null +++ b/Octopus-Cmdlets/RemoveCertificate.cs @@ -0,0 +1,121 @@ +#region License +// Copyright 2014 Colin Svingen + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion + +using System; +using System.Management.Automation; +using Octopus.Client; +using Octopus.Client.Exceptions; + +namespace Octopus_Cmdlets +{ + /// + /// Remove a certificate from the Octopus Deploy server. + /// The Remove-OctoCertificate cmdlet removes a certificate from the Octopus Deploy server. + /// + /// + /// PS C:\>remove-octocertificate CERT1 + /// + /// Remove the certificate named 'CERT1'. + /// + /// + [Cmdlet(VerbsCommon.Remove, "Certificate")] + public class RemoveCertificate : PSCmdlet + { + /// + /// The name of the certificate to remove. + /// + [Parameter( + ParameterSetName = "ByName", + Position = 0, + Mandatory = true, + ValueFromPipelineByPropertyName = true, + ValueFromPipeline = true)] + public string[] Name { get; set; } + + /// + /// The id of the certificate to remove. + /// + [Parameter( + ParameterSetName = "ById", + Mandatory = true, + ValueFromPipelineByPropertyName = true, + ValueFromPipeline = false)] + [Alias("CertificateId")] + public string[] Id { get; set; } + + private IOctopusRepository _octopus; + + /// + /// BeginProcessing + /// + protected override void BeginProcessing() + { + _octopus = Session.RetrieveSession(this); + } + + /// + /// ProcessRecord + /// + protected override void ProcessRecord() + { + switch (ParameterSetName) + { + case "ByName": + ProcessByName(); + break; + case "ById": + ProcessById(); + break; + default: + throw new Exception("Unknown ParameterSetName: " + ParameterSetName); + } + } + + private void ProcessById() + { + foreach (var id in Id) + { + try + { + var cert = _octopus.Certificates.Get(id); + WriteVerbose("Deleting certificate: " + cert.Name); + _octopus.Certificates.Delete(cert); + } + catch (OctopusResourceNotFoundException) + { + WriteWarning(string.Format("A certificate with the id '{0}' does not exist.", id)); + } + } + } + + private void ProcessByName() + { + foreach (var name in Name) + { + var cert = _octopus.Certificates.FindByName(name); + if (cert != null) + { + WriteVerbose("Deleting certificate: " + cert.Name); + _octopus.Certificates.Delete(cert); + } + else + { + WriteWarning(string.Format("The certificate '{0}' does not exist.", name)); + } + } + } + } +} diff --git a/Octopus-Cmdlets/Utilities/Cache.cs b/Octopus-Cmdlets/Utilities/Cache.cs index 1abe72d..b61d3b2 100644 --- a/Octopus-Cmdlets/Utilities/Cache.cs +++ b/Octopus-Cmdlets/Utilities/Cache.cs @@ -24,12 +24,14 @@ static class Cache { public const int Duration = 60; public static readonly CacheNode Environments; + public static readonly CacheNode Certificates; public static readonly CacheNode LibraryVariableSets; public static readonly CacheNode Projects; public static readonly CacheNode Releases; static Cache() { + Certificates = new CacheNode(); LibraryVariableSets = new CacheNode(); Environments = new CacheNode(); Projects = new CacheNode(); diff --git a/README.md b/README.md index 4722acd..6bcf12a 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Powershell Gallery (preferred method) Binary Archive -------------- -Download the latest binary: [v0.5.1](https://github.com/Swoogan/Octopus-Cmdlets/releases/download/v0.5.1/Octopus-Cmdlets-v0.5.1.zip) +Download the latest binary: [v0.6.0](https://github.com/Swoogan/Octopus-Cmdlets/releases/download/v0.6.0/Octopus-Cmdlets-v0.6.0.zip) Extract the zip and copy the `Octopus-Cmdlets` folder into a folder in your `$env:PSModulePath`. diff --git a/Version.cs b/Version.cs index 4ab3645..3d1c903 100644 --- a/Version.cs +++ b/Version.cs @@ -1,4 +1,4 @@ using System.Reflection; -[assembly: AssemblyVersion("0.5.0.0")] -[assembly: AssemblyFileVersion("0.5.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("0.6.0.0")] +[assembly: AssemblyFileVersion("0.6.0.0")] \ No newline at end of file From 911c8c43a7dcae0995f4002548caab60aa40d597 Mon Sep 17 00:00:00 2001 From: Vojtech Vit Date: Mon, 15 Apr 2019 13:52:55 +0200 Subject: [PATCH 2/2] feat: Variable type (e.g. Certificate) can now be specified --- Octopus-Cmdlets/AddLibraryVariable.cs | 11 ++++++++++- Octopus-Cmdlets/AddVariable.cs | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Octopus-Cmdlets/AddLibraryVariable.cs b/Octopus-Cmdlets/AddLibraryVariable.cs index fb4bbfe..6573770 100644 --- a/Octopus-Cmdlets/AddLibraryVariable.cs +++ b/Octopus-Cmdlets/AddLibraryVariable.cs @@ -81,6 +81,15 @@ public class AddLibraryVariable : PSCmdlet ValueFromPipelineByPropertyName = true)] public string Value { get; set; } + /// + /// The type of the variable to create. + /// + [Parameter( + ParameterSetName = "ByParts", + Mandatory = false, + ValueFromPipelineByPropertyName = true)] + public VariableType Type { get; set; } + /// /// The environments to restrict the scope to. /// @@ -181,7 +190,7 @@ private void ProcessByObject() private void ProcessByParts() { - var variable = new VariableResource { Name = Name, Value = Value, IsSensitive = Sensitive }; + var variable = new VariableResource { Name = Name, Value = Value, Type = Type, IsSensitive = Sensitive }; if (Environments != null) AddEnvironments(variable); diff --git a/Octopus-Cmdlets/AddVariable.cs b/Octopus-Cmdlets/AddVariable.cs index 9f5cb60..9f02756 100644 --- a/Octopus-Cmdlets/AddVariable.cs +++ b/Octopus-Cmdlets/AddVariable.cs @@ -66,6 +66,15 @@ public class AddVariable : PSCmdlet ValueFromPipelineByPropertyName = true)] public string Value { get; set; } + /// + /// The type of the variable to create. + /// + [Parameter( + ParameterSetName = "ByParts", + Mandatory = false, + ValueFromPipelineByPropertyName = true)] + public VariableType Type { get; set; } + /// /// The environments to restrict the scope to. /// @@ -190,7 +199,7 @@ protected override void ProcessRecord() private void ProcessByParts() { - var variable = new VariableResource { Name = Name, Value = Value, IsSensitive = Sensitive }; + var variable = new VariableResource { Name = Name, Value = Value, Type = Type, IsSensitive = Sensitive }; if (Environments != null) AddEnvironments(variable);