-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.go
113 lines (88 loc) · 2.17 KB
/
library.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"encoding/json"
"github.com/ricallinson/forgery"
"github.com/spacedock-io/index/models"
)
func CreateLibrary(req *f.Request, res *f.Response, next func()) {
images := req.Map["json"]
u := req.Map["_user"].(*models.User)
if !u.Admin {
res.Send("Not Authorized", 401)
return
}
r := &models.Repo{
Name: req.Params["repo"],
}
ts, err := r.Create("1", u, images.([]interface{}))
if err != nil {
res.Send(err.Error(), 400)
}
res.Set("X-Docker-Token", ts)
res.Set("WWW-Authenticate", "Token " + ts)
res.Set("X-Docker-Endpoints", "staging.spacedock.io:8081")
res.Send("\"\"", 200)
}
func DeleteLibrary(req *f.Request, res *f.Response, next func()) {
repo := req.Params["repo"]
r, err := models.GetRepo("", repo)
if err != nil {
res.Send(err.Error(), 400)
return
}
if !r.Deleted {
ts, err := r.MarkAsDeleted(req.Map["_uid"].(int64))
if err != nil {
res.Send(err.Error(), 400)
return
}
res.Set("X-Docker-Token", ts)
res.Set("WWW-Authenticate", "Token " + ts)
res.Set("X-Docker-Endpoints", "staging.spacedock.io:8081")
res.Send(202)
return
}
err = r.Delete()
if err != nil {
res.Send(err.Error(), 400)
return
}
res.Send(200)
}
func GetLibraryImage(req *f.Request, res *f.Response, next func()) {
repo := req.Params["repo"]
r, err := models.GetRepo("library", repo)
if err != nil {
res.Send(err.Error(), 400)
}
images, er := r.GetImages()
if er != nil {
res.Send(er.Error(), 400)
}
j, e := json.Marshal(images)
if e != nil {
res.Send("Error returning data", 400)
}
res.Send(string(j), 200)
}
func LibraryAuth(req *f.Request, res *f.Response, next func()) {
res.Send(200)
}
func UpdateLibraryImage(req *f.Request, res *f.Response, next func()) {
u := req.Map["_user"].(*models.User)
if !u.Admin {
res.Send("Not Authorized", 401)
return
}
repo := req.Params["repo"]
json := req.Map["json"].([]interface{})
r, err := models.GetRepo("", repo)
if err != nil {
res.Send(err.Error(), 400)
}
er := r.UpdateImages(json)
if er != nil {
res.Send(err.Error(), 400)
}
res.Send("\"\"", 204)
}