Skip to content

Commit 31f4dc6

Browse files
author
jasper-schneider
committed
Batch cert cmdlet updates
Incorporate code review comments.
1 parent 61ee3ff commit 31f4dc6

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchClient.Certificates.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,26 @@ public IEnumerable<PSCertificate> ListCertificates(ListCertificateOptions option
3535
throw new ArgumentNullException("options");
3636
}
3737

38-
ODATADetailLevel odata = new ODATADetailLevel(selectClause: options.Select);
39-
4038
// Get the single certificate matching the specified thumbprint
4139
if (!string.IsNullOrWhiteSpace(options.Thumbprint))
4240
{
4341
WriteVerbose(string.Format(Resources.GetCertificateByThumbprint, options.Thumbprint));
4442
CertificateOperations certOperations = options.Context.BatchOMClient.CertificateOperations;
45-
Certificate certificate = certOperations.GetCertificate(options.ThumbprintAlgorithm, options.Thumbprint,
46-
detailLevel: odata, additionalBehaviors: options.AdditionalBehaviors);
43+
ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select);
44+
Certificate certificate = certOperations.GetCertificate(options.ThumbprintAlgorithm, options.Thumbprint,
45+
detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors);
4746
PSCertificate psCertificate = new PSCertificate(certificate);
4847
return new PSCertificate[] { psCertificate };
4948
}
5049
// List certificates using the specified filter
5150
else
5251
{
5352
string verboseLogString = null;
53+
ODATADetailLevel listDetailLevel = new ODATADetailLevel(selectClause: options.Select);
5454
if (!string.IsNullOrEmpty(options.Filter))
5555
{
5656
verboseLogString = Resources.GetCertificatesByFilter;
57-
odata.FilterClause = options.Filter;
57+
listDetailLevel.FilterClause = options.Filter;
5858
}
5959
else
6060
{
@@ -63,7 +63,7 @@ public IEnumerable<PSCertificate> ListCertificates(ListCertificateOptions option
6363
WriteVerbose(verboseLogString);
6464

6565
CertificateOperations certOperations = options.Context.BatchOMClient.CertificateOperations;
66-
IPagedEnumerable<Certificate> certificates = certOperations.ListCertificates(odata, options.AdditionalBehaviors);
66+
IPagedEnumerable<Certificate> certificates = certOperations.ListCertificates(listDetailLevel, options.AdditionalBehaviors);
6767
Func<Certificate, PSCertificate> mappingFunction = c => { return new PSCertificate(c); };
6868
return PSPagedEnumerable<PSCertificate, Certificate>.CreateWithMaxCount(
6969
certificates, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)));
@@ -82,7 +82,7 @@ public void AddCertificate(NewCertificateParameters parameters)
8282
}
8383

8484
CertificateOperations certOperations = parameters.Context.BatchOMClient.CertificateOperations;
85-
Certificate unboundCert = null;
85+
Certificate unboundCert;
8686

8787
if (!string.IsNullOrWhiteSpace(parameters.FilePath))
8888
{

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchClient.ComputeNodes.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@ public IEnumerable<PSComputeNode> ListComputeNodes(ListComputeNodeOptions option
3535
throw new ArgumentNullException("options");
3636
}
3737

38-
ODATADetailLevel odata = new ODATADetailLevel(selectClause: options.Select);
39-
4038
string poolId = options.Pool == null ? options.PoolId : options.Pool.Id;
4139

4240
// Get the single compute node matching the specified id
4341
if (!string.IsNullOrEmpty(options.ComputeNodeId))
4442
{
4543
WriteVerbose(string.Format(Resources.GetComputeNodeById, options.ComputeNodeId, poolId));
4644
PoolOperations poolOperations = options.Context.BatchOMClient.PoolOperations;
47-
ComputeNode computeNode = poolOperations.GetComputeNode(poolId, options.ComputeNodeId, detailLevel: odata, additionalBehaviors: options.AdditionalBehaviors);
45+
ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select);
46+
ComputeNode computeNode = poolOperations.GetComputeNode(poolId, options.ComputeNodeId, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors);
4847
PSComputeNode psComputeNode = new PSComputeNode(computeNode);
4948
return new PSComputeNode[] { psComputeNode };
5049
}
5150
// List compute nodes using the specified filter
5251
else
5352
{
5453
string verboseLogString = null;
54+
ODATADetailLevel listDetailLevel = new ODATADetailLevel(selectClause: options.Select);
5555
if (!string.IsNullOrEmpty(options.Filter))
5656
{
5757
verboseLogString = string.Format(Resources.GetComputeNodeByOData, poolId);
58-
odata.FilterClause = options.Filter;
58+
listDetailLevel.FilterClause = options.Filter;
5959
}
6060
else
6161
{
@@ -64,7 +64,7 @@ public IEnumerable<PSComputeNode> ListComputeNodes(ListComputeNodeOptions option
6464
WriteVerbose(verboseLogString);
6565

6666
PoolOperations poolOperations = options.Context.BatchOMClient.PoolOperations;
67-
IPagedEnumerable<ComputeNode> computeNodes = poolOperations.ListComputeNodes(poolId, odata, options.AdditionalBehaviors);
67+
IPagedEnumerable<ComputeNode> computeNodes = poolOperations.ListComputeNodes(poolId, listDetailLevel, options.AdditionalBehaviors);
6868
Func<ComputeNode, PSComputeNode> mappingFunction = c => { return new PSComputeNode(c); };
6969
return PSPagedEnumerable<PSComputeNode, ComputeNode>.CreateWithMaxCount(
7070
computeNodes, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)));

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchClient.JobSchedules.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@ public IEnumerable<PSCloudJobSchedule> ListJobSchedules(ListJobScheduleOptions o
3737
throw new ArgumentNullException("options");
3838
}
3939

40-
ODATADetailLevel odata = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
41-
4240
// Get the single job schedule matching the specified id
4341
if (!string.IsNullOrWhiteSpace(options.JobScheduleId))
4442
{
4543
WriteVerbose(string.Format(Resources.GetJobScheduleById, options.JobScheduleId));
4644
JobScheduleOperations jobScheduleOperations = options.Context.BatchOMClient.JobScheduleOperations;
47-
CloudJobSchedule jobSchedule = jobScheduleOperations.GetJobSchedule(options.JobScheduleId, detailLevel: odata, additionalBehaviors: options.AdditionalBehaviors);
45+
ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
46+
CloudJobSchedule jobSchedule = jobScheduleOperations.GetJobSchedule(options.JobScheduleId, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors);
4847
PSCloudJobSchedule psJobSchedule = new PSCloudJobSchedule(jobSchedule);
4948
return new PSCloudJobSchedule[] { psJobSchedule };
5049
}
5150
// List job schedules using the specified filter
5251
else
5352
{
5453
string verboseLogString = null;
54+
ODATADetailLevel listDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
5555
if (!string.IsNullOrEmpty(options.Filter))
5656
{
5757
verboseLogString = Resources.GetJobScheduleByOData;
58-
odata.FilterClause = options.Filter;
58+
listDetailLevel.FilterClause = options.Filter;
5959
}
6060
else
6161
{
@@ -64,7 +64,7 @@ public IEnumerable<PSCloudJobSchedule> ListJobSchedules(ListJobScheduleOptions o
6464
WriteVerbose(verboseLogString);
6565

6666
JobScheduleOperations jobScheduleOperations = options.Context.BatchOMClient.JobScheduleOperations;
67-
IPagedEnumerable<CloudJobSchedule> workItems = jobScheduleOperations.ListJobSchedules(odata, options.AdditionalBehaviors);
67+
IPagedEnumerable<CloudJobSchedule> workItems = jobScheduleOperations.ListJobSchedules(listDetailLevel, options.AdditionalBehaviors);
6868
Func<CloudJobSchedule, PSCloudJobSchedule> mappingFunction = j => { return new PSCloudJobSchedule(j); };
6969
return PSPagedEnumerable<PSCloudJobSchedule, CloudJobSchedule>.CreateWithMaxCount(
7070
workItems, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)));

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchClient.Jobs.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ public IEnumerable<PSCloudJob> ListJobs(ListJobOptions options)
3636
throw new ArgumentNullException("options");
3737
}
3838

39-
ODATADetailLevel odata = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
40-
4139
// Get the single job matching the specified id
4240
if (!string.IsNullOrEmpty(options.JobId))
4341
{
4442
WriteVerbose(string.Format(Resources.GetJobById, options.JobId));
4543
JobOperations jobOperations = options.Context.BatchOMClient.JobOperations;
46-
CloudJob job = jobOperations.GetJob(options.JobId, detailLevel: odata, additionalBehaviors: options.AdditionalBehaviors);
44+
ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
45+
CloudJob job = jobOperations.GetJob(options.JobId, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors);
4746
PSCloudJob psJob = new PSCloudJob(job);
4847
return new PSCloudJob[] { psJob };
4948
}
@@ -52,12 +51,13 @@ public IEnumerable<PSCloudJob> ListJobs(ListJobOptions options)
5251
{
5352
string jobScheduleId = options.JobSchedule == null ? options.JobScheduleId : options.JobSchedule.Id;
5453
bool filterByJobSchedule = !string.IsNullOrEmpty(jobScheduleId);
54+
ODATADetailLevel listDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
5555

5656
string verboseLogString = null;
5757
if (!string.IsNullOrEmpty(options.Filter))
5858
{
5959
verboseLogString = filterByJobSchedule ? Resources.GetJobByOData : string.Format(Resources.GetJobByODataAndJobSChedule, jobScheduleId);
60-
odata.FilterClause = options.Filter;
60+
listDetailLevel.FilterClause = options.Filter;
6161
}
6262
else
6363
{
@@ -69,12 +69,12 @@ public IEnumerable<PSCloudJob> ListJobs(ListJobOptions options)
6969
if (filterByJobSchedule)
7070
{
7171
JobScheduleOperations jobScheduleOperations = options.Context.BatchOMClient.JobScheduleOperations;
72-
jobs = jobScheduleOperations.ListJobs(jobScheduleId, odata, options.AdditionalBehaviors);
72+
jobs = jobScheduleOperations.ListJobs(jobScheduleId, listDetailLevel, options.AdditionalBehaviors);
7373
}
7474
else
7575
{
7676
JobOperations jobOperations = options.Context.BatchOMClient.JobOperations;
77-
jobs = jobOperations.ListJobs(odata, options.AdditionalBehaviors);
77+
jobs = jobOperations.ListJobs(listDetailLevel, options.AdditionalBehaviors);
7878
}
7979
Func<CloudJob, PSCloudJob> mappingFunction = j => { return new PSCloudJob(j); };
8080
return PSPagedEnumerable<PSCloudJob, CloudJob>.CreateWithMaxCount(

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchClient.Pools.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,25 @@ public IEnumerable<PSCloudPool> ListPools(ListPoolOptions options)
3636
throw new ArgumentNullException("options");
3737
}
3838

39-
ODATADetailLevel odata = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
40-
4139
// Get the single pool matching the specified id
4240
if (!string.IsNullOrWhiteSpace(options.PoolId))
4341
{
4442
WriteVerbose(string.Format(Resources.GetPoolById, options.PoolId));
4543
PoolOperations poolOperations = options.Context.BatchOMClient.PoolOperations;
46-
CloudPool pool = poolOperations.GetPool(options.PoolId, detailLevel: odata, additionalBehaviors: options.AdditionalBehaviors);
44+
ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
45+
CloudPool pool = poolOperations.GetPool(options.PoolId, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors);
4746
PSCloudPool psPool = new PSCloudPool(pool);
4847
return new PSCloudPool[] { psPool };
4948
}
5049
// List pools using the specified filter
5150
else
5251
{
5352
string verboseLogString = null;
53+
ODATADetailLevel listDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
5454
if (!string.IsNullOrEmpty(options.Filter))
5555
{
5656
verboseLogString = Resources.GetPoolByOData;
57-
odata.FilterClause = options.Filter;
57+
listDetailLevel.FilterClause = options.Filter;
5858
}
5959
else
6060
{
@@ -63,7 +63,7 @@ public IEnumerable<PSCloudPool> ListPools(ListPoolOptions options)
6363
WriteVerbose(verboseLogString);
6464

6565
PoolOperations poolOperations = options.Context.BatchOMClient.PoolOperations;
66-
IPagedEnumerable<CloudPool> pools = poolOperations.ListPools(odata, options.AdditionalBehaviors);
66+
IPagedEnumerable<CloudPool> pools = poolOperations.ListPools(listDetailLevel, options.AdditionalBehaviors);
6767
Func<CloudPool, PSCloudPool> mappingFunction = p => { return new PSCloudPool(p); };
6868
return PSPagedEnumerable<PSCloudPool, CloudPool>.CreateWithMaxCount(
6969
pools, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)));

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchClient.Tasks.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ public IEnumerable<PSCloudTask> ListTasks(ListTaskOptions options)
3636
throw new ArgumentNullException("options");
3737
}
3838

39-
ODATADetailLevel odata = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
40-
4139
// Get the single task matching the specified id
4240
if (!string.IsNullOrEmpty(options.TaskId))
4341
{
4442
WriteVerbose(string.Format(Resources.GetTaskById, options.TaskId, options.JobId));
4543
JobOperations jobOperations = options.Context.BatchOMClient.JobOperations;
46-
CloudTask task = jobOperations.GetTask(options.JobId, options.TaskId, detailLevel: odata, additionalBehaviors: options.AdditionalBehaviors);
44+
ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
45+
CloudTask task = jobOperations.GetTask(options.JobId, options.TaskId, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors);
4746
PSCloudTask psTask = new PSCloudTask(task);
4847
return new PSCloudTask[] { psTask };
4948
}
@@ -52,10 +51,11 @@ public IEnumerable<PSCloudTask> ListTasks(ListTaskOptions options)
5251
{
5352
string jobId = options.Job == null ? options.JobId : options.Job.Id;
5453
string verboseLogString = null;
54+
ODATADetailLevel listDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
5555
if (!string.IsNullOrEmpty(options.Filter))
5656
{
5757
verboseLogString = string.Format(Resources.GetTaskByOData, jobId);
58-
odata.FilterClause = options.Filter;
58+
listDetailLevel.FilterClause = options.Filter;
5959
}
6060
else
6161
{
@@ -66,12 +66,12 @@ public IEnumerable<PSCloudTask> ListTasks(ListTaskOptions options)
6666
IPagedEnumerable<CloudTask> tasks = null;
6767
if (options.Job != null)
6868
{
69-
tasks = options.Job.omObject.ListTasks(odata, options.AdditionalBehaviors);
69+
tasks = options.Job.omObject.ListTasks(listDetailLevel, options.AdditionalBehaviors);
7070
}
7171
else
7272
{
7373
JobOperations jobOperations = options.Context.BatchOMClient.JobOperations;
74-
tasks = jobOperations.ListTasks(options.JobId, odata, options.AdditionalBehaviors);
74+
tasks = jobOperations.ListTasks(options.JobId, listDetailLevel, options.AdditionalBehaviors);
7575
}
7676
Func<CloudTask, PSCloudTask> mappingFunction = t => { return new PSCloudTask(t); };
7777
return PSPagedEnumerable<PSCloudTask, CloudTask>.CreateWithMaxCount(

0 commit comments

Comments
 (0)