v3.0.0 f19f453

secret_input.go RawHistoryFolder

1package cli
2
3import (
4	"fmt"
5	"io"
6	"os"
7	"strings"
8
9	"golang.org/x/sys/unix"
10)
11
12func readProtectedSecretFile(path string) (string, error) {
13	fd, err := unix.Open(path, unix.O_RDONLY|unix.O_CLOEXEC|unix.O_NOFOLLOW, 0)
14	if err != nil {
15		return "", fmt.Errorf("open secret file %s: %w", path, err)
16	}
17	if fd < 0 {
18		return "", fmt.Errorf("open secret file %s: invalid file descriptor %d", path, fd)
19	}
20	//nolint:gosec // G115: fd is validated non-negative and originates from unix.Open.
21	file := os.NewFile(uintptr(fd), path)
22	if file == nil {
23		_ = unix.Close(fd)
24		return "", fmt.Errorf("open secret file %s: invalid file descriptor", path)
25	}
26	defer file.Close()
27
28	info, err := file.Stat()
29	if err != nil {
30		return "", fmt.Errorf("stat secret file %s: %w", path, err)
31	}
32	if !info.Mode().IsRegular() {
33		return "", fmt.Errorf("%s is not a regular file", path)
34	}
35	if info.Mode().Perm()&0o077 != 0 {
36		return "", fmt.Errorf("%s must not be accessible by group or others (use chmod 600)", path)
37	}
38	data, err := io.ReadAll(file)
39	if err != nil {
40		return "", fmt.Errorf("read secret file %s: %w", path, err)
41	}
42	value := strings.TrimSpace(string(data))
43	if value == "" {
44		return "", fmt.Errorf("%s is empty", path)
45	}
46	return value, nil
47}

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