-
-
Notifications
You must be signed in to change notification settings - Fork 105
/
api_images.go
41 lines (32 loc) · 1010 Bytes
/
api_images.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
package docker
import (
"net/http"
"encoding/json"
"github.com/azukaar/cosmos-server/src/utils"
)
func InspectImageRoute(w http.ResponseWriter, req *http.Request) {
if utils.AdminOnly(w, req) != nil {
return
}
errD := Connect()
if errD != nil {
utils.Error("InspectImage", errD)
utils.HTTPError(w, "Internal server error: " + errD.Error(), http.StatusInternalServerError, "DS002")
return
}
imageName := utils.SanitizeSafe(req.URL.Query().Get("imageName"))
utils.Log("InspectImage " + imageName)
if req.Method == "GET" {
image, _, err := DockerClient.ImageInspectWithRaw(DockerContext, imageName)
if err != nil {
utils.Error("InspectImage", err)
utils.HTTPError(w, "Internal server error: " + err.Error(), http.StatusInternalServerError, "DS002")
return
}
json.NewEncoder(w).Encode(image)
} else {
utils.Error("InspectImage: Method not allowed" + req.Method, nil)
utils.HTTPError(w, "Method not allowed", http.StatusMethodNotAllowed, "HTTP001")
return
}
}