public IWebConsoleData CreateWebConsole( string userId, ISessionToken sessionToken, ISolutionStsClient stsClient, string vcEndpoint) { IWebConsoleData result = null; _logger.LogInformation("StartCreateWebConsole"); try { Sessions.Instance.EnsureValidUser(userId); _logger.LogDebug("RunspaceProvider -> CreateWebConsole call"); string bearerSamlToken = ""; try { _logger.LogDebug($"HoK Saml Token availble: {sessionToken.HoKSamlToken != null}"); if (sessionToken.HoKSamlToken == null) { throw new Exception(APIGatewayResources.PowerCLIVCloginController_NoRefreshTokenAvailable_For_Session); } _logger.LogDebug($"STSClient -> IssueBearerTokenBySolutionToken call"); bearerSamlToken = stsClient .IssueBearerTokenBySolutionToken(sessionToken.HoKSamlToken.RawXmlElement) .OuterXml; } catch (Exception exc) { _logger.LogError(exc, "Issue Bearer Token failed"); result.State = DataTypes.WebConsoleState.Error; result.ErrorDetails = new DataTypes.ErrorDetails(exc); } var token = Convert.ToBase64String(System.Text.Encoding.Unicode.GetBytes(bearerSamlToken)); var webConsoleInfo = _runspaceProvider.CreateWebConsole(vcEndpoint, token, true); _logger.LogDebug($"Runspace provider result: {webConsoleInfo.Id}, {webConsoleInfo.CreationState}, {webConsoleInfo.CreationError}"); result = new WebConsoleData(webConsoleInfo); result.CreationTime = DateTime.Now; result.State = DataTypes.WebConsoleState.Available; _runspacesStatsMonitor.RegisterWebConsole(result, sessionToken.SessionId); _userWebConsoles.Add(userId, result.Id, result); } catch (RunspaceProviderException runspaceProviderException) { _logger.LogError(runspaceProviderException, "Runspace provider exception was thrown"); throw; } catch (Exception ex) { throw new RunspaceProviderException( string.Format( APIGatewayResources.MultiTenantRunspaceProvider_CreateFailed, userId, ex.Message), ex); } return(result); }
public WebConsole(IWebConsoleData webConsoleData) { if (webConsoleData == null) { throw new ArgumentNullException(nameof(webConsoleData)); } Id = webConsoleData.Id; CreationTime = webConsoleData.CreationTime; State = webConsoleData.State; ErrorDetails = webConsoleData.ErrorDetails; }
public IWebConsoleData GetWebConsole(string userId, string webConsoleId) { _logger.LogInformation($"Get web console with id: {webConsoleId}"); IWebConsoleData result = null; try { Sessions.Instance.EnsureValidUser(userId); if (!_userWebConsoles.Contains(userId)) { throw new RunspaceProviderException( string.Format(APIGatewayResources.MultiTenantRunspaceProvider_UserHasNoWebConsoles, userId)); } if (!_userWebConsoles.Contains(userId, webConsoleId)) { throw new RunspaceProviderException( string.Format(APIGatewayResources.MultiTenantRunspaceProvider_UserHasNoWebConsoleWithId, userId, webConsoleId)); } var webConsoleInfo = _runspaceProvider.GetWebConsole(webConsoleId); var webConsoleData = _userWebConsoles.GetData(userId, webConsoleId); if (webConsoleInfo == null && webConsoleData != null) { _userWebConsoles.RemoveData(userId, webConsoleId); } else { result = webConsoleData; } } catch (Exception ex) { throw new RunspaceProviderException( string.Format( APIGatewayResources.MultiTenantRunspaceProvider_GetWebConsoleFailed, userId, ex.Message), ex); } return(result); }