MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / buildBootstrapURL

Function buildBootstrapURL

internal/cli/bootstrap.go:153–183  ·  view source on GitHub ↗

buildBootstrapURL constructs the /setup URL the operator should open. setup_method dispatch (kept in sync with handleSessionCheck in internal/server/handlers_auth.go): - "logs_token" — server generated a one-time token and persisted it to /.bootstrap-token. We read it and hand the operato

(cfg *config.Config, setupMethod, next string)

Source from the content-addressed store, hash-verified

151// - anything else — newer server speaking a method this CLI doesn't know.
152// Bail loudly with the same --cli-prompt fallback hint.
153func buildBootstrapURL(cfg *config.Config, setupMethod, next string) (string, error) {
154 base := cfg.BrowserURL()
155
156 // The next= handoff target rides as a query param, which MUST sit
157 // before any #token fragment (a query after the fragment would be
158 // parsed as part of the fragment and never reach the page's
159 // searchParams). url.QueryEscape keeps the leading slash and any
160 // nested path safe to round-trip through the address bar.
161 query := ""
162 if next != "" {
163 query = "?next=" + url.QueryEscape(next)
164 }
165
166 switch setupMethod {
167 case "logs_token":
168 token, err := ReadBootstrapToken(cfg.DataDir)
169 if err != nil {
170 return "", err
171 }
172 return fmt.Sprintf("%s/setup%s#token=%s", base, query, token), nil
173
174 case "open":
175 return base + "/setup" + query, nil
176
177 case "", "local_cli":
178 return "", fmt.Errorf("server has no bootstrap token configured (setup_method=%q); re-run with --cli-prompt to use the legacy TTY flow", setupMethod)
179
180 default:
181 return "", fmt.Errorf("server reported unknown setup_method=%q; this CLI may be older than the server. Re-run with --cli-prompt to use the legacy TTY flow", setupMethod)
182 }
183}
184
185// ReadBootstrapToken reads <DataDir>/.bootstrap-token. The file is created
186// by EnsureBootstrapToken in internal/server/bootstrap.go with mode 0600

Calls 2

ReadBootstrapTokenFunction · 0.85
BrowserURLMethod · 0.80