diff --git a/src/PSInfisicalAPI.Tests/PkiEndpointRegistryTests.cs b/src/PSInfisicalAPI.Tests/PkiEndpointRegistryTests.cs index dae7d4b..9e692e9 100644 --- a/src/PSInfisicalAPI.Tests/PkiEndpointRegistryTests.cs +++ b/src/PSInfisicalAPI.Tests/PkiEndpointRegistryTests.cs @@ -61,7 +61,28 @@ namespace PSInfisicalAPI.Tests Type cmdletType = ModuleAssembly.GetType("PSInfisicalAPI.Cmdlets.GetInfisicalCertificateCmdlet", true); Assert.NotNull(cmdletType.GetProperty("CommonName")); Assert.NotNull(cmdletType.GetProperty("FriendlyName")); + Assert.NotNull(cmdletType.GetProperty("Search")); + Assert.NotNull(cmdletType.GetProperty("Status")); Assert.NotNull(cmdletType.GetProperty("CaId")); + Assert.NotNull(cmdletType.GetProperty("ProfileId")); + Assert.NotNull(cmdletType.GetProperty("ApplicationId")); + Assert.NotNull(cmdletType.GetProperty("ApplicationIds")); + Assert.NotNull(cmdletType.GetProperty("EnrollmentType")); + Assert.NotNull(cmdletType.GetProperty("ExtendedKeyUsage")); + Assert.NotNull(cmdletType.GetProperty("KeyAlgorithm")); + Assert.NotNull(cmdletType.GetProperty("SignatureAlgorithm")); + Assert.NotNull(cmdletType.GetProperty("KeySize")); + Assert.NotNull(cmdletType.GetProperty("Source")); + Assert.NotNull(cmdletType.GetProperty("FromDate")); + Assert.NotNull(cmdletType.GetProperty("ToDate")); + Assert.NotNull(cmdletType.GetProperty("NotAfterFrom")); + Assert.NotNull(cmdletType.GetProperty("NotAfterTo")); + Assert.NotNull(cmdletType.GetProperty("NotBeforeFrom")); + Assert.NotNull(cmdletType.GetProperty("NotBeforeTo")); + Assert.NotNull(cmdletType.GetProperty("Metadata")); + Assert.NotNull(cmdletType.GetProperty("ForPkiSync")); + Assert.NotNull(cmdletType.GetProperty("SortBy")); + Assert.NotNull(cmdletType.GetProperty("SortOrder")); Assert.NotNull(cmdletType.GetProperty("Limit")); Assert.NotNull(cmdletType.GetProperty("Offset")); Assert.NotNull(cmdletType.GetProperty("NoAutoPage")); diff --git a/src/PSInfisicalAPI/Cmdlets/GetInfisicalCertificateCmdlet.cs b/src/PSInfisicalAPI/Cmdlets/GetInfisicalCertificateCmdlet.cs index a9b98d7..566d4fb 100644 --- a/src/PSInfisicalAPI/Cmdlets/GetInfisicalCertificateCmdlet.cs +++ b/src/PSInfisicalAPI/Cmdlets/GetInfisicalCertificateCmdlet.cs @@ -1,4 +1,6 @@ using System; +using System.Collections; +using System.Collections.Generic; using System.Management.Automation; using PSInfisicalAPI.Connections; using PSInfisicalAPI.Models; @@ -18,8 +20,35 @@ namespace PSInfisicalAPI.Cmdlets [Parameter(ParameterSetName = "List", Mandatory = true)] public string ProjectId { get; set; } [Parameter(ParameterSetName = "List")] public string CommonName { get; set; } [Parameter(ParameterSetName = "List")] public string FriendlyName { get; set; } + [Parameter(ParameterSetName = "List")] public string Search { get; set; } [Parameter(ParameterSetName = "List")] public string Status { get; set; } [Parameter(ParameterSetName = "List")] public string[] CaId { get; set; } + [Parameter(ParameterSetName = "List")] public string[] ProfileId { get; set; } + [Parameter(ParameterSetName = "List")] public string ApplicationId { get; set; } + [Parameter(ParameterSetName = "List")] public string[] ApplicationIds { get; set; } + [Parameter(ParameterSetName = "List")] public string[] EnrollmentType { get; set; } + [Parameter(ParameterSetName = "List")] public string ExtendedKeyUsage { get; set; } + [Parameter(ParameterSetName = "List")] public string[] KeyAlgorithm { get; set; } + [Parameter(ParameterSetName = "List")] public string SignatureAlgorithm { get; set; } + [Parameter(ParameterSetName = "List")] public int[] KeySize { get; set; } + [Parameter(ParameterSetName = "List")] public string[] Source { get; set; } + [Parameter(ParameterSetName = "List")] public DateTimeOffset? FromDate { get; set; } + [Parameter(ParameterSetName = "List")] public DateTimeOffset? ToDate { get; set; } + [Parameter(ParameterSetName = "List")] public DateTimeOffset? NotAfterFrom { get; set; } + [Parameter(ParameterSetName = "List")] public DateTimeOffset? NotAfterTo { get; set; } + [Parameter(ParameterSetName = "List")] public DateTimeOffset? NotBeforeFrom { get; set; } + [Parameter(ParameterSetName = "List")] public DateTimeOffset? NotBeforeTo { get; set; } + [Parameter(ParameterSetName = "List")] public Hashtable Metadata { get; set; } + [Parameter(ParameterSetName = "List")] public SwitchParameter ForPkiSync { get; set; } + + [Parameter(ParameterSetName = "List")] + [ValidateSet("notAfter", "notBefore", "createdAt", "commonName", "keyAlgorithm", "status")] + public string SortBy { get; set; } + + [Parameter(ParameterSetName = "List")] + [ValidateSet("asc", "desc")] + public string SortOrder { get; set; } + [Parameter(ParameterSetName = "List")] public int? Limit { get; set; } [Parameter(ParameterSetName = "List")] public int? Offset { get; set; } [Parameter(ParameterSetName = "List")] public SwitchParameter NoAutoPage { get; set; } @@ -47,8 +76,28 @@ namespace PSInfisicalAPI.Cmdlets ProjectId = ProjectId, CommonName = CommonName, FriendlyName = FriendlyName, + Search = Search, Status = Status, CaIds = CaId, + ProfileIds = ProfileId, + ApplicationId = ApplicationId, + ApplicationIds = ApplicationIds, + EnrollmentTypes = EnrollmentType, + ExtendedKeyUsage = ExtendedKeyUsage, + KeyAlgorithm = KeyAlgorithm, + SignatureAlgorithm = SignatureAlgorithm, + KeySizes = KeySize, + Source = Source, + FromDate = FromDate, + ToDate = ToDate, + NotAfterFrom = NotAfterFrom, + NotAfterTo = NotAfterTo, + NotBeforeFrom = NotBeforeFrom, + NotBeforeTo = NotBeforeTo, + Metadata = ToStringDictionary(Metadata), + SortBy = SortBy, + SortOrder = SortOrder, + ForPkiSync = ForPkiSync.IsPresent ? (bool?)true : null, Limit = Limit ?? 100, Offset = Offset ?? 0 }; @@ -87,5 +136,17 @@ namespace PSInfisicalAPI.Cmdlets ThrowTerminatingForException("GetInfisicalCertificateCmdlet", "GetCertificate", exception); } } + + private static Dictionary ToStringDictionary(Hashtable hashtable) + { + if (hashtable == null) { return null; } + Dictionary result = new Dictionary(StringComparer.OrdinalIgnoreCase); + foreach (DictionaryEntry entry in hashtable) + { + if (entry.Key == null) { continue; } + result[entry.Key.ToString()] = entry.Value != null ? entry.Value.ToString() : null; + } + return result; + } } } diff --git a/src/PSInfisicalAPI/Cmdlets/SearchInfisicalCertificateCmdlet.cs b/src/PSInfisicalAPI/Cmdlets/SearchInfisicalCertificateCmdlet.cs index 1bd04b5..fd1d0ae 100644 --- a/src/PSInfisicalAPI/Cmdlets/SearchInfisicalCertificateCmdlet.cs +++ b/src/PSInfisicalAPI/Cmdlets/SearchInfisicalCertificateCmdlet.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Management.Automation; using PSInfisicalAPI.Connections; @@ -18,17 +19,27 @@ namespace PSInfisicalAPI.Cmdlets [Parameter] public string Status { get; set; } [Parameter] public string[] CaId { get; set; } [Parameter] public string[] ProfileId { get; set; } - [Parameter] public string[] ApplicationId { get; set; } + [Parameter] public string ApplicationId { get; set; } + [Parameter] public string[] ApplicationIds { get; set; } [Parameter] public string[] EnrollmentType { get; set; } [Parameter] public string ExtendedKeyUsage { get; set; } [Parameter] public string[] KeyAlgorithm { get; set; } [Parameter] public string SignatureAlgorithm { get; set; } + [Parameter] public int[] KeySize { get; set; } [Parameter] public string[] Source { get; set; } + [Parameter] public DateTimeOffset? FromDate { get; set; } + [Parameter] public DateTimeOffset? ToDate { get; set; } [Parameter] public DateTimeOffset? NotAfterFrom { get; set; } [Parameter] public DateTimeOffset? NotAfterTo { get; set; } [Parameter] public DateTimeOffset? NotBeforeFrom { get; set; } [Parameter] public DateTimeOffset? NotBeforeTo { get; set; } - [Parameter] public string SortBy { get; set; } + [Parameter] public Hashtable Metadata { get; set; } + [Parameter] public SwitchParameter ForPkiSync { get; set; } + + [Parameter] + [ValidateSet("notAfter", "notBefore", "createdAt", "commonName", "keyAlgorithm", "status")] + public string SortBy { get; set; } + [Parameter] [ValidateSet("asc", "desc")] public string SortOrder { get; set; } [Parameter] public int? Limit { get; set; } [Parameter] public int? Offset { get; set; } @@ -91,21 +102,39 @@ namespace PSInfisicalAPI.Cmdlets Status = Status, CaIds = CaId, ProfileIds = ProfileId, - ApplicationIds = ApplicationId, + ApplicationId = ApplicationId, + ApplicationIds = ApplicationIds, EnrollmentTypes = EnrollmentType, ExtendedKeyUsage = ExtendedKeyUsage, KeyAlgorithm = KeyAlgorithm, SignatureAlgorithm = SignatureAlgorithm, + KeySizes = KeySize, Source = Source, + FromDate = FromDate, + ToDate = ToDate, NotAfterFrom = NotAfterFrom, NotAfterTo = NotAfterTo, NotBeforeFrom = NotBeforeFrom, NotBeforeTo = NotBeforeTo, + Metadata = ToStringDictionary(Metadata), + ForPkiSync = ForPkiSync.IsPresent ? (bool?)true : null, SortBy = SortBy, SortOrder = SortOrder, Limit = Limit, Offset = Offset }; } + + private static Dictionary ToStringDictionary(Hashtable hashtable) + { + if (hashtable == null) { return null; } + Dictionary result = new Dictionary(StringComparer.OrdinalIgnoreCase); + foreach (DictionaryEntry entry in hashtable) + { + if (entry.Key == null) { continue; } + result[entry.Key.ToString()] = entry.Value != null ? entry.Value.ToString() : null; + } + return result; + } } } diff --git a/src/PSInfisicalAPI/Pki/InfisicalCertificateDtos.cs b/src/PSInfisicalAPI/Pki/InfisicalCertificateDtos.cs index 5996c44..44e8def 100644 --- a/src/PSInfisicalAPI/Pki/InfisicalCertificateDtos.cs +++ b/src/PSInfisicalAPI/Pki/InfisicalCertificateDtos.cs @@ -70,11 +70,13 @@ namespace PSInfisicalAPI.Pki [JsonProperty("limit", NullValueHandling = NullValueHandling.Ignore)] public int? Limit { get; set; } [JsonProperty("caIds", NullValueHandling = NullValueHandling.Ignore)] public string[] CaIds { get; set; } [JsonProperty("profileIds", NullValueHandling = NullValueHandling.Ignore)] public string[] ProfileIds { get; set; } + [JsonProperty("applicationId", NullValueHandling = NullValueHandling.Ignore)] public string ApplicationId { get; set; } [JsonProperty("applicationIds", NullValueHandling = NullValueHandling.Ignore)] public string[] ApplicationIds { get; set; } [JsonProperty("enrollmentTypes", NullValueHandling = NullValueHandling.Ignore)] public string[] EnrollmentTypes { get; set; } [JsonProperty("extendedKeyUsage", NullValueHandling = NullValueHandling.Ignore)] public string ExtendedKeyUsage { get; set; } [JsonProperty("keyAlgorithm", NullValueHandling = NullValueHandling.Ignore)] public string[] KeyAlgorithm { get; set; } [JsonProperty("signatureAlgorithm", NullValueHandling = NullValueHandling.Ignore)] public string SignatureAlgorithm { get; set; } + [JsonProperty("keySizes", NullValueHandling = NullValueHandling.Ignore)] public int[] KeySizes { get; set; } [JsonProperty("source", NullValueHandling = NullValueHandling.Ignore)] public string[] Source { get; set; } [JsonProperty("fromDate", NullValueHandling = NullValueHandling.Ignore)] public string FromDate { get; set; } [JsonProperty("toDate", NullValueHandling = NullValueHandling.Ignore)] public string ToDate { get; set; } @@ -82,11 +84,18 @@ namespace PSInfisicalAPI.Pki [JsonProperty("notAfterTo", NullValueHandling = NullValueHandling.Ignore)] public string NotAfterTo { get; set; } [JsonProperty("notBeforeFrom", NullValueHandling = NullValueHandling.Ignore)] public string NotBeforeFrom { get; set; } [JsonProperty("notBeforeTo", NullValueHandling = NullValueHandling.Ignore)] public string NotBeforeTo { get; set; } + [JsonProperty("metadata", NullValueHandling = NullValueHandling.Ignore)] public InfisicalCertificateSearchMetadataEntryDto[] Metadata { get; set; } [JsonProperty("sortBy", NullValueHandling = NullValueHandling.Ignore)] public string SortBy { get; set; } [JsonProperty("sortOrder", NullValueHandling = NullValueHandling.Ignore)] public string SortOrder { get; set; } [JsonProperty("forPkiSync", NullValueHandling = NullValueHandling.Ignore)] public bool? ForPkiSync { get; set; } } + internal sealed class InfisicalCertificateSearchMetadataEntryDto + { + [JsonProperty("key")] public string Key { get; set; } + [JsonProperty("value", NullValueHandling = NullValueHandling.Ignore)] public string Value { get; set; } + } + internal sealed class InfisicalCertificateBundleResponseDto { [JsonProperty("serialNumber")] public string SerialNumber { get; set; } diff --git a/src/PSInfisicalAPI/Pki/InfisicalCertificateSearchQuery.cs b/src/PSInfisicalAPI/Pki/InfisicalCertificateSearchQuery.cs index f655a51..fb08d4b 100644 --- a/src/PSInfisicalAPI/Pki/InfisicalCertificateSearchQuery.cs +++ b/src/PSInfisicalAPI/Pki/InfisicalCertificateSearchQuery.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace PSInfisicalAPI.Pki { @@ -13,11 +14,13 @@ namespace PSInfisicalAPI.Pki public int? Limit { get; set; } public string[] CaIds { get; set; } public string[] ProfileIds { get; set; } + public string ApplicationId { get; set; } public string[] ApplicationIds { get; set; } public string[] EnrollmentTypes { get; set; } public string ExtendedKeyUsage { get; set; } public string[] KeyAlgorithm { get; set; } public string SignatureAlgorithm { get; set; } + public int[] KeySizes { get; set; } public string[] Source { get; set; } public DateTimeOffset? FromDate { get; set; } public DateTimeOffset? ToDate { get; set; } @@ -25,6 +28,7 @@ namespace PSInfisicalAPI.Pki public DateTimeOffset? NotAfterTo { get; set; } public DateTimeOffset? NotBeforeFrom { get; set; } public DateTimeOffset? NotBeforeTo { get; set; } + public IDictionary Metadata { get; set; } public string SortBy { get; set; } public string SortOrder { get; set; } public bool? ForPkiSync { get; set; } diff --git a/src/PSInfisicalAPI/Pki/InfisicalPkiClient.cs b/src/PSInfisicalAPI/Pki/InfisicalPkiClient.cs index 2735cd6..657ea93 100644 --- a/src/PSInfisicalAPI/Pki/InfisicalPkiClient.cs +++ b/src/PSInfisicalAPI/Pki/InfisicalPkiClient.cs @@ -863,11 +863,13 @@ namespace PSInfisicalAPI.Pki Limit = query.Limit, CaIds = query.CaIds, ProfileIds = query.ProfileIds, + ApplicationId = query.ApplicationId, ApplicationIds = query.ApplicationIds, EnrollmentTypes = query.EnrollmentTypes, ExtendedKeyUsage = query.ExtendedKeyUsage, KeyAlgorithm = query.KeyAlgorithm, SignatureAlgorithm = query.SignatureAlgorithm, + KeySizes = query.KeySizes, Source = query.Source, FromDate = FormatTimestamp(query.FromDate), ToDate = FormatTimestamp(query.ToDate), @@ -875,12 +877,25 @@ namespace PSInfisicalAPI.Pki NotAfterTo = FormatTimestamp(query.NotAfterTo), NotBeforeFrom = FormatTimestamp(query.NotBeforeFrom), NotBeforeTo = FormatTimestamp(query.NotBeforeTo), + Metadata = BuildMetadataEntries(query.Metadata), SortBy = query.SortBy, SortOrder = query.SortOrder, ForPkiSync = query.ForPkiSync }; } + private static InfisicalCertificateSearchMetadataEntryDto[] BuildMetadataEntries(IDictionary source) + { + if (source == null || source.Count == 0) { return null; } + List entries = new List(source.Count); + foreach (KeyValuePair pair in source) + { + if (string.IsNullOrEmpty(pair.Key)) { continue; } + entries.Add(new InfisicalCertificateSearchMetadataEntryDto { Key = pair.Key, Value = pair.Value }); + } + return entries.Count == 0 ? null : entries.ToArray(); + } + private static string FormatTimestamp(DateTimeOffset? value) { if (!value.HasValue) { return null; }