mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-03-20 11:56:47 +08:00
auto adjust code
This commit is contained in:
@@ -126,15 +126,15 @@ func artifactNameToID(s string) int64 {
|
||||
return int64(h.Sum32())
|
||||
}
|
||||
|
||||
func (c ArtifactContext) Error(status int, _ ...interface{}) {
|
||||
func (c ArtifactContext) Error(status int, _ ...any) {
|
||||
c.Resp.WriteHeader(status)
|
||||
}
|
||||
|
||||
func (c ArtifactContext) JSON(status int, _ ...interface{}) {
|
||||
func (c ArtifactContext) JSON(status int, _ ...any) {
|
||||
c.Resp.WriteHeader(status)
|
||||
}
|
||||
|
||||
func validateRunIDV4(ctx *ArtifactContext, rawRunID string) (interface{}, int64, bool) {
|
||||
func validateRunIDV4(ctx *ArtifactContext, rawRunID string) (any, int64, bool) {
|
||||
runID, err := strconv.ParseInt(rawRunID, 10, 64)
|
||||
if err != nil /* || task.Job.RunID != runID*/ {
|
||||
log.Error("Error runID not match")
|
||||
@@ -210,7 +210,7 @@ func (r artifactV4Routes) buildSignature(endp, expires, artifactName string, tas
|
||||
func (r artifactV4Routes) buildArtifactURL(endp, artifactName string, taskID int64) string {
|
||||
expires := time.Now().Add(60 * time.Minute).Format("2006-01-02 15:04:05.999999999 -0700 MST")
|
||||
uploadURL := "http://" + strings.TrimSuffix(r.AppURL, "/") + strings.TrimSuffix(r.prefix, "/") +
|
||||
"/" + endp + "?sig=" + base64.URLEncoding.EncodeToString(r.buildSignature(endp, expires, artifactName, taskID)) + "&expires=" + url.QueryEscape(expires) + "&artifactName=" + url.QueryEscape(artifactName) + "&taskID=" + fmt.Sprint(taskID)
|
||||
"/" + endp + "?sig=" + base64.URLEncoding.EncodeToString(r.buildSignature(endp, expires, artifactName, taskID)) + "&expires=" + url.QueryEscape(expires) + "&artifactName=" + url.QueryEscape(artifactName) + "&taskID=" + strconv.FormatInt(taskID, 10)
|
||||
return uploadURL
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ func (r *artifactV4Routes) createArtifact(ctx *ArtifactContext) {
|
||||
|
||||
artifactName := req.Name
|
||||
|
||||
safeRunPath := safeResolve(r.baseDir, fmt.Sprint(runID))
|
||||
safeRunPath := safeResolve(r.baseDir, strconv.FormatInt(runID, 10))
|
||||
safePath := safeResolve(safeRunPath, artifactName)
|
||||
safePath = safeResolve(safePath, artifactName+".zip")
|
||||
file, err := r.fs.OpenWritable(safePath)
|
||||
@@ -305,7 +305,7 @@ func (r *artifactV4Routes) uploadArtifact(ctx *ArtifactContext) {
|
||||
switch comp {
|
||||
case "block", "appendBlock":
|
||||
|
||||
safeRunPath := safeResolve(r.baseDir, fmt.Sprint(task))
|
||||
safeRunPath := safeResolve(r.baseDir, strconv.FormatInt(task, 10))
|
||||
safePath := safeResolve(safeRunPath, artifactName)
|
||||
safePath = safeResolve(safePath, artifactName+".zip")
|
||||
|
||||
@@ -365,7 +365,7 @@ func (r *artifactV4Routes) listArtifacts(ctx *ArtifactContext) {
|
||||
return
|
||||
}
|
||||
|
||||
safePath := safeResolve(r.baseDir, fmt.Sprint(runID))
|
||||
safePath := safeResolve(r.baseDir, strconv.FormatInt(runID, 10))
|
||||
|
||||
entries, err := fs.ReadDir(r.rfs, safePath)
|
||||
if err != nil {
|
||||
@@ -424,7 +424,7 @@ func (r *artifactV4Routes) downloadArtifact(ctx *ArtifactContext) {
|
||||
return
|
||||
}
|
||||
|
||||
safeRunPath := safeResolve(r.baseDir, fmt.Sprint(task))
|
||||
safeRunPath := safeResolve(r.baseDir, strconv.FormatInt(task, 10))
|
||||
safePath := safeResolve(safeRunPath, artifactName)
|
||||
safePath = safeResolve(safePath, artifactName+".zip")
|
||||
|
||||
@@ -443,7 +443,7 @@ func (r *artifactV4Routes) deleteArtifact(ctx *ArtifactContext) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
safeRunPath := safeResolve(r.baseDir, fmt.Sprint(runID))
|
||||
safeRunPath := safeResolve(r.baseDir, strconv.FormatInt(runID, 10))
|
||||
safePath := safeResolve(safeRunPath, req.Name)
|
||||
|
||||
_ = os.RemoveAll(safePath)
|
||||
|
||||
@@ -68,7 +68,7 @@ func TestNewArtifactUploadPrepare(t *testing.T) {
|
||||
router := httprouter.New()
|
||||
uploads(router, "artifact/server/path", writeMapFS{memfs})
|
||||
|
||||
req, _ := http.NewRequest("POST", "http://localhost/_apis/pipelines/workflows/1/artifacts", nil)
|
||||
req, _ := http.NewRequest(http.MethodPost, "http://localhost/_apis/pipelines/workflows/1/artifacts", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
router.ServeHTTP(rr, req)
|
||||
@@ -94,7 +94,7 @@ func TestArtifactUploadBlob(t *testing.T) {
|
||||
router := httprouter.New()
|
||||
uploads(router, "artifact/server/path", writeMapFS{memfs})
|
||||
|
||||
req, _ := http.NewRequest("PUT", "http://localhost/upload/1?itemPath=some/file", strings.NewReader("content"))
|
||||
req, _ := http.NewRequest(http.MethodPut, "http://localhost/upload/1?itemPath=some/file", strings.NewReader("content"))
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
router.ServeHTTP(rr, req)
|
||||
@@ -121,7 +121,7 @@ func TestFinalizeArtifactUpload(t *testing.T) {
|
||||
router := httprouter.New()
|
||||
uploads(router, "artifact/server/path", writeMapFS{memfs})
|
||||
|
||||
req, _ := http.NewRequest("PATCH", "http://localhost/_apis/pipelines/workflows/1/artifacts", nil)
|
||||
req, _ := http.NewRequest(http.MethodPatch, "http://localhost/_apis/pipelines/workflows/1/artifacts", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
router.ServeHTTP(rr, req)
|
||||
@@ -151,7 +151,7 @@ func TestListArtifacts(t *testing.T) {
|
||||
router := httprouter.New()
|
||||
downloads(router, "artifact/server/path", memfs)
|
||||
|
||||
req, _ := http.NewRequest("GET", "http://localhost/_apis/pipelines/workflows/1/artifacts", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://localhost/_apis/pipelines/workflows/1/artifacts", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
router.ServeHTTP(rr, req)
|
||||
@@ -183,7 +183,7 @@ func TestListArtifactContainer(t *testing.T) {
|
||||
router := httprouter.New()
|
||||
downloads(router, "artifact/server/path", memfs)
|
||||
|
||||
req, _ := http.NewRequest("GET", "http://localhost/download/1?itemPath=some/file", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://localhost/download/1?itemPath=some/file", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
router.ServeHTTP(rr, req)
|
||||
@@ -198,7 +198,7 @@ func TestListArtifactContainer(t *testing.T) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
assert.Equal(1, len(response.Value))
|
||||
assert.Len(response.Value, 1)
|
||||
assert.Equal("some/file", response.Value[0].Path)
|
||||
assert.Equal("file", response.Value[0].ItemType)
|
||||
assert.Equal("http://localhost/artifact/1/some/file/.", response.Value[0].ContentLocation)
|
||||
@@ -216,7 +216,7 @@ func TestDownloadArtifactFile(t *testing.T) {
|
||||
router := httprouter.New()
|
||||
downloads(router, "artifact/server/path", memfs)
|
||||
|
||||
req, _ := http.NewRequest("GET", "http://localhost/artifact/1/some/file", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://localhost/artifact/1/some/file", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
router.ServeHTTP(rr, req)
|
||||
@@ -283,7 +283,7 @@ func runTestJobFile(ctx context.Context, t *testing.T, tjfi TestJobFileInfo) {
|
||||
}
|
||||
|
||||
workdir, err := filepath.Abs(tjfi.workdir)
|
||||
assert.Nil(t, err, workdir)
|
||||
assert.NoError(t, err, workdir)
|
||||
fullWorkflowPath := filepath.Join(workdir, tjfi.workflowPath)
|
||||
runnerConfig := &runner.Config{
|
||||
Workdir: workdir,
|
||||
@@ -299,16 +299,16 @@ func runTestJobFile(ctx context.Context, t *testing.T, tjfi TestJobFileInfo) {
|
||||
}
|
||||
|
||||
runner, err := runner.New(runnerConfig)
|
||||
assert.Nil(t, err, tjfi.workflowPath)
|
||||
assert.NoError(t, err, tjfi.workflowPath)
|
||||
|
||||
planner, err := model.NewWorkflowPlanner(fullWorkflowPath, model.PlannerConfig{})
|
||||
assert.Nil(t, err, fullWorkflowPath)
|
||||
assert.NoError(t, err, fullWorkflowPath)
|
||||
|
||||
plan, err := planner.PlanEvent(tjfi.eventName)
|
||||
if err == nil {
|
||||
err = runner.NewPlanExecutor(plan)(ctx)
|
||||
if tjfi.errorMessage == "" {
|
||||
assert.Nil(t, err, fullWorkflowPath)
|
||||
assert.NoError(t, err, fullWorkflowPath)
|
||||
} else {
|
||||
assert.Error(t, err, tjfi.errorMessage)
|
||||
}
|
||||
@@ -356,7 +356,7 @@ func TestDownloadArtifactFileUnsafePath(t *testing.T) {
|
||||
router := httprouter.New()
|
||||
downloads(router, "artifact/server/path", memfs)
|
||||
|
||||
req, _ := http.NewRequest("GET", "http://localhost/artifact/2/../../some/file", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://localhost/artifact/2/../../some/file", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
router.ServeHTTP(rr, req)
|
||||
@@ -378,7 +378,7 @@ func TestArtifactUploadBlobUnsafePath(t *testing.T) {
|
||||
router := httprouter.New()
|
||||
uploads(router, "artifact/server/path", writeMapFS{memfs})
|
||||
|
||||
req, _ := http.NewRequest("PUT", "http://localhost/upload/1?itemPath=../../some/file", strings.NewReader("content"))
|
||||
req, _ := http.NewRequest(http.MethodPut, "http://localhost/upload/1?itemPath=../../some/file", strings.NewReader("content"))
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
router.ServeHTTP(rr, req)
|
||||
|
||||
Reference in New Issue
Block a user