Skip to content

Commit ef3d20b

Browse files
committed
Merge pull request #11 from vivsriaus/dev
Retain auth info (AADOAuth and Basic) when getting/updating jobs
2 parents 177e1c9 + d0f2632 commit ef3d20b

File tree

6 files changed

+111
-38
lines changed

6 files changed

+111
-38
lines changed

src/ServiceManagement/Services/Commands.Utilities/Properties/Resources.Designer.cs

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceManagement/Services/Commands.Utilities/Properties/Resources.resx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,12 @@ use and privacy statement at <url> and (c) agree to sharing my contact inf
16021602
<value>A valid value for ClientCertificatePfx and ClientCertificatePassword parameters are required for Http scheduler jobs with ClientCertificate authentication type.</value>
16031603
</data>
16041604
<data name="SchedulerInvalidNoneAuthRequest" xml:space="preserve">
1605-
<value>For None authentication type, both ClientCertificatePfx and ClientCertificatePassword parameters should be null</value>
1605+
<value>For None authentication type, all authentication related parameters should be null</value>
1606+
</data>
1607+
<data name="SchedulerInvalidAADOAuthRequest" xml:space="preserve">
1608+
<value>A valid value for Tenant, Secret, Audience and Clientid parameters are required for Http scheduler jobs with ActiveDirectoryOAuth authentication type.</value>
1609+
</data>
1610+
<data name="SchedulerInvalidBasicAuthRequest" xml:space="preserve">
1611+
<value>A valid value for Username and Password parameters are required for Http scheduler jobs with Basic authentication type.</value>
16061612
</data>
16071613
</root>

src/ServiceManagement/Services/Commands.Utilities/Scheduler/Model/PSCreateJobParams.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,17 @@ public class PSCreateJobParams
7474
public string ClientCertPfx { get; set; }
7575

7676
public string ClientCertPassword { get; set; }
77+
78+
public string Secret { get; set; }
79+
80+
public string Tenant { get; set; }
81+
82+
public string Audience { get; set; }
83+
84+
public string ClientId { get; set; }
85+
86+
public string Username { get; set; }
87+
88+
public string Password { get; set; }
7789
}
7890
}

src/ServiceManagement/Services/Commands.Utilities/Scheduler/SchedulerMgmntClient.CreateJobs.cs

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -315,29 +315,19 @@ private JobCreateOrUpdateParameters PopulateExistingJobParams(Job job, PSCreateJ
315315
//Job has existing authentication
316316
if (job.Action.Request.Authentication != null)
317317
{
318-
if (jobRequest.HttpAuthType.Equals("ClientCertificate", StringComparison.OrdinalIgnoreCase))
318+
if (!string.IsNullOrEmpty(jobRequest.HttpAuthType))
319319
{
320-
jobUpdateParams.Action.Request.Authentication = SetClientCertAuthentication(jobRequest, jobUpdateParams);
321-
}
322-
else if (jobRequest.HttpAuthType.Equals("None", StringComparison.OrdinalIgnoreCase))
323-
{
324-
if (!string.IsNullOrEmpty(jobRequest.ClientCertPfx) || !string.IsNullOrEmpty(jobRequest.ClientCertPassword))
325-
{
326-
throw new InvalidOperationException(Resources.SchedulerInvalidNoneAuthRequest);
327-
}
328-
else
329-
{
330-
jobUpdateParams.Action.Request.Authentication = null;
331-
}
320+
jobUpdateParams.Action.Request.Authentication = SetHttpAuthentication(jobRequest, jobUpdateParams);
332321
}
322+
//the new request doesn't have any changes to auth, so preserve it
333323
else
334324
{
335325
jobUpdateParams.Action.Request.Authentication = job.Action.Request.Authentication;
336326
}
337327
}
338-
else if (job.Action.Request.Authentication == null && jobRequest.HttpAuthType.Equals("ClientCertificate", StringComparison.OrdinalIgnoreCase))
328+
else if (job.Action.Request.Authentication == null)
339329
{
340-
jobUpdateParams.Action.Request.Authentication = SetClientCertAuthentication(jobRequest, jobUpdateParams);
330+
jobUpdateParams.Action.Request.Authentication = SetHttpAuthentication(jobRequest, jobUpdateParams);
341331
}
342332
}
343333
else if (job.Action.Request == null)
@@ -346,10 +336,7 @@ private JobCreateOrUpdateParameters PopulateExistingJobParams(Job job, PSCreateJ
346336
jobUpdateParams.Action.Request.Method = jobRequest.Method;
347337
jobUpdateParams.Action.Request.Headers = jobRequest.Headers.ToDictionary();
348338
jobUpdateParams.Action.Request.Body = jobRequest.Body;
349-
if (jobRequest.HttpAuthType.Equals("ClientCertificate", StringComparison.OrdinalIgnoreCase))
350-
{
351-
jobUpdateParams.Action.Request.Authentication = SetClientCertAuthentication(jobRequest, jobUpdateParams);
352-
}
339+
jobUpdateParams.Action.Request.Authentication = SetHttpAuthentication(jobRequest, jobUpdateParams);
353340
}
354341
}
355342
else
@@ -358,10 +345,7 @@ private JobCreateOrUpdateParameters PopulateExistingJobParams(Job job, PSCreateJ
358345
jobUpdateParams.Action.Request.Method = jobRequest.Method;
359346
jobUpdateParams.Action.Request.Headers = jobRequest.Headers.ToDictionary();
360347
jobUpdateParams.Action.Request.Body = jobRequest.Body;
361-
if (jobRequest.HttpAuthType.Equals("ClientCertificate", StringComparison.OrdinalIgnoreCase))
362-
{
363-
jobUpdateParams.Action.Request.Authentication = SetClientCertAuthentication(jobRequest, jobUpdateParams);
364-
}
348+
jobUpdateParams.Action.Request.Authentication = SetHttpAuthentication(jobRequest, jobUpdateParams);
365349
}
366350
}
367351
else
@@ -460,21 +444,74 @@ private JobCreateOrUpdateParameters PopulateExistingJobParams(Job job, PSCreateJ
460444
return jobUpdateParams;
461445
}
462446

463-
private HttpAuthentication SetClientCertAuthentication(PSCreateJobParams jobRequest, JobCreateOrUpdateParameters jobUpdateParams)
447+
private HttpAuthentication SetHttpAuthentication(PSCreateJobParams jobRequest, JobCreateOrUpdateParameters jobUpdateParams)
464448
{
465-
if (jobRequest.ClientCertPfx != null && jobRequest.ClientCertPassword != null)
449+
HttpAuthentication httpAuthentication = null;
450+
if (!string.IsNullOrEmpty(jobRequest.HttpAuthType))
466451
{
467-
return new ClientCertAuthentication
452+
switch (jobRequest.HttpAuthType.ToLower())
468453
{
469-
Type = HttpAuthenticationType.ClientCertificate,
470-
Password = jobRequest.ClientCertPassword,
471-
Pfx = jobRequest.ClientCertPfx
472-
};
473-
}
474-
else
475-
{
476-
throw new InvalidOperationException(Resources.SchedulerInvalidClientCertAuthRequest);
454+
case "clientcertificate":
455+
if (jobRequest.ClientCertPfx != null && jobRequest.ClientCertPassword != null)
456+
{
457+
httpAuthentication = new ClientCertAuthentication
458+
{
459+
Type = HttpAuthenticationType.ClientCertificate,
460+
Password = jobRequest.ClientCertPassword,
461+
Pfx = jobRequest.ClientCertPfx
462+
};
463+
}
464+
else
465+
{
466+
throw new InvalidOperationException(Resources.SchedulerInvalidClientCertAuthRequest);
467+
}
468+
break;
469+
470+
case "activedirectoryoauth":
471+
if (jobRequest.Tenant != null && jobRequest.Audience != null && jobRequest.ClientId != null && jobRequest.Secret != null)
472+
{
473+
httpAuthentication = new AADOAuthAuthentication
474+
{
475+
Type = HttpAuthenticationType.ActiveDirectoryOAuth,
476+
Tenant = jobRequest.Tenant,
477+
Audience = jobRequest.Audience,
478+
ClientId = jobRequest.ClientId,
479+
Secret = jobRequest.Secret
480+
};
481+
}
482+
else
483+
{
484+
throw new InvalidOperationException(Resources.SchedulerInvalidAADOAuthRequest);
485+
}
486+
break;
487+
488+
case "basic":
489+
if (jobRequest.Username != null && jobRequest.Password != null)
490+
{
491+
httpAuthentication = new BasicAuthentication
492+
{
493+
Type = HttpAuthenticationType.Basic,
494+
Username = jobRequest.Username,
495+
Password = jobRequest.Password
496+
};
497+
}
498+
else
499+
{
500+
throw new InvalidOperationException(Resources.SchedulerInvalidBasicAuthRequest);
501+
}
502+
break;
503+
504+
case "none":
505+
if (!string.IsNullOrEmpty(jobRequest.ClientCertPfx) || !string.IsNullOrEmpty(jobRequest.ClientCertPassword) ||
506+
!string.IsNullOrEmpty(jobRequest.Tenant) || !string.IsNullOrEmpty(jobRequest.Secret) || !string.IsNullOrEmpty(jobRequest.ClientId) || !string.IsNullOrEmpty(jobRequest.Audience) ||
507+
!string.IsNullOrEmpty(jobRequest.Username) || !string.IsNullOrEmpty(jobRequest.Password))
508+
{
509+
throw new InvalidOperationException(Resources.SchedulerInvalidNoneAuthRequest);
510+
}
511+
break;
512+
}
477513
}
514+
return httpAuthentication;
478515
}
479516

480517
/// <summary>

src/ServiceManagement/Services/Commands/Scheduler/NewSchedulerHttpJobCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public class NewSchedulerHttpJobCommand : SchedulerBaseCmdlet
120120

121121
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = AuthParamSet, HelpMessage = "The Http Authentication type (None or ClientCertificate).")]
122122
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = RequiredParamSet, HelpMessage = "The Http Authentication type (None or ClientCertificate).")]
123-
[ValidateSet("None", "ClientCertificate", IgnoreCase = true)]
123+
[ValidateSet("None", "ClientCertificate", "ActiveDirectoryOAuth", "Basic", IgnoreCase = true)]
124124
public string HttpAuthenticationType { get; set; }
125125

126126
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = AuthParamSet, HelpMessage = "The pfx of client certificate.")]

src/ServiceManagement/Services/Commands/Scheduler/SetSchedulerHttpJobCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public class SetSchedulerHttpJobCommand : SchedulerBaseCmdlet
119119

120120
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = AuthParamSet, HelpMessage = "The Http Authentication type (None or ClientCertificate).")]
121121
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = RequiredParamSet, HelpMessage = "The Http Authentication type (None or ClientCertificate).")]
122-
[ValidateSet("None", "ClientCertificate", IgnoreCase = true)]
122+
[ValidateSet("None", "ClientCertificate", "ActiveDirectoryOAuth", "Basic", IgnoreCase = true)]
123123
public string HttpAuthenticationType { get; set; }
124124

125125
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = AuthParamSet, HelpMessage = "The pfx of client certificate.")]

0 commit comments

Comments
 (0)