From be325f26a6bde5400bf38f4021fcd3175231a38a Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Mon, 30 Mar 2020 14:48:02 -0400 Subject: [PATCH] support config with GHES url. (#393) --- .../Configuration/ConfigurationManager.cs | 24 +++++++++++++------ .../Configuration/ConfigurationManagerL0.cs | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Runner.Listener/Configuration/ConfigurationManager.cs b/src/Runner.Listener/Configuration/ConfigurationManager.cs index 1c12a7324..a6e980a5d 100644 --- a/src/Runner.Listener/Configuration/ConfigurationManager.cs +++ b/src/Runner.Listener/Configuration/ConfigurationManager.cs @@ -94,8 +94,7 @@ namespace GitHub.Runner.Listener.Configuration { // Get the URL var inputUrl = command.GetUrl(); - if (!inputUrl.Contains("github.com", StringComparison.OrdinalIgnoreCase) && - !inputUrl.Contains("github.localhost", StringComparison.OrdinalIgnoreCase)) + if (inputUrl.Contains("codedev.ms", StringComparison.OrdinalIgnoreCase)) { runnerSettings.ServerUrl = inputUrl; // Get the credentials @@ -198,7 +197,7 @@ namespace GitHub.Runner.Listener.Configuration } else { - // Create a new agent. + // Create a new agent. agent = CreateNewAgent(runnerSettings.AgentName, publicKey); try @@ -290,7 +289,7 @@ namespace GitHub.Runner.Listener.Configuration { // there are two exception messages server send that indicate clock skew. // 1. The bearer token expired on {jwt.ValidTo}. Current server time is {DateTime.UtcNow}. - // 2. The bearer token is not valid until {jwt.ValidFrom}. Current server time is {DateTime.UtcNow}. + // 2. The bearer token is not valid until {jwt.ValidFrom}. Current server time is {DateTime.UtcNow}. Trace.Error("Catch exception during test agent connection."); Trace.Error(ex); throw new Exception("The local machine's clock may be out of sync with the server time by more than five minutes. Please sync your clock with your domain or internet time and try again."); @@ -402,7 +401,7 @@ namespace GitHub.Runner.Listener.Configuration _term.WriteLine("Cannot connect to server, because config files are missing. Skipping removing runner from the server."); } - //delete credential config files + //delete credential config files currentAction = "Removing .credentials"; if (hasCredentials) { @@ -416,7 +415,7 @@ namespace GitHub.Runner.Listener.Configuration _term.WriteLine("Does not exist. Skipping " + currentAction); } - //delete settings config file + //delete settings config file currentAction = "Removing .runner"; if (isConfigured) { @@ -519,8 +518,19 @@ namespace GitHub.Runner.Listener.Configuration private async Task GetTenantCredential(string githubUrl, string githubToken, string runnerEvent) { + var githubApiUrl = ""; var gitHubUrlBuilder = new UriBuilder(githubUrl); - var githubApiUrl = $"{gitHubUrlBuilder.Scheme}://api.{gitHubUrlBuilder.Host}/actions/runner-registration"; + if (string.Equals(gitHubUrlBuilder.Host, "github.com", StringComparison.OrdinalIgnoreCase) || + string.Equals(gitHubUrlBuilder.Host, "www.github.com", StringComparison.OrdinalIgnoreCase) || + string.Equals(gitHubUrlBuilder.Host, "github.localhost", StringComparison.OrdinalIgnoreCase)) + { + githubApiUrl = $"{gitHubUrlBuilder.Scheme}://api.{gitHubUrlBuilder.Host}/actions/runner-registration"; + } + else + { + githubApiUrl = $"{gitHubUrlBuilder.Scheme}://{gitHubUrlBuilder.Host}/api/v3/actions/runner-registration"; + } + using (var httpClientHandler = HostContext.CreateHttpClientHandler()) using (var httpClient = new HttpClient(httpClientHandler)) { diff --git a/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs b/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs index e9d054353..c47d5be21 100644 --- a/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs +++ b/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs @@ -37,7 +37,7 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration private Mock _rsaKeyManager; private string _expectedToken = "expectedToken"; - private string _expectedServerUrl = "https://localhost"; + private string _expectedServerUrl = "https://codedev.ms"; private string _expectedAgentName = "expectedAgentName"; private string _expectedPoolName = "poolName"; private string _expectedAuthType = "pat";