-
Notifications
You must be signed in to change notification settings - Fork 84
/
upload.go
84 lines (71 loc) · 1.34 KB
/
upload.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"errors"
"fmt"
"io"
"os"
"strings"
"github.com/gin-gonic/gin"
)
func uploadChart(c *gin.Context) {
file, header, err := c.Request.FormFile("chart")
if err != nil {
respErr(c, err)
return
}
filename := header.Filename
t := strings.Split(filename, ".")
if t[len(t)-1] != "tgz" {
respErr(c, fmt.Errorf("chart file suffix must .tgz"))
return
}
out, err := os.Create(helmConfig.UploadPath + "/" + filename)
if err != nil {
respErr(c, err)
return
}
defer out.Close()
_, err = io.Copy(out, file)
if err != nil {
respErr(c, err)
return
}
respOK(c, nil)
}
func listUploadedCharts(c *gin.Context) {
charts := []string{}
files, err := os.ReadDir(helmConfig.UploadPath)
if err != nil {
respErr(c, err)
return
}
for _, f := range files {
t := strings.Split(f.Name(), ".")
if t[len(t)-1] == "tgz" {
charts = append(charts, f.Name())
}
}
respOK(c, charts)
}
func deleteChart(c *gin.Context) {
chart := c.Param("chart")
if chart == "" {
err := errors.New("chart must be not empty")
respErr(c, err)
return
}
filePath := helmConfig.UploadPath + "/" + chart
// not exist,ok
_, err := os.Stat(filePath)
if err != nil || os.IsNotExist(err) {
respOK(c, nil)
return
}
//delete chart from disk
err = os.Remove(filePath)
if err != nil {
respErr(c, err)
return
}
respOK(c, nil)
}