|
| 1 | +using System.Management.Automation; |
| 2 | +using UiPath.PowerShell.Models; |
| 3 | +using UiPath.PowerShell.Util; |
| 4 | +using UiPath.Web.Client201910; |
| 5 | +//NB: the use of 20.4 resource type enum on the 19.10 client is intentional |
| 6 | +using ResourceType20204 = UiPath.Web.Client20204.Models.DefaultCredentialStoreDtoResourceType; |
| 7 | + |
| 8 | +namespace UiPath.PowerShell.Cmdlets |
| 9 | +{ |
| 10 | + [Cmdlet(VerbsCommon.Get, Nouns.CredentialStore)] |
| 11 | + public class GetCredentialStore : FilteredIdCmdlet |
| 12 | + { |
| 13 | + [Filter] |
| 14 | + [Parameter(ParameterSetName = "Filter")] |
| 15 | + public string Name { get; set; } |
| 16 | + |
| 17 | + [Filter] |
| 18 | + [Parameter(ParameterSetName = "Filter")] |
| 19 | + public string Type { get; set; } |
| 20 | + |
| 21 | + [ValidateEnum(typeof(ResourceType20204))] |
| 22 | + [Parameter(ParameterSetName = "Defaults", Mandatory = true)] |
| 23 | + public string Default { get; set; } |
| 24 | + |
| 25 | + protected override void ProcessRecord() |
| 26 | + { |
| 27 | + if (ParameterSetName == "Defaults") |
| 28 | + { |
| 29 | + var id = HandleHttpResponseException(() => Api_19_10.CredentialStores.GetDefaultStoreForResourceTypeByResourcetypeWithHttpMessagesAsync(Default)); |
| 30 | + if (id.Value.HasValue) |
| 31 | + { |
| 32 | + var store = HandleHttpResponseException(() => Api_19_10.CredentialStores.GetByIdWithHttpMessagesAsync(id.Value.Value)); |
| 33 | + WriteObject(CredentialStore.FromDto(store)); |
| 34 | + } |
| 35 | + } |
| 36 | + else |
| 37 | + { |
| 38 | + ProcessImpl( |
| 39 | + (filter, top, skip) => HandleHttpResponseException(() => Api_19_10.CredentialStores.GetCredentialStoresWithHttpMessagesAsync(filter: filter, top: top, skip: skip, count: false)), |
| 40 | + id => HandleHttpResponseException(() => Api_19_10.CredentialStores.GetByIdWithHttpMessagesAsync(id)), |
| 41 | + dto => CredentialStore.FromDto(dto)); |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments