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

Function ReadBootstrapToken

internal/cli/bootstrap.go:197–214  ·  view source on GitHub ↗

ReadBootstrapToken reads /.bootstrap-token. The file is created by EnsureBootstrapToken in internal/server/bootstrap.go with mode 0600 and contains the base64url-encoded token followed by a trailing newline. Errors are wrapped with the absolute path so the operator can find the file (or co

(dataDir string)

Source from the content-addressed store, hash-verified

195// Callers that want a best-effort token (absent → empty, not an error) should
196// ignore the returned error and use the token only when non-empty.
197func ReadBootstrapToken(dataDir string) (string, error) {
198 path := filepath.Join(dataDir, bootstrapTokenFilename)
199 data, err := os.ReadFile(path)
200 if err != nil {
201 if errors.Is(err, os.ErrNotExist) {
202 // Wrap with %w so callers can errors.Is(err, os.ErrNotExist) to
203 // distinguish "file absent" from other read failures (e.g. to
204 // treat absence as best-effort rather than a hard error).
205 return "", fmt.Errorf("bootstrap token file %s not found (%w) — the server may have already consumed it, or token generation failed at startup. Re-run with --cli-prompt to use the legacy TTY flow", path, os.ErrNotExist)
206 }
207 return "", fmt.Errorf("read bootstrap token %s: %w (re-run with --cli-prompt to use the legacy TTY flow)", path, err)
208 }
209 token := strings.TrimSpace(string(data))
210 if token == "" {
211 return "", fmt.Errorf("bootstrap token file %s is empty; delete it and restart the server, or re-run with --cli-prompt to use the legacy TTY flow", path)
212 }
213 return token, nil
214}
215
216// pollUntilSetupDone tickets every bootstrapPollInterval and returns nil
217// the first time CheckSession reports setup_required: false. Returns

Callers 3

doHeadlessBootstrapFunction · 0.92
buildBootstrapURLFunction · 0.85

Calls 1

JoinMethod · 0.80