Skip to content

Commit 5e62e7d

Browse files
committed
Storage Bucket cmdlets
1 parent 560e149 commit 5e62e7d

19 files changed

+882
-19
lines changed
+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Management.Automation;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using UiPath.PowerShell.Models;
8+
using UiPath.PowerShell.Util;
9+
using UiPath.Web.Client20204;
10+
using UiPath.Web.Client20204.Models;
11+
12+
namespace UiPath.PowerShell.Cmdlets
13+
{
14+
[Cmdlet(VerbsCommon.Add, Nouns.Bucket)]
15+
public class AddBucket : AuthenticatedCmdlet
16+
{
17+
private const string FileSystemSet = nameof(FileSystemSet);
18+
private const string AmazonSet = nameof(AmazonSet);
19+
private const string AzureSet = nameof(AzureSet);
20+
private const string MinioSet = nameof(MinioSet);
21+
private const string OrchestratorSet = nameof(OrchestratorSet);
22+
23+
[Parameter(Mandatory = true, Position = 1, ParameterSetName = OrchestratorSet)]
24+
[Parameter(Mandatory = true, Position = 1, ParameterSetName = FileSystemSet)]
25+
[Parameter(Mandatory = true, Position = 1, ParameterSetName = AmazonSet)]
26+
[Parameter(Mandatory = true, Position = 1, ParameterSetName = AzureSet)]
27+
[Parameter(Mandatory = true, Position = 1, ParameterSetName = MinioSet)]
28+
public string Name { get; set; }
29+
30+
[Parameter]
31+
public string Description { get; set; }
32+
33+
[Parameter]
34+
public SwitchParameter ReadOnly { get; set; }
35+
36+
[Parameter]
37+
public SwitchParameter AuditReadAccess { get; set; }
38+
39+
[Parameter(Mandatory = true, ParameterSetName = FileSystemSet)]
40+
public SwitchParameter FileSystem { get; set; }
41+
42+
[Parameter(Mandatory = true, ParameterSetName = FileSystemSet)]
43+
public string Path { get; set; }
44+
45+
[Parameter(Mandatory = true, ParameterSetName = AmazonSet)]
46+
public SwitchParameter Aws { get; set; }
47+
48+
[ValidateNotNull]
49+
[Parameter(Mandatory = true, ParameterSetName = AmazonSet)]
50+
public string S3BucketName { get; set; }
51+
52+
[ValidateNotNull]
53+
[Parameter(Mandatory = true, ParameterSetName = AmazonSet)]
54+
public string EndpointRegion { get; set; }
55+
56+
[ValidateNotNull]
57+
[Parameter(Mandatory = true, ParameterSetName = AmazonSet)]
58+
[Parameter(Mandatory = true, ParameterSetName = MinioSet)]
59+
public string AccessKey { get; set; }
60+
61+
[ValidateNotNull]
62+
[Parameter(Mandatory = true, ParameterSetName = AmazonSet)]
63+
[Parameter(Mandatory = true, ParameterSetName = MinioSet)]
64+
public string SecretKey { get; set; }
65+
66+
[Parameter(Mandatory = true, ParameterSetName = AzureSet)]
67+
public SwitchParameter Azure { get; set; }
68+
69+
[Parameter(Mandatory = true, ParameterSetName = AzureSet)]
70+
[Parameter(Mandatory = true, ParameterSetName = MinioSet)]
71+
public string ContainerName { get; set; }
72+
73+
[Parameter(Mandatory = true, ParameterSetName = AzureSet)]
74+
public string AccountName { get; set; }
75+
76+
[Parameter(Mandatory = true, ParameterSetName = AzureSet)]
77+
public string AccountKey { get; set; }
78+
79+
[Parameter(Mandatory = true, ParameterSetName = AzureSet)]
80+
public string EndpointSuffix { get; set; }
81+
82+
[Parameter(Mandatory = true, ParameterSetName = MinioSet)]
83+
public SwitchParameter MinIO { get; set; }
84+
85+
[Parameter(Mandatory = true, ParameterSetName = MinioSet)]
86+
public string Server { get; set; }
87+
88+
[Parameter(ParameterSetName = AzureSet)]
89+
[Parameter(ParameterSetName = AmazonSet)]
90+
[Parameter(ParameterSetName = MinioSet)]
91+
public CredentialStore CredentialStore { get; set; }
92+
93+
protected override void ProcessRecord()
94+
{
95+
var dto = new BucketDto
96+
{
97+
Name = Name,
98+
Description = Description,
99+
Options = BucketDtoOptions.None,
100+
Identifier = Guid.NewGuid(),
101+
};
102+
103+
if (ReadOnly.IsPresent)
104+
{
105+
dto.Options |= BucketDtoOptions.ReadOnly;
106+
}
107+
108+
if (AuditReadAccess.IsPresent)
109+
{
110+
dto.Options |= BucketDtoOptions.AuditReadAccess;
111+
}
112+
113+
switch(ParameterSetName)
114+
{
115+
case FileSystemSet:
116+
dto.StorageProvider = "FileSystem";
117+
dto.StorageParameters = $"RootPath={Path}";
118+
break;
119+
case AmazonSet:
120+
dto.StorageProvider = "Amazon";
121+
dto.Password = SecretKey;
122+
dto.StorageContainer = S3BucketName;
123+
dto.StorageParameters = $"EndpointRegion={EndpointRegion};accessKey={AccessKey};secretKey=$Password";
124+
dto.CredentialStoreId = CredentialStore?.Id ?? this.GetDefaultCredentialStore(CredentialStoreResourceDtoType.BucketCredential.ToString());
125+
break;
126+
case AzureSet:
127+
dto.StorageProvider = "Azure";
128+
dto.Password = AccountKey;
129+
dto.StorageContainer = ContainerName;
130+
dto.StorageParameters = $"EndpointSuffix={EndpointSuffix};AccountName={AccountName};AccountKey=$Password";
131+
dto.CredentialStoreId = CredentialStore?.Id ?? this.GetDefaultCredentialStore(CredentialStoreResourceDtoType.BucketCredential.ToString());
132+
break;
133+
case MinioSet:
134+
dto.StorageProvider = "Minio";
135+
dto.Password = SecretKey;
136+
dto.StorageContainer = ContainerName;
137+
dto.StorageParameters = $"host={Server};accessKey={AccessKey};secretKey=$Password";
138+
dto.CredentialStoreId = CredentialStore?.Id ?? this.GetDefaultCredentialStore(CredentialStoreResourceDtoType.BucketCredential.ToString());
139+
break;
140+
}
141+
142+
dto = Api_20_4.Buckets.Post(dto);
143+
WriteObject(dto);
144+
}
145+
}
146+
}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Management.Automation;
2+
using UiPath.PowerShell.Models;
3+
using UiPath.PowerShell.Util;
4+
using UiPath.Web.Client20204;
5+
using UiPath.Web.Client20204.Models;
6+
7+
namespace UiPath.PowerShell.Cmdlets
8+
{
9+
[Cmdlet(VerbsData.Edit, Nouns.Bucket)]
10+
public class EditBucket : AuthenticatedCmdlet
11+
{
12+
internal const string IdSet = nameof(IdSet);
13+
internal const string BucketSet = nameof(BucketSet);
14+
15+
[Parameter(Mandatory = true, ParameterSetName = IdSet)]
16+
public long Id { get; set; }
17+
18+
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = BucketSet)]
19+
public Bucket Bucket { get; set; }
20+
21+
[SetParameter]
22+
[Parameter]
23+
public string Description { get; set; }
24+
25+
[SetParameter(DtoProperty = nameof(BucketDto.Options))]
26+
[Parameter]
27+
public SwitchParameter ReadOnly { get; set; }
28+
29+
[SetParameter(DtoProperty = nameof(BucketDto.Options))]
30+
[Parameter]
31+
public SwitchParameter AuditReadAccess { get; set; }
32+
33+
protected override void ProcessRecord()
34+
{
35+
var dto = HandleHttpOperationException(() => Api_20_4.Buckets.GetById(Bucket?.Id ?? Id));
36+
37+
bool anyChange;
38+
(dto, anyChange) = this.ApplySetParameters(dto);
39+
40+
if (anyChange)
41+
{
42+
dto = HandleHttpOperationException(() => Api_20_4.Buckets.PutById(dto.Id.Value, dto));
43+
WriteObject(dto);
44+
}
45+
}
46+
}
47+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Management.Automation;
2+
using UiPath.PowerShell.Models;
3+
using UiPath.PowerShell.Util;
4+
using UiPath.Web.Client20204;
5+
6+
namespace UiPath.PowerShell.Cmdlets
7+
{
8+
[Cmdlet(VerbsCommon.Get, Nouns.Bucket)]
9+
public class GetBucket : FilteredIdCmdlet
10+
{
11+
[Filter]
12+
[Parameter(ParameterSetName = "Filter")]
13+
public string Name { get; set; }
14+
15+
[Filter]
16+
[Parameter(ParameterSetName = "Filter")]
17+
public string StorageProvider { get; set; }
18+
19+
protected override void ProcessRecord()
20+
{
21+
ProcessImpl(
22+
(filter, top, skip) => Api_20_4.Buckets.Get(filter: filter, top: top, skip: skip, count: false),
23+
id => Api_20_4.Buckets.GetById(id),
24+
dto => Bucket.FromDto(dto));
25+
}
26+
}
27+
}

UiPath.PowerShell/Cmdlets/GetCredentialStore.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ protected override void ProcessRecord()
2626
{
2727
if (ParameterSetName == "Defaults")
2828
{
29-
var id = HandleHttpResponseException(() => Api_19_10.CredentialStores.GetDefaultStoreForResourceTypeByResourcetypeWithHttpMessagesAsync(Default));
30-
if (id.Value.HasValue)
29+
var id = this.GetDefaultCredentialStore(Default);
30+
if (id.HasValue)
3131
{
32-
var store = HandleHttpResponseException(() => Api_19_10.CredentialStores.GetByIdWithHttpMessagesAsync(id.Value.Value));
32+
var store = HandleHttpResponseException(() => Api_19_10.CredentialStores.GetByIdWithHttpMessagesAsync(id.Value));
3333
WriteObject(CredentialStore.FromDto(store));
3434
}
3535
}

UiPath.PowerShell/Cmdlets/Nouns.cs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ internal static class Nouns
77
internal const string Asset = UiPath + "Asset";
88
internal const string AssetRobotValue = UiPath + "AssetRobotValue";
99
internal const string AuthToken = UiPath + "AuthToken";
10+
internal const string Bucket = UiPath + "StorageBucket";
1011
internal const string CredentialStore = UiPath + "CredentialStore";
1112
internal const string Environment = UiPath + "Environment";
1213
internal const string EnvironmentRobot = UiPath + "EnvironmentRobot";
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Management.Automation;
2+
using UiPath.PowerShell.Models;
3+
using UiPath.PowerShell.Util;
4+
using UiPath.Web.Client20204;
5+
6+
namespace UiPath.PowerShell.Cmdlets
7+
{
8+
[Cmdlet(VerbsCommon.Remove, Nouns.Bucket)]
9+
public class RemoveBucket : AuthenticatedCmdlet
10+
{
11+
[ValidateNotNull]
12+
[Parameter(Mandatory = true, Position = 0, ParameterSetName = "Id")]
13+
public long? Id { get; set; }
14+
15+
[ValidateNotNull]
16+
[Parameter(Mandatory = true, Position = 0, ParameterSetName = "Bucket", ValueFromPipeline = true)]
17+
public Bucket Bucket { get; set; }
18+
19+
protected override void ProcessRecord()
20+
{
21+
HandleHttpOperationException(() => Api_20_4.Buckets.DeleteById(Bucket?.Id ?? Id.Value));
22+
}
23+
}
24+
}

UiPath.PowerShell/Models/Bucket.cs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using UiPath.PowerShell.Util;
8+
using UiPath.Web.Client20204.Models;
9+
10+
namespace UiPath.PowerShell.Models
11+
{
12+
[Flags]
13+
public enum BucketOptions
14+
{
15+
None,
16+
ReadOnly,
17+
AuditReadAccess,
18+
}
19+
20+
[TypeConverter(typeof(UiPathTypeConverter))]
21+
22+
public class Bucket
23+
{
24+
public long Id { get; private set; }
25+
public string Name { get; private set; }
26+
public string Description { get; private set; }
27+
public string StorageProvider { get; private set; }
28+
public Guid Identifier { get; private set; }
29+
public BucketOptions Options { get; private set; }
30+
public string StorageContainer { get; private set; }
31+
public string StorageParameters { get; private set; }
32+
public long? CredentialStoreId { get; private set; }
33+
34+
public static Bucket FromDto(BucketDto dto) =>
35+
new Bucket
36+
{
37+
Id = dto.Id.Value,
38+
Name = dto.Name,
39+
Description = dto.Description,
40+
StorageProvider = dto.StorageProvider,
41+
Identifier = dto.Identifier,
42+
Options = (BucketOptions) Enum.Parse(typeof(BucketOptions), dto.Options?.ToString()),
43+
StorageContainer = dto.StorageContainer,
44+
StorageParameters = dto.StorageParameters,
45+
CredentialStoreId = dto.CredentialStoreId,
46+
};
47+
}
48+
}

UiPath.PowerShell/Util/AuthenticatedCmdlet.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected static bool Supports(Version minVersion, AuthToken authToken)
8383
return authToken.ApiVersion >= minVersion;
8484
}
8585

86-
protected UiPathWebApi_18_1 Api
86+
internal UiPathWebApi_18_1 Api
8787
{
8888
get
8989
{
@@ -96,7 +96,7 @@ protected UiPathWebApi_18_1 Api
9696
}
9797
}
9898

99-
protected UiPathWebApi_18_2 Api_18_2
99+
internal UiPathWebApi_18_2 Api_18_2
100100
{
101101
get
102102
{
@@ -109,7 +109,7 @@ protected UiPathWebApi_18_2 Api_18_2
109109
}
110110
}
111111

112-
protected UiPathWebApi_18_3 Api_18_3
112+
internal UiPathWebApi_18_3 Api_18_3
113113
{
114114
get
115115
{
@@ -122,7 +122,7 @@ protected UiPathWebApi_18_3 Api_18_3
122122
}
123123
}
124124

125-
protected UiPathWebApi_18_4 Api_18_4
125+
internal UiPathWebApi_18_4 Api_18_4
126126
{
127127
get
128128
{
@@ -135,7 +135,7 @@ protected UiPathWebApi_18_4 Api_18_4
135135
}
136136
}
137137

138-
protected UiPathWebApi_19_1 Api_19_1
138+
internal UiPathWebApi_19_1 Api_19_1
139139
{
140140
get
141141
{
@@ -148,7 +148,7 @@ protected UiPathWebApi_19_1 Api_19_1
148148
}
149149
}
150150

151-
protected UiPathWebApi_19_4 Api_19_4
151+
internal UiPathWebApi_19_4 Api_19_4
152152
{
153153
get
154154
{
@@ -161,7 +161,7 @@ protected UiPathWebApi_19_4 Api_19_4
161161
}
162162
}
163163

164-
protected UiPathWebApi_19_10 Api_19_10
164+
internal UiPathWebApi_19_10 Api_19_10
165165
{
166166
get
167167
{
@@ -174,7 +174,7 @@ protected UiPathWebApi_19_10 Api_19_10
174174
}
175175
}
176176

177-
protected UiPathWebApi_20_4 Api_20_4
177+
internal UiPathWebApi_20_4 Api_20_4
178178
{
179179
get
180180
{

0 commit comments

Comments
 (0)