-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo.go
115 lines (92 loc) · 2.28 KB
/
repo.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
114
115
package main
import (
"encoding/json"
"github.com/ricallinson/forgery"
"github.com/spacedock-io/index/models"
)
func CreateRepo(req *f.Request, res *f.Response, next func()) {
images := req.Map["json"]
u := req.Map["_user"].(*models.User)
r := &models.Repo{
Namespace: req.Params["namespace"],
Name: req.Params["repo"],
}
ts, err := r.Create("1", u, images.([]interface{}))
if err == models.AlreadyExistsError {
res.Send("\"\"", 200)
return
} else 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("\"\"", 201)
}
func DeleteRepo(req *f.Request, res *f.Response, next func()) {
namespace := req.Params["namespace"]
repo := req.Params["repo"]
r, err := models.GetRepo(namespace, 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 GetUserImage(req *f.Request, res *f.Response, next func()) {
repo := req.Params["repo"]
ns := req.Params["namespace"]
r, err := models.GetRepo(ns, repo)
if err != nil {
res.Send(err.Error(), 400)
return
}
images, e := r.GetImages()
if e != nil {
res.Send(e.Error(), 400)
return
}
j, jsonErr := json.Marshal(images)
if jsonErr != nil {
res.Send("Error returning data", 400)
return
}
res.Send(string(j), 200)
}
func RepoAuth(req *f.Request, res *f.Response, next func()) {
res.Send(200)
}
func UpdateUserImage(req *f.Request, res *f.Response, next func()) {
repo := req.Params["repo"]
ns := req.Params["namespace"]
json := req.Map["json"].([]interface{})
r, err := models.GetRepo(ns, repo)
if err != nil {
res.Send(err.Error(), 400)
return
}
er := r.UpdateImages(json)
if er != nil {
res.Send(err.Error(), 400)
return
}
res.Send("\"\"", 204)
}