gitea: the Go bundles fall back to the token files in gitea's state directory by default

The binary is placed by hand on novox first, under gitea 0.1.316's composition, which hands the Go bundles
neither MESH_GITEA_TOKEN_FILE nor MESH_GITEA_PACKAGES_TOKEN_FILE, nor any variable naming gitea's state
directory. Without them the fallback reads token and packages-token in /var/lib/mesh/gitea/state (the
manifest's runtime-state directory) and says at start that the path is the default; the manifest's
variables still win when handed.

Builds: design 47 H2 H-A-564 (hq 1b286366)
This commit is contained in:
2026-11-23 13:11:56 +01:00
parent 1ced7fce14
commit 263b5d9aba
2 changed files with 70 additions and 18 deletions
+29 -10
View File
@@ -16,6 +16,7 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"sync"
@@ -61,8 +62,10 @@ type VaultToken struct {
Account string
// File is the token file gitea's TypeScript bundle keeps for Account, "" when the manifest names none.
File string
ask Ask
keys seal.KeyPair
// FileByDefault says File is DefaultStateDir's, the manifest naming none.
FileByDefault bool
ask Ask
keys seal.KeyPair
mu sync.Mutex
token string
@@ -205,14 +208,20 @@ func TokenOf(account string) (*VaultToken, error) {
if err != nil {
return nil, err
}
t.File = TokenFile(account)
t.File, t.FileByDefault = TokenFile(account)
processTokens[account] = t
return t, nil
}
// DefaultStateDir is gitea's runtime-state directory (the manifest's `${dir:mesh-state}/state`), where its TypeScript
// bundle keeps the token files, for a composition that hands the Go bundles no token file (gitea 0.1.316 hands them
// no variable naming that directory either; H-A-564).
const DefaultStateDir = "/var/lib/mesh/gitea/state"
// TokenFile is the file the manifest names for account's token as gitea's TypeScript bundle keeps it (H-A-564):
// MESH_GITEA_PACKAGES_TOKEN_FILE for the packages account, MESH_GITEA_TOKEN_FILE for the tools' account.
func TokenFile(account string) string {
// MESH_GITEA_PACKAGES_TOKEN_FILE for the packages account, MESH_GITEA_TOKEN_FILE for the tools' account; when the
// variable is not handed, the file in DefaultStateDir, and byDefault says so. "" for any other account.
func TokenFile(account string) (file string, byDefault bool) {
packages := os.Getenv("MESH_GITEA_PACKAGES_USER")
if packages == "" {
packages = PackagesAccount
@@ -221,13 +230,19 @@ func TokenFile(account string) string {
if tools == "" {
tools = ToolsAccount
}
variable, name := "", ""
switch account {
case packages:
return os.Getenv("MESH_GITEA_PACKAGES_TOKEN_FILE")
variable, name = "MESH_GITEA_PACKAGES_TOKEN_FILE", "packages-token"
case tools:
return os.Getenv("MESH_GITEA_TOKEN_FILE")
variable, name = "MESH_GITEA_TOKEN_FILE", "token"
default:
return "", false
}
return ""
if f := os.Getenv(variable); f != "" {
return f, false
}
return filepath.Join(DefaultStateDir, name), true
}
// Follow reads each account's token once the runtime serves, and again at each `secret-changed` naming it, saying
@@ -265,8 +280,12 @@ func Start(logf func(format string, args ...any), held ...*VaultToken) {
case err != nil:
logf("%s is not read at the start (the module mints it): %v", VaultName(t.Account), err)
case t.Source() == SourceFile:
logf("the vault refuses %s to this process's account, so %s's token is read from %s, %s (H-A-564)",
VaultName(t.Account), t.Account, SourceFile, t.File)
how := "named by the manifest"
if t.FileByDefault {
how = "the default path, the manifest naming none"
}
logf("the vault refuses %s to this process's account, so %s's token is read from %s, %s (%s; H-A-564)",
VaultName(t.Account), t.Account, SourceFile, t.File, how)
default:
logf("read %s at generation %d from %s", VaultName(t.Account), t.Generation(), SourceVault)
}