diff --git a/network/client.go b/network/client.go index 9cd6430c7161c899ab2fb8ae9cc2189a172e23d2..76afaaa7b07024e406695a2df5c766986ea41dc7 100644 --- a/network/client.go +++ b/network/client.go @@ -49,17 +49,16 @@ var ( type client struct { http.Client - url *url.URL - caFile string - certFile string - keyFile string - caData []byte - skipVerify bool - updateTime time.Time - lastUpdate string - compatibleWithGitLab bool - requestBackOffs map[string]*backoff.Backoff - lock sync.Mutex + url *url.URL + caFile string + certFile string + keyFile string + caData []byte + skipVerify bool + updateTime time.Time + lastUpdate string + requestBackOffs map[string]*backoff.Backoff + lock sync.Mutex } type ResponseTLSData struct { @@ -361,12 +360,11 @@ func newClient(requestCredentials requestCredentials) (c *client, err error) { } c = &client{ - url: url, - caFile: requestCredentials.GetTLSCAFile(), - certFile: requestCredentials.GetTLSCertFile(), - keyFile: requestCredentials.GetTLSKeyFile(), - compatibleWithGitLab: true, - requestBackOffs: make(map[string]*backoff.Backoff), + url: url, + caFile: requestCredentials.GetTLSCAFile(), + certFile: requestCredentials.GetTLSCertFile(), + keyFile: requestCredentials.GetTLSKeyFile(), + requestBackOffs: make(map[string]*backoff.Backoff), } host := strings.Split(url.Host, ":")[0] diff --git a/network/gitlab.go b/network/gitlab.go index 45907df3fb3bbbd181f4e50a7fbae90e5b6e72fb..ba2a4bed3967ee6f4c2a0b6c9865e7df9896a164 100644 --- a/network/gitlab.go +++ b/network/gitlab.go @@ -21,8 +21,6 @@ import ( const clientError = -100 -var notSupportingGitLabPre90Message = "GitLab Runner >= 9.0 can be used ONLY with GitLab CE/EE >= 9.0" - type GitLabClient struct { clients map[string]*client lock sync.Mutex @@ -95,28 +93,6 @@ func (n *GitLabClient) doJSON(credentials requestCredentials, method, uri string return c.doJSON(uri, method, statusCode, request, response) } -func (n *GitLabClient) checkGitLabVersionCompatibility(runner common.RunnerCredentials) { - request := common.VerifyRunnerRequest{ - Token: "compatiblity-check", - } - - result, statusText, _ := n.doJSON(&runner, "POST", "runners/verify", http.StatusOK, &request, nil) - - switch result { - case http.StatusForbidden: - runner.Log().Println("Checking GitLab compatibility...", "OK") - default: - runner.Log().WithFields(logrus.Fields{ - "result": result, - "statusText": statusText, - "reason": notSupportingGitLabPre90Message, - }).Errorln("Checking GitLab compatibility...", "not-compatible") - - c, _ := n.getClient(&runner) - c.compatibleWithGitLab = false - } -} - func (n *GitLabClient) RegisterRunner(runner common.RunnerCredentials, description, tags string, runUntagged, locked bool) *common.RegisterRunnerResponse { // TODO: pass executor request := common.RegisterRunnerRequest{ @@ -143,7 +119,6 @@ func (n *GitLabClient) RegisterRunner(runner common.RunnerCredentials, descripti return nil default: runner.Log().WithField("status", statusText).Errorln("Registering runner...", "failed") - n.checkGitLabVersionCompatibility(runner) return nil } } @@ -168,7 +143,6 @@ func (n *GitLabClient) VerifyRunner(runner common.RunnerCredentials) bool { return true default: runner.Log().WithField("status", statusText).Errorln("Verifying runner...", "failed") - n.checkGitLabVersionCompatibility(runner) return true } } @@ -193,7 +167,6 @@ func (n *GitLabClient) UnregisterRunner(runner common.RunnerCredentials) bool { return false default: runner.Log().WithField("status", statusText).Errorln(baseLogText, "failed") - n.checkGitLabVersionCompatibility(runner) return false } } @@ -245,7 +218,6 @@ func (n *GitLabClient) RequestJob(config common.RunnerConfig) (*common.JobRespon return nil, false default: config.Log().WithField("status", statusText).Warningln("Checking for jobs...", "failed") - n.checkGitLabVersionCompatibility(config.RunnerCredentials) return nil, true } } diff --git a/network/gitlab_test.go b/network/gitlab_test.go index ad149376e53667ad0ae63633a3442f7dff16535f..6aa5d0a8fdae4c18f7fde277a9050a98311e062a 100644 --- a/network/gitlab_test.go +++ b/network/gitlab_test.go @@ -890,90 +890,3 @@ func TestArtifactsDownload(t *testing.T) { state = c.DownloadArtifacts(fileNotFoundTokenCredentials, artifactsFileName) assert.Equal(t, DownloadNotFound, state, "Artifacts should be bit downloaded if it's not found") } - -func prepareAPIv4CompatibilityTestEnvironment(name string, handler func(w http.ResponseWriter, r *http.Request)) (server *httptest.Server, runner RunnerConfig) { - server = httptest.NewServer(http.HandlerFunc(handler)) - - runner = RunnerConfig{ - Name: name, - RunnerCredentials: RunnerCredentials{ - URL: server.URL, - Token: "valid", - }, - } - - return -} - -func execAPIv4CompatibilityTestRequest(t *testing.T, requestType string, runner RunnerConfig, isCompatible bool) { - t.Run(fmt.Sprintf("%s/%s", requestType, runner.Name), func(t *testing.T) { - c := NewGitLabClient() - - switch requestType { - case "register runner": - c.RegisterRunner(runner.RunnerCredentials, "", "", false, false) - case "verify runner": - c.VerifyRunner(runner.RunnerCredentials) - case "unregister runner": - c.UnregisterRunner(runner.RunnerCredentials) - case "request job": - c.RequestJob(runner) - } - - client, err := c.getClient(&runner.RunnerCredentials) - assert.NoError(t, err) - if isCompatible { - assert.True(t, client.compatibleWithGitLab, "Client should be marked as compatible with GitLab") - } else { - assert.False(t, client.compatibleWithGitLab, "Client should be marked as not compatible with GitLab") - } - }) -} - -func TestAPIv4Compatibility(t *testing.T) { - serverPre90, runnerPre90 := prepareAPIv4CompatibilityTestEnvironment("pre 9.0", func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case "/api/v4/runners": - w.WriteHeader(http.StatusUnauthorized) - case "/api/v4/runners/verify": - w.WriteHeader(http.StatusUnauthorized) - case "/api/v4/jobs/request": - w.WriteHeader(http.StatusNotFound) - } - }) - defer serverPre90.Close() - - server90, runner90 := prepareAPIv4CompatibilityTestEnvironment("9.0", func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case "/api/v4/runners": - switch r.Method { - case "POST": - res := make(map[string]interface{}) - res["token"] = "token-here" - - output, err := json.Marshal(res) - require.NoError(t, err) - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusCreated) - w.Write(output) - case "DELETE": - w.WriteHeader(http.StatusNoContent) - } - case "/api/v4/runners/verify": - w.WriteHeader(http.StatusOK) - case "/api/v4/jobs/request": - w.WriteHeader(http.StatusNoContent) - } - }) - defer server90.Close() - - execAPIv4CompatibilityTestRequest(t, "register runner", runnerPre90, false) - execAPIv4CompatibilityTestRequest(t, "register runner", runner90, true) - execAPIv4CompatibilityTestRequest(t, "verify runner", runnerPre90, false) - execAPIv4CompatibilityTestRequest(t, "verify runner", runner90, true) - execAPIv4CompatibilityTestRequest(t, "unregister runner", runnerPre90, false) - execAPIv4CompatibilityTestRequest(t, "unregister runner", runner90, true) - execAPIv4CompatibilityTestRequest(t, "request job", runnerPre90, false) - execAPIv4CompatibilityTestRequest(t, "request job", runner90, true) -}