镜像自地址
https://github.com/tuna/tunasync.git
已同步 2025-12-06 14:36:47 +00:00
refactor(tunasync):
1. refactored manager and worker to support TLS transport 2. if mirror_dir is specified from a mirror config, don't add the mirror name
这个提交包含在:
@@ -4,6 +4,7 @@ import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@@ -153,6 +154,7 @@ func (s *Manager) listWorkers(c *gin.Context) {
|
||||
func (s *Manager) registerWorker(c *gin.Context) {
|
||||
var _worker WorkerStatus
|
||||
c.BindJSON(&_worker)
|
||||
_worker.LastOnline = time.Now()
|
||||
newWorker, err := s.adapter.CreateWorker(_worker)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("failed to register worker: %s",
|
||||
@@ -230,7 +232,7 @@ func (s *Manager) handleClientCmd(c *gin.Context) {
|
||||
}
|
||||
|
||||
// post command to worker
|
||||
_, err = postJSON(workerURL, workerCmd)
|
||||
_, err = PostJSON(workerURL, workerCmd, s.tlsConfig)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("post command to worker %s(%s) fail: %s", workerID, workerURL, err.Error())
|
||||
c.Error(err)
|
||||
|
||||
@@ -65,7 +65,7 @@ func TestHTTPServer(t *testing.T) {
|
||||
w := WorkerStatus{
|
||||
ID: "test_worker1",
|
||||
}
|
||||
resp, err := postJSON(baseURL+"/workers", w)
|
||||
resp, err := PostJSON(baseURL+"/workers", w, nil)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode, ShouldEqual, http.StatusOK)
|
||||
|
||||
@@ -90,7 +90,7 @@ func TestHTTPServer(t *testing.T) {
|
||||
Upstream: "mirrors.tuna.tsinghua.edu.cn",
|
||||
Size: "3GB",
|
||||
}
|
||||
resp, err := postJSON(fmt.Sprintf("%s/workers/%s/jobs/%s", baseURL, status.Worker, status.Name), status)
|
||||
resp, err := PostJSON(fmt.Sprintf("%s/workers/%s/jobs/%s", baseURL, status.Worker, status.Name), status, nil)
|
||||
defer resp.Body.Close()
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode, ShouldEqual, http.StatusOK)
|
||||
@@ -136,8 +136,8 @@ func TestHTTPServer(t *testing.T) {
|
||||
Upstream: "mirrors.tuna.tsinghua.edu.cn",
|
||||
Size: "4GB",
|
||||
}
|
||||
resp, err := postJSON(fmt.Sprintf("%s/workers/%s/jobs/%s",
|
||||
baseURL, status.Worker, status.Name), status)
|
||||
resp, err := PostJSON(fmt.Sprintf("%s/workers/%s/jobs/%s",
|
||||
baseURL, status.Worker, status.Name), status, nil)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode, ShouldEqual, http.StatusBadRequest)
|
||||
defer resp.Body.Close()
|
||||
@@ -156,7 +156,7 @@ func TestHTTPServer(t *testing.T) {
|
||||
ID: "test_worker_cmd",
|
||||
URL: workerBaseURL + "/cmd",
|
||||
}
|
||||
resp, err := postJSON(baseURL+"/workers", w)
|
||||
resp, err := PostJSON(baseURL+"/workers", w, nil)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode, ShouldEqual, http.StatusOK)
|
||||
|
||||
@@ -177,7 +177,7 @@ func TestHTTPServer(t *testing.T) {
|
||||
MirrorID: "ubuntu-sync",
|
||||
WorkerID: "not_exist_worker",
|
||||
}
|
||||
resp, err := postJSON(baseURL+"/cmd", clientCmd)
|
||||
resp, err := PostJSON(baseURL+"/cmd", clientCmd, nil)
|
||||
defer resp.Body.Close()
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode, ShouldEqual, http.StatusBadRequest)
|
||||
@@ -190,7 +190,7 @@ func TestHTTPServer(t *testing.T) {
|
||||
WorkerID: w.ID,
|
||||
}
|
||||
|
||||
resp, err := postJSON(baseURL+"/cmd", clientCmd)
|
||||
resp, err := PostJSON(baseURL+"/cmd", clientCmd, nil)
|
||||
defer resp.Body.Close()
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func postJSON(url string, obj interface{}) (*http.Response, error) {
|
||||
b := new(bytes.Buffer)
|
||||
json.NewEncoder(b).Encode(obj)
|
||||
return http.Post(url, "application/json; charset=utf-8", b)
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户