protected override void ProcessRecord() { if (AuthToken != null) { AuthenticatedCmdlet.SetAuthToken(AuthToken); } }
private void GetServerVersion(AuthToken authToken) { authToken.ApiVersion = OrchestratorProtocolVersion.V18_1; using (var api = AuthenticatedCmdlet.MakeApi(authToken, Timeout)) { try { api.MakeHttpRequest(HttpMethod.Get, "odata/Settings/UiPath.Server.Configuration.OData.GetAuthenticationSettings", null, out var response, out var headers); if (headers.TryGetValues("api-supported-versions", out var values)) { if (Version.TryParse(values.First(), out var version)) { authToken.ApiVersion = version; } } // v18.1 client type system cannot parse the response // var dict = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <Web.Client20182.Models.ResponseDictionaryDto>(response); for (int i = 0; i < dict.Keys.Count; ++i) { if (0 != String.Compare(dict.Keys[i], "Build.Version", true)) { continue; } authToken.BuildVersion = dict.Values[i]; break; } } catch (Exception e) { WriteVerbose($"Error retrieving API version: {e.GetType().Name}: {e.Message}"); } } }
protected override void ProcessRecord() { try { AuthToken authToken = null; if (ParameterSetName == UserPasswordSet) { authToken = GetUserToken(); } else if (ParameterSetName == WindowsCredentialsSet) { authToken = GetWindowsToken(); } else if (ParameterSetName == UnauthenticatedSet) { authToken = GetUnauthenticatedToken(); } GetServerVersion(authToken); if (Session.IsPresent) { AuthenticatedCmdlet.SetAuthToken(authToken); } WriteObject(authToken); } catch(Exception e) { WriteVerbose(e.ToString()); } }
private void SetOrganizationUnit(AuthToken authToken, string organizationUnit) { using (var api = AuthenticatedCmdlet.MakeApi(authToken, Timeout)) { var unit = HandleHttpOperationException(() => api.OrganizationUnits.GetOrganizationUnits(filter: $"DisplayName eq '{organizationUnit}'").Value.First(ou => ou.DisplayName == organizationUnit)); authToken.OrganizationUnit = unit.DisplayName; authToken.OrganizationUnitId = unit.Id.Value; } }
private void GetServerVersion(AuthToken authToken) { using (var api = AuthenticatedCmdlet.MakeApi(authToken)) { api.MakeHttpRequest(HttpMethod.Get, "/odata/$metadata", null, out var response, out var headers); if (headers.TryGetValues("api-supported-versions", out var values)) { authToken.ApiVersion = values.First(); } } }
protected override void ProcessRecord() { if (ParameterSetName == CurrentSessionSet) { WriteObject(AuthenticatedCmdlet.SessionAuthToken); } else { AuthToken authToken = null; if (ParameterSetName == UserPasswordSet) { authToken = GetUserToken(); } else if (ParameterSetName == WindowsCredentialsSet) { authToken = GetWindowsToken(); } else if (ParameterSetName == UnauthenticatedSet) { authToken = GetUnauthenticatedToken(); } GetServerVersion(authToken); if (!String.IsNullOrWhiteSpace(OrganizationUnit)) { SetOrganizationUnit(authToken, OrganizationUnit); } authToken.TenantName = TenantName ?? "Default"; if (Session.IsPresent) { AuthenticatedCmdlet.SetAuthToken(authToken); } if (MyInvocation.BoundParameters.ContainsKey(nameof(RequestTimeout))) { authToken.RequestTimeout = RequestTimeout; } WriteObject(authToken); } }
protected override void ProcessRecord() { if (ParameterSetName == CurrentSessionSet) { WriteObject(AuthenticatedCmdlet.SessionAuthToken); } else { AuthToken authToken = null; if (ParameterSetName == UserPasswordSet) { authToken = GetUserToken(); } else if (ParameterSetName == WindowsCredentialsSet) { authToken = GetWindowsToken(); } else if (ParameterSetName == UnauthenticatedSet) { authToken = GetUnauthenticatedToken(); } else if (ParameterSetName == CloudInteractiveSet || ParameterSetName == CloudCodeSet || ParameterSetName == CloudAPISet) { AuthToken token = null; if (Session.IsPresent) { token = AuthenticatedCmdlet.SessionAuthToken; } token = token ?? new AuthToken(); token.AuthorizationCode = AuthorizationCode; token.AuthorizationVerifier = AuthorizationVerifier; token.TenantName = TenantName; token.AccountName = AccountName; token.Token = null; token.AuthorizationRefreshToken = null; token.AuthorizationTokenId = null; token.AuthorizationUrl = AuthorizationUrl; token.AccountUrl = AccountUrl; token.ApplicationId = ApplicationId; if (ParameterSetName == CloudAPISet) { token.AuthorizationRefreshToken = UserKey; token.ApplicationId = ClientId; } token.CloudDeployment = string.IsNullOrWhiteSpace(CloudDeployment) ? CloudDeployments.Production : (CloudDeployments)Enum.Parse(typeof(CloudDeployments), CloudDeployment); if (ParameterSetName == CloudInteractiveSet) { token = GetInteractiveToken(token); } authToken = token; } GetServerVersion(authToken); if (!string.IsNullOrWhiteSpace(OrganizationUnit)) { if (authToken.ApiVersion >= OrchestratorProtocolVersion.V19_10) { WriteWarning("The use of OrganizationUnit is deprecated and will be removed. Use FolderPath instead."); } SetOrganizationUnit(authToken, OrganizationUnit); } else if (!string.IsNullOrWhiteSpace(FolderPath)) { if (authToken.ApiVersion < OrchestratorProtocolVersion.V19_10) { WriteError("Use of FolderPath requires Orchestrator version 19.10 or newer."); } SetCurrentFolder(authToken, FolderPath, Timeout); } else if (authToken.ApiVersion >= OrchestratorProtocolVersion.V19_10) { WriteVerbose("No FolderPath was specified, using 'Default'"); SetCurrentFolder(authToken, "Default", Timeout); } else { authToken.CurrentFolder = default; authToken.OrganizationUnit = default; authToken.OrganizationUnitId = default; } authToken.TenantName = authToken.TenantName ?? TenantName ?? "Default"; if (Session.IsPresent) { AuthenticatedCmdlet.SetAuthToken(authToken); } if (MyInvocation.BoundParameters.ContainsKey(nameof(RequestTimeout))) { authToken.RequestTimeout = RequestTimeout; } WriteObject(authToken); } }
protected override void ProcessRecord() { if (ParameterSetName == CurrentSessionSet) { WriteObject(AuthenticatedCmdlet.SessionAuthToken); } else { AuthToken authToken = null; if (ParameterSetName == UserPasswordSet) { authToken = GetUserToken(); } else if (ParameterSetName == WindowsCredentialsSet) { authToken = GetWindowsToken(); } else if (ParameterSetName == UnauthenticatedSet) { authToken = GetUnauthenticatedToken(); } else if (ParameterSetName == CloudInteractiveSet || ParameterSetName == CloudCodeSet) { AuthToken token = null; if (Session.IsPresent) { token = AuthenticatedCmdlet.SessionAuthToken; } token = token ?? new AuthToken(); token.AuthorizationCode = AuthorizationCode; token.AuthorizationVerifier = AuthorizationVerifier; token.TenantName = TenantName; token.AccountName = AccountName; token.Token = null; token.AuthorizationRefreshToken = null; token.AuthorizationTokenId = null; token.AuthorizationUrl = AuthorizationUrl; token.AccountUrl = AccountUrl; token.ApplicationId = ApplicationId; token.CloudDeployment = string.IsNullOrWhiteSpace(CloudDeployment) ? CloudDeployments.Production : (CloudDeployments)Enum.Parse(typeof(CloudDeployments), CloudDeployment); if (ParameterSetName == CloudInteractiveSet) { token = GetInteractiveToken(token); } authToken = token; } GetServerVersion(authToken); if (!String.IsNullOrWhiteSpace(OrganizationUnit)) { SetOrganizationUnit(authToken, OrganizationUnit); } authToken.TenantName = authToken.TenantName ?? TenantName ?? "Default"; if (Session.IsPresent) { AuthenticatedCmdlet.SetAuthToken(authToken); } if (MyInvocation.BoundParameters.ContainsKey(nameof(RequestTimeout))) { authToken.RequestTimeout = RequestTimeout; } WriteObject(authToken); } }
protected override void ProcessRecord() { if (ParameterSetName == CurrentSessionSet) { WriteObject(AuthenticatedCmdlet.SessionAuthToken); } else { AuthToken authToken = null; if (Host.IsPresent) { TenantName = "Host"; } if (!string.IsNullOrWhiteSpace(URL)) { var uri = new Uri(URL); if (0 == string.Compare(uri.Host, "alpha.uipath.com", true) || 0 == string.Compare(uri.Host, "staging.uipath.com", true) || 0 == string.Compare(uri.Host, "cloud.uipath.com", true) || 0 == string.Compare(uri.Host, "platform.uipath.com", true)) { WriteError("Use -CloudDeployment parameter to connect to UiPath Automation Cloud"); return; } } if (ParameterSetName == UserPasswordSet || ParameterSetName == HostSet) { authToken = GetUserToken(); } else if (ParameterSetName == WindowsCredentialsSet) { authToken = GetWindowsToken(); } else if (ParameterSetName == UnauthenticatedSet) { authToken = GetUnauthenticatedToken(); } else if (ParameterSetName == CloudAPISet) { AuthToken token = null; if (Session.IsPresent) { token = AuthenticatedCmdlet.SessionAuthToken; } token = token ?? new AuthToken(); token.TenantName = TenantName; token.AccountName = AccountName; token.Token = null; token.AuthorizationRefreshToken = null; if (ParameterSetName == CloudAPISet) { token.AuthorizationRefreshToken = UserKey; token.ApplicationId = ClientId; } token.CloudDeployment = string.IsNullOrWhiteSpace(CloudDeployment) ? CloudDeployments.Production : (CloudDeployments)Enum.Parse(typeof(CloudDeployments), CloudDeployment); authToken = token; } GetServerVersion(authToken); authToken.TenantName = authToken.TenantName ?? TenantName; if (!string.IsNullOrWhiteSpace(OrganizationUnit)) { if (authToken.ApiVersion >= OrchestratorProtocolVersion.V19_10) { WriteWarning("The use of OrganizationUnit is deprecated and will be removed. Use FolderPath instead."); } SetOrganizationUnit(authToken, OrganizationUnit); } else if (!string.IsNullOrWhiteSpace(FolderPath)) { if (authToken.ApiVersion < OrchestratorProtocolVersion.V19_10) { WriteError("Use of FolderPath requires Orchestrator version 19.10 or newer."); } SetCurrentFolder(authToken, FolderPath, Timeout); } else if (authToken.ApiVersion >= OrchestratorProtocolVersion.V19_10 && 0 != string.Compare(TenantName, "Host", true) && !Host.IsPresent) { FindAndSetDefaultFolder(authToken, Timeout); WriteVerbose($"No FolderPath was specified, using {authToken.CurrentFolder?.DisplayName}"); } else { authToken.CurrentFolder = default; authToken.OrganizationUnit = default; authToken.OrganizationUnitId = default; } if (Session.IsPresent) { AuthenticatedCmdlet.SetAuthToken(authToken); } if (MyInvocation.BoundParameters.ContainsKey(nameof(RequestTimeout))) { authToken.RequestTimeout = RequestTimeout; } WriteObject(authToken); } }