Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf0bfba

Browse files
committed
Add support for CredentialType Password/SmartCard
18.4 Orchestrators support Smartcard based login and this adds the required support in the Add-UiPathUser cmdlet.
1 parent 297a992 commit cf0bfba

File tree

4 files changed

+75
-17
lines changed

4 files changed

+75
-17
lines changed

UiPath.PowerShell/Cmdlets/AddRobot.cs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
using UiPath.PowerShell.Util;
55
using UiPath.Web.Client20181;
66
using UiPath.Web.Client20183;
7+
using UiPath.Web.Client20184;
78
using RobotDtoType20181 = UiPath.Web.Client20181.Models.RobotDtoType;
89
using RobotDtoType20183 = UiPath.Web.Client20183.Models.RobotDtoType;
10+
using RobotDtoType20184 = UiPath.Web.Client20184.Models.RobotDtoType;
911
using RobotDtoHostingType20183 = UiPath.Web.Client20183.Models.RobotDtoHostingType;
1012
using RobotDto20181 = UiPath.Web.Client20181.Models.RobotDto;
1113
using RobotDto20183 = UiPath.Web.Client20183.Models.RobotDto;
14+
using RobotDto20184 = UiPath.Web.Client20184.Models.RobotDto;
1215

1316
namespace UiPath.PowerShell.Cmdlets
1417
{
1518
[Cmdlet(VerbsCommon.Add, Nouns.Robot)]
16-
public class AddRobot: AuthenticatedCmdlet
19+
public class AddRobot : AuthenticatedCmdlet
1720
{
1821
[Parameter(Mandatory = true)]
1922
public string Name { get; private set; }
@@ -42,9 +45,17 @@ public class AddRobot: AuthenticatedCmdlet
4245
[Parameter]
4346
public string HostingType { get; set; }
4447

48+
[ValidateEnum(typeof(Web.Client20184.Models.RobotDtoCredentialType))]
49+
[Parameter]
50+
public string CredentialType { get; set; }
51+
4552
protected override void ProcessRecord()
4653
{
47-
if (MyInvocation.BoundParameters.ContainsKey(nameof(HostingType)))
54+
if (MyInvocation.BoundParameters.ContainsKey(nameof(CredentialType)))
55+
{
56+
AddRobot20184();
57+
}
58+
else if (MyInvocation.BoundParameters.ContainsKey(nameof(HostingType)))
4859
{
4960
AddRobot20183();
5061
}
@@ -55,7 +66,7 @@ protected override void ProcessRecord()
5566
}
5667

5768
private void AddRobot20181()
58-
{
69+
{
5970
var robot = new RobotDto20181
6071
{
6172
Name = Name,
@@ -66,11 +77,7 @@ private void AddRobot20181()
6677
Description = Description,
6778
};
6879

69-
RobotDtoType20181 type;
70-
if (Enum.TryParse<RobotDtoType20181>(Type, out type))
71-
{
72-
robot.Type = type;
73-
}
80+
ApplyEnumMember<RobotDtoType20181>(Type, type => robot.Type = type);
7481

7582
var dto = HandleHttpOperationException(() => Api.Robots.Post(robot));
7683
WriteObject(Robot.FromDto(dto));
@@ -85,18 +92,34 @@ private void AddRobot20183()
8592
LicenseKey = LicenseKey,
8693
Username = Username,
8794
Password = Password,
88-
Description = Description,
89-
HostingType = (RobotDtoHostingType20183)Enum.Parse(typeof(RobotDtoHostingType20183), HostingType)
95+
Description = Description
9096
};
9197

92-
RobotDtoType20183 type;
93-
if (Enum.TryParse<RobotDtoType20183>(Type, out type))
94-
{
95-
robot.Type = type;
96-
}
98+
ApplyEnumMember<RobotDtoHostingType20183>(Type, hostingType => robot.HostingType = hostingType);
99+
ApplyEnumMember<RobotDtoType20183>(Type, type => robot.Type = type);
97100

98101
var dto = HandleHttpOperationException(() => Api_18_3.Robots.Post(robot));
99102
WriteObject(Robot.FromDto(dto));
100103
}
104+
105+
private void AddRobot20184()
106+
{
107+
var robot = new RobotDto20184
108+
{
109+
Name = Name,
110+
MachineName = MachineName,
111+
LicenseKey = LicenseKey,
112+
Username = Username,
113+
Password = Password,
114+
Description = Description,
115+
};
116+
117+
ApplyEnumMember<Web.Client20184.Models.RobotDtoCredentialType>(CredentialType, credentialType => robot.CredentialType = credentialType);
118+
ApplyEnumMember<Web.Client20184.Models.RobotDtoHostingType>(HostingType, hostingType => robot.HostingType = hostingType);
119+
ApplyEnumMember<RobotDtoType20184>(Type, type => robot.Type = type);
120+
121+
var dto = HandleHttpOperationException(() => Api_18_4.Robots.Post(robot));
122+
WriteObject(Robot.FromDto(dto));
123+
}
101124
}
102125
}

UiPath.PowerShell/Models/Robot.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using RobotDtoHostingType20183 = UiPath.Web.Client20183.Models.RobotDtoHostingType;
66
using RobotDto20181 = UiPath.Web.Client20181.Models.RobotDto;
77
using RobotDto20183 = UiPath.Web.Client20183.Models.RobotDto;
8+
using RobotDto20184 = UiPath.Web.Client20184.Models.RobotDto;
89

910
namespace UiPath.PowerShell.Models
1011
{
@@ -18,6 +19,7 @@ public class Robot
1819
public string Username { get; private set; }
1920
public string Type { get; private set; }
2021
public string HostingType { get; private set; }
22+
public string CredentialType { get; private set; }
2123

2224
internal static Robot FromDto(RobotDto20181 dto)
2325
{
@@ -87,5 +89,21 @@ internal static object FromDto(RobotDto20183 dto)
8789
HostingType = dto.HostingType.ToString(),
8890
};
8991
}
92+
93+
internal static object FromDto(RobotDto20184 dto)
94+
{
95+
return new Robot
96+
{
97+
Id = dto.Id.Value,
98+
LicenseKey = dto.LicenseKey,
99+
MachineName = dto.MachineName,
100+
Name = dto.Name,
101+
Description = dto.Description,
102+
Username = dto.Username,
103+
Type = dto.Type.ToString(),
104+
HostingType = dto.HostingType.ToString(),
105+
CredentialType = dto.CredentialType.ToString()
106+
};
107+
}
90108
}
91109
}

UiPath.PowerShell/Util/UiPathCmdlet.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,13 @@ protected void WriteError(int? errorCode, string errorMessage)
148148
{
149149
WriteError($"The operation returned an error: {errorCode}: {errorMessage}");
150150
}
151+
152+
internal static void ApplyEnumMember<TEnum>(string stringValue, Action<TEnum> action) where TEnum : struct
153+
{
154+
if (Enum.TryParse<TEnum>(stringValue, out var enumValue))
155+
{
156+
action(enumValue);
157+
}
158+
}
151159
}
152160
}

docs/Add-UiPathRobot.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ SYNOPSIS
77
88
99
SYNTAX
10-
Add-UiPathRobot -Name <string> -Username <string> [-AuthToken <AuthToken>] [-Description <string>] [-HostingType
11-
<string>] [-LicenseKey <string>] [-MachineName <string>] [-Password <string>] [-Type <string>] [<CommonParameters>]
10+
Add-UiPathRobot -Name <string> -Username <string> [-AuthToken <AuthToken>] [-CredentialType <string>]
11+
[-Description <string>] [-HostingType <string>] [-LicenseKey <string>] [-MachineName <string>] [-Password
12+
<string>] [-Type <string>] [<CommonParameters>]
1213
1314
1415
DESCRIPTION
@@ -79,6 +80,14 @@ PARAMETERS
7980
Accept pipeline input? false
8081
Accept wildcard characters? false
8182
83+
-CredentialType <string>
84+
85+
Required? false
86+
Position? named
87+
Default value
88+
Accept pipeline input? false
89+
Accept wildcard characters? false
90+
8291
-AuthToken <AuthToken>
8392
8493
Required? false

0 commit comments

Comments
 (0)