Skip to content

Commit be01aa5

Browse files
author
jasper-schneider
committed
Add Batch cert cmdlets
1 parent 80e9e91 commit be01aa5

17 files changed

+1182
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Batch.Models;
16+
using System.Management.Automation;
17+
using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants;
18+
19+
namespace Microsoft.Azure.Commands.Batch
20+
{
21+
[Cmdlet(VerbsCommon.Get, Constants.AzureBatchCertificate, DefaultParameterSetName = Constants.ODataFilterParameterSet),
22+
OutputType(typeof(PSCertificate))]
23+
public class GetBatchCertificateCommand : BatchObjectModelCmdletBase
24+
{
25+
internal const string ThumbprintParameterSet = "Thumbprint";
26+
private int maxCount = Constants.DefaultMaxCount;
27+
28+
[Parameter(Position = 0, ParameterSetName = ThumbprintParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true,
29+
HelpMessage = "The algorithm used to derive the Thumbprint parameter. This must be sha1.")]
30+
[ValidateNotNullOrEmpty]
31+
public string ThumbprintAlgorithm { get; set; }
32+
33+
[Parameter(Position = 1, ParameterSetName = ThumbprintParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true,
34+
HelpMessage = "The thumbprint of the certificate to get.")]
35+
[ValidateNotNullOrEmpty]
36+
public string Thumbprint { get; set; }
37+
38+
[Parameter(ParameterSetName = Constants.ODataFilterParameterSet)]
39+
[ValidateNotNullOrEmpty]
40+
public string Filter { get; set; }
41+
42+
[Parameter(ParameterSetName = Constants.ODataFilterParameterSet)]
43+
public int MaxCount
44+
{
45+
get { return this.maxCount; }
46+
set { this.maxCount = value; }
47+
}
48+
49+
[Parameter]
50+
[ValidateNotNullOrEmpty]
51+
public string Select { get; set; }
52+
53+
protected override void ProcessRecord()
54+
{
55+
ListCertificateOptions options = new ListCertificateOptions(this.BatchContext, this.AdditionalBehaviors)
56+
{
57+
ThumbprintAlgorithm = this.ThumbprintAlgorithm,
58+
Thumbprint = this.Thumbprint,
59+
Filter = this.Filter,
60+
Select = this.Select,
61+
MaxCount = this.MaxCount
62+
};
63+
64+
// The enumerator will internally query the service in chunks. Using WriteObject with the enumerate flag will enumerate
65+
// the entire collection first and then write the items out one by one in a single group. Using foreach, we can take
66+
// advantage of the enumerator's behavior and write output to the pipeline in bursts.
67+
foreach (PSCertificate certificate in BatchClient.ListCertificates(options))
68+
{
69+
WriteObject(certificate);
70+
}
71+
}
72+
}
73+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Batch.Models;
16+
using System.Management.Automation;
17+
using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants;
18+
19+
namespace Microsoft.Azure.Commands.Batch
20+
{
21+
[Cmdlet(VerbsCommon.New, Constants.AzureBatchCertificate, DefaultParameterSetName = FileParameterSet)]
22+
public class NewBatchCertificateCommand : BatchObjectModelCmdletBase
23+
{
24+
internal const string FileParameterSet = "File";
25+
internal const string RawDataParameterSet = "RawData";
26+
27+
[Parameter(Position = 0, ParameterSetName = FileParameterSet, Mandatory = true,
28+
HelpMessage = "The path to the certificate file. The certificate must be in either .cer or .pfx format.")]
29+
[ValidateNotNullOrEmpty]
30+
public string FilePath { get; set; }
31+
32+
[Parameter(Position = 0, ParameterSetName = RawDataParameterSet, Mandatory = true, ValueFromPipeline = true,
33+
ValueFromPipelineByPropertyName = true, HelpMessage = "The raw certificate data in either .cer or .pfx format.")]
34+
[ValidateNotNullOrEmpty]
35+
public byte[] RawData { get; set; }
36+
37+
[Parameter]
38+
[ValidateNotNullOrEmpty]
39+
public string Password { get; set; }
40+
41+
protected override void ProcessRecord()
42+
{
43+
NewCertificateParameters parameters = new NewCertificateParameters(this.BatchContext, this.FilePath, this.RawData,
44+
this.AdditionalBehaviors)
45+
{
46+
Password = this.Password
47+
};
48+
49+
BatchClient.AddCertificate(parameters);
50+
}
51+
}
52+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Batch.Models;
16+
using System.Management.Automation;
17+
using Microsoft.Azure.Commands.Batch.Properties;
18+
using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants;
19+
20+
namespace Microsoft.Azure.Commands.Batch
21+
{
22+
[Cmdlet(VerbsCommon.Remove, Constants.AzureBatchCertificate)]
23+
public class RemoveBatchCertificateCommand : BatchObjectModelCmdletBase
24+
{
25+
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true,
26+
HelpMessage = "The algorithm used to derive the Thumbprint parameter. This must be sha1.")]
27+
[ValidateNotNullOrEmpty]
28+
public string ThumbprintAlgorithm { get; set; }
29+
30+
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true,
31+
HelpMessage = "The thumbprint of the certificate to delete.")]
32+
[ValidateNotNullOrEmpty]
33+
public string Thumbprint { get; set; }
34+
35+
[Parameter]
36+
public SwitchParameter Force { get; set; }
37+
38+
protected override void ProcessRecord()
39+
{
40+
CertificateOperationParameters parameters = new CertificateOperationParameters(this.BatchContext,
41+
this.ThumbprintAlgorithm, this.Thumbprint, this.AdditionalBehaviors);
42+
43+
ConfirmAction(
44+
Force.IsPresent,
45+
string.Format(Resources.RemoveCertificateConfirm, this.Thumbprint),
46+
Resources.RemoveCertificate,
47+
this.Thumbprint,
48+
() => BatchClient.DeleteCertificate(parameters));
49+
}
50+
}
51+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Batch.Models;
16+
using System.Management.Automation;
17+
using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants;
18+
19+
namespace Microsoft.Azure.Commands.Batch
20+
{
21+
[Cmdlet(VerbsLifecycle.Stop, Constants.AzureBatchCertificateDeletion)]
22+
public class StopBatchCertificateDeletionCommand : BatchObjectModelCmdletBase
23+
{
24+
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true,
25+
HelpMessage = "The algorithm used to derive the Thumbprint parameter. This must be sha1.")]
26+
[ValidateNotNullOrEmpty]
27+
public string ThumbprintAlgorithm { get; set; }
28+
29+
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true,
30+
HelpMessage = "The thumbprint of the certificate that failed to delete.")]
31+
[ValidateNotNullOrEmpty]
32+
public string Thumbprint { get; set; }
33+
34+
protected override void ProcessRecord()
35+
{
36+
CertificateOperationParameters parameters = new CertificateOperationParameters(this.BatchContext,
37+
this.ThumbprintAlgorithm, this.Thumbprint, this.AdditionalBehaviors);
38+
39+
BatchClient.CancelDeleteCertificate(parameters);
40+
}
41+
}
42+
}

src/ResourceManager/AzureBatch/Commands.Batch/Commands.Batch.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@
154154
<Compile Include="Accounts\NewBatchAccountCommand.cs" />
155155
<Compile Include="Accounts\NewBatchAccountKeyCommand.cs" />
156156
<Compile Include="Accounts\SetBatchAccountCommand.cs" />
157+
<Compile Include="Certificates\GetBatchCertificateCommand.cs" />
158+
<Compile Include="Certificates\RemoveBatchCertificateCommand.cs" />
159+
<Compile Include="Certificates\NewBatchCertificateCommand.cs" />
160+
<Compile Include="Certificates\StopBatchCertificateDeletionCommand.cs" />
157161
<Compile Include="ComputeNodes\ResetBatchComputeNodeCommand.cs" />
158162
<Compile Include="ComputeNodes\RestartBatchComputeNodeCommand.cs" />
159163
<Compile Include="ComputeNodeUsers\SetBatchComputeNodeUserCommand.cs" />
@@ -171,14 +175,19 @@
171175
<Compile Include="Jobs\SetBatchJobCommand.cs" />
172176
<Compile Include="Jobs\StopBatchJobCommand.cs" />
173177
<Compile Include="Models.Generated\PSAutoScaleEvaluation.cs" />
178+
<Compile Include="Models.Generated\PSCertificate.cs" />
174179
<Compile Include="Models.Generated\PSCloudJobSchedule.cs" />
175180
<Compile Include="Models.Generated\PSComputeNode.cs" />
176181
<Compile Include="Models.Generated\PSComputeNodeError.cs" />
177182
<Compile Include="Models.Generated\PSComputeNodeInformation.cs" />
178183
<Compile Include="Models.Generated\PSComputeNodeUser.cs" />
184+
<Compile Include="Models.Generated\PSDeleteCertificateError.cs" />
179185
<Compile Include="Models.Generated\PSJobManagerTask.cs" />
186+
<Compile Include="Models.Generated\PSJobPreparationAndReleaseTaskExecutionInformation.cs" />
180187
<Compile Include="Models.Generated\PSJobPreparationTask.cs" />
188+
<Compile Include="Models.Generated\PSJobPreparationTaskExecutionInformation.cs" />
181189
<Compile Include="Models.Generated\PSJobReleaseTask.cs" />
190+
<Compile Include="Models.Generated\PSJobReleaseTaskExecutionInformation.cs" />
182191
<Compile Include="Models.Generated\PSJobScheduleExecutionInformation.cs" />
183192
<Compile Include="Models.Generated\PSJobScheduleStatistics.cs" />
184193
<Compile Include="Models.Generated\PSNodeFile.cs" />
@@ -188,6 +197,7 @@
188197
<Compile Include="Models.Generated\PSTaskSchedulingPolicy.cs" />
189198
<Compile Include="Models\AutoScaleParameters.cs" />
190199
<Compile Include="Models\BatchClient.Accounts.cs" />
200+
<Compile Include="Models\BatchClient.Certificates.cs" />
191201
<Compile Include="Models\BatchClient.cs" />
192202
<Compile Include="BatchCmdletBase.cs" />
193203
<Compile Include="BatchObjectModelCmdletBase.cs" />
@@ -201,17 +211,20 @@
201211
<Compile Include="Models\BatchClient.ComputeNodes.cs" />
202212
<Compile Include="Models\BatchClient.JobSchedules.cs" />
203213
<Compile Include="Models\BatchClientParametersBase.cs" />
214+
<Compile Include="Models\CertificateOperationParameters.cs" />
204215
<Compile Include="Models\ChangeOSVersionParameters.cs" />
205216
<Compile Include="Models\DisableJobParameters.cs" />
206217
<Compile Include="Models\DownloadNodeFileOptions.cs" />
207218
<Compile Include="Models\DownloadRemoteDesktopProtocolFileOptions.cs" />
208219
<Compile Include="Models\JobOperationParameters.cs" />
220+
<Compile Include="Models\ListCertificateOptions.cs" />
209221
<Compile Include="Models\ListJobOptions.cs" />
210222
<Compile Include="Models\ListNodeFileOptions.cs" />
211223
<Compile Include="Models\ListPoolOptions.cs" />
212224
<Compile Include="Models\ListTaskOptions.cs" />
213225
<Compile Include="Models\ListComputeNodeOptions.cs" />
214226
<Compile Include="Models\ListJobScheduleOptions.cs" />
227+
<Compile Include="Models\NewCertificateParameters.cs" />
215228
<Compile Include="Models\NewJobParameters.cs" />
216229
<Compile Include="Models\NewPoolParameters.cs" />
217230
<Compile Include="Models\NewTaskParameters.cs" />
@@ -326,6 +339,7 @@
326339
<Name>Commands.ResourceManager.Common</Name>
327340
</ProjectReference>
328341
</ItemGroup>
342+
<ItemGroup />
329343
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
330344
<Import Project="..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
331345
</Project>

0 commit comments

Comments
 (0)