latest cdbcd03

createcontainer.go RawHistoryFolder

1package handler
2
3import (
4	"fmt"
5	"net/http"
6
7	"github.com/bnema/gordon/internal/server"
8	"github.com/bnema/gordon/internal/templating/cmdparams"
9	"github.com/bnema/gordon/internal/templating/render"
10	"github.com/bnema/gordon/pkg/docker"
11	"github.com/bnema/gordon/pkg/sanitize"
12	"github.com/labstack/echo/v4"
13)
14
15// FromShortIDToImageID converts a short image ID to a full image ID
16func FromShortIDToImageID(ShortID string) (string, error) {
17	imageID, exists := safelyInteractWithIDMap(Fetch, ShortID)
18	if exists {
19		return imageID, nil
20	}
21	return "", fmt.Errorf("image ID not found")
22}
23
24// CreateContainerRoute is the route for creating a new container
25func CreateContainerGET(c echo.Context, a *server.App) error {
26	// Retreive the ShortID of the image from the URL
27	ShortID := c.Param("ID")
28
29	// Convert the ShortID to a full image ID
30	imageID, err := FromShortIDToImageID(ShortID)
31	if err != nil {
32		return sendError(c, err)
33	}
34
35	// Get the image info
36	imageInfo, err := docker.GetImageInfo(imageID)
37	if err != nil {
38		return sendError(c, err)
39	}
40
41	// Extract image name
42	var imageName string
43	if len(imageInfo.RepoTags) > 0 {
44		imageName = imageInfo.RepoTags[0]
45	}
46
47	data := map[string]interface{}{
48		"Title":     "Create a new container",
49		"ShortID":   ShortID,
50		"ImageID":   imageID,
51		"ImageName": imageName,
52	}
53
54	rendererData, err := render.GetHTMLRenderer("html/fragments", "createcontainer.gohtml", a.TemplateFS, a)
55
56	if err != nil {
57		return sendError(c, err)
58	}
59
60	renderedHTML, err := rendererData.Render(data, a)
61
62	if err != nil {
63		return sendError(c, err)
64	}
65
66	return c.HTML(200, renderedHTML)
67
68}
69
70// CreateContainerPOST handles the create container form submission
71func CreateContainerPOST(c echo.Context, a *server.App) error {
72	// Retreive the ShortID of the image from the URL
73	ShortID := c.Param("ID")
74
75	// Convert the ShortID to a full image ID
76	imageID, err := FromShortIDToImageID(ShortID)
77	if err != nil {
78		return sendError(c, err)
79	}
80
81	// Get the image info
82	_, err = docker.GetImageInfo(imageID)
83	if err != nil {
84		return sendError(c, err)
85	}
86
87	// Retrieve all form parameters
88	formParams, err := c.FormParams()
89	if err != nil {
90		return sendError(c, err)
91	}
92
93	// Initialize a map to store sanitized values
94	sanitizedInputs := make(map[string]string)
95
96	// Iterate over all form parameters and sanitize them
97	for k, v := range formParams {
98		if len(v) > 0 {
99			sanitized, err := sanitize.SanitizeHTML(v[0])
100			if err != nil {
101				return sendError(c, err)
102			}
103			sanitizedInputs[k] = sanitized
104		}
105	}
106
107	cmdParams, err := cmdparams.FromInputsToCmdParams(sanitizedInputs, a)
108	if err != nil {
109		return sendError(c, err)
110	}
111
112	// Create the container
113	_, err = docker.CreateContainer(cmdParams)
114	if err != nil {
115		return sendError(c, err)
116	}
117
118	return c.HTML(http.StatusOK, ActionSuccess(a))
119}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close