No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AutoConfig.cs 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using Codice.Client.Common;
  2. using Codice.CM.Common;
  3. using PlasticGui;
  4. using Unity.PlasticSCM.Editor.Configuration.CloudEdition.Welcome;
  5. using Unity.PlasticSCM.Editor.WebApi;
  6. namespace Unity.PlasticSCM.Editor.Configuration
  7. {
  8. internal static class AutoConfig
  9. {
  10. internal static TokenExchangeResponse PlasticCredentials(
  11. string unityAccessToken,
  12. string serverName,
  13. string wkPath)
  14. {
  15. SetupUnityEditionToken.CreateCloudEditionTokenIfNeeded();
  16. bool isClientConfigConfigured = ClientConfig.IsConfigured();
  17. if (!isClientConfigConfigured)
  18. {
  19. ConfigureClientConf.FromUnityAccessToken(
  20. unityAccessToken, serverName, wkPath);
  21. }
  22. TokenExchangeResponse tokenExchangeResponse = WebRestApiClient.
  23. PlasticScm.TokenExchange(unityAccessToken);
  24. if (tokenExchangeResponse.Error != null)
  25. return tokenExchangeResponse;
  26. CloudEditionWelcomeWindow.JoinCloudServer(
  27. serverName,
  28. tokenExchangeResponse.User);
  29. if (!isClientConfigConfigured)
  30. return tokenExchangeResponse;
  31. ConfigureProfile.ForServerIfNeeded(
  32. serverName,
  33. tokenExchangeResponse.User);
  34. return tokenExchangeResponse;
  35. }
  36. static class ConfigureClientConf
  37. {
  38. internal static void FromUnityAccessToken(
  39. string unityAccessToken,
  40. string serverName,
  41. string wkPath)
  42. {
  43. CredentialsResponse response = WebRestApiClient.
  44. PlasticScm.GetCredentials(unityAccessToken);
  45. if (response.Error != null)
  46. {
  47. UnityEngine.Debug.LogErrorFormat(
  48. PlasticLocalization.GetString(
  49. PlasticLocalization.Name.ErrorGettingCredentialsCloudProject),
  50. response.Error.Message,
  51. response.Error.ErrorCode);
  52. return;
  53. }
  54. ClientConfigData configData = BuildClientConfigData(
  55. serverName, wkPath, response);
  56. ClientConfig.Get().Save(configData);
  57. }
  58. static ClientConfigData BuildClientConfigData(
  59. string serverName,
  60. string wkPath,
  61. CredentialsResponse response)
  62. {
  63. SEIDWorkingMode workingMode = GetWorkingMode(response.Type);
  64. ClientConfigData configData = new ClientConfigData();
  65. configData.WorkspaceServer = serverName;
  66. configData.CurrentWorkspace = wkPath;
  67. configData.WorkingMode = workingMode.ToString();
  68. configData.SecurityConfig = UserInfo.GetSecurityConfigStr(
  69. workingMode,
  70. response.Email,
  71. GetPassword(response.Token, response.Type));
  72. configData.LastRunningEdition = InstalledEdition.Get();
  73. return configData;
  74. }
  75. static string GetPassword(
  76. string token,
  77. CredentialsResponse.TokenType tokenType)
  78. {
  79. if (tokenType == CredentialsResponse.TokenType.Bearer)
  80. return BEARER_PREFIX + token;
  81. return token;
  82. }
  83. static SEIDWorkingMode GetWorkingMode(CredentialsResponse.TokenType tokenType)
  84. {
  85. if (tokenType == CredentialsResponse.TokenType.Bearer)
  86. return SEIDWorkingMode.SSOWorkingMode;
  87. return SEIDWorkingMode.LDAPWorkingMode;
  88. }
  89. const string BEARER_PREFIX = "Bearer ";
  90. }
  91. static class ConfigureProfile
  92. {
  93. internal static void ForServerIfNeeded(string serverName, string user)
  94. {
  95. ProfileManager profileManager = CmConnection.Get().GetProfileManager();
  96. ServerProfile serverProfile = profileManager.GetProfileForServer(serverName);
  97. if (serverProfile != null)
  98. return;
  99. serverProfile = ProfileManager.CreateProfile(
  100. serverName,
  101. SEIDWorkingMode.SSOWorkingMode,
  102. user);
  103. profileManager.SaveProfile(serverProfile);
  104. }
  105. }
  106. }
  107. }