v3.4.0 593c1c3

app_l4.go RawHistoryFolder

1package domain
2
3import (
4	"fmt"
5	"net"
6	"strconv"
7	"strings"
8)
9
10// EntryPointListener is the canonical public bind of one installation
11// entrypoint. An app L4 publish declaration must be exactly compatible
12// with the entrypoint that will actually bind it: the runtime binds the
13// entrypoint address, so a narrower publish (for example loopback) would
14// silently be exposed on the entrypoint listener instead.
15type EntryPointListener struct {
16	// Address is the configured listen address, "host:port" or ":port".
17	Address string
18	// Protocol is the entrypoint transport.
19	Protocol EntryPointProtocol
20}
21
22// CanonicalBindHost normalizes a bind host: an empty host means "all
23// interfaces" and is reported as 0.0.0.0 so an unset host and an explicit
24// wildcard compare equal.
25func CanonicalBindHost(host string) string {
26	host = strings.TrimSpace(host)
27	if host == "" {
28		return "0.0.0.0"
29	}
30	return host
31}
32
33// EntryPointCarriesTransport reports whether an entrypoint protocol can
34// carry the given app interface transport.
35func EntryPointCarriesTransport(protocol EntryPointProtocol, transport NetworkProtocol) bool {
36	switch transport {
37	case NetworkProtocolTCP:
38		switch protocol {
39		case EntryPointProtocolTCP, EntryPointProtocolTLSMux, EntryPointProtocolSmartTCP:
40			return true
41		}
42		return false
43	case NetworkProtocolUDP:
44		return protocol == EntryPointProtocolUDP
45	default:
46		return false
47	}
48}
49
50// ValidatePublishForListener requires a declared publish bind to equal the
51// entrypoint listener address and the declared transport to be supported
52// by the entrypoint protocol. Any mismatch is rejected before persistence
53// or container effects; a caller must never substitute the entrypoint
54// address for a narrower declared bind.
55func ValidatePublishForListener(publish string, transport NetworkProtocol, listener EntryPointListener, entrypointName string) error {
56	host, port, err := ParsePublish(publish)
57	if err != nil {
58		return err
59	}
60	listenerHost, listenerPort, err := SplitListenerAddress(listener.Address)
61	if err != nil {
62		return fmt.Errorf("%w: entrypoint %q listener address %q is invalid: %s", ErrInvalidAppSpec, entrypointName, listener.Address, err)
63	}
64	if port != listenerPort || CanonicalBindHost(host) != CanonicalBindHost(listenerHost) {
65		return fmt.Errorf(
66			"%w: publish %q for entrypoint %q must match the listener bind %q exactly",
67			ErrInvalidAppSpec, publish, entrypointName, listener.Address,
68		)
69	}
70	if !EntryPointCarriesTransport(listener.Protocol, transport) {
71		return fmt.Errorf(
72			"%w: entrypoint %q protocol %q cannot carry %s traffic",
73			ErrInvalidAppSpec, entrypointName, listener.Protocol, transport,
74		)
75	}
76	return nil
77}
78
79// SplitListenerAddress parses a configured listen address into its
80// canonical host and port. An address without a port is invalid: the
81// runtime always binds a concrete port.
82func SplitListenerAddress(address string) (string, int, error) {
83	address = strings.TrimSpace(address)
84	if address == "" {
85		return "", 0, fmt.Errorf("empty listen address")
86	}
87	host, portText, err := net.SplitHostPort(address)
88	if err != nil {
89		return "", 0, err
90	}
91	port, err := strconv.Atoi(portText)
92	if err != nil || port < 1 || port > 65535 {
93		return "", 0, fmt.Errorf("port %q must be 1-65535", portText)
94	}
95	return host, port, nil
96}

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