Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s
- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名) - 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块) - docreader proto 描述符采用等长替换,保持序列化字节布局有效 - Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像 - 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package allocation
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/binary"
|
|
"encoding/hex"
|
|
"errors"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// UserMachine is the logical identity of one shared machine: one owner, one
|
|
// sandbox config. It is comparable so it can key maps. ConfigID must already
|
|
// be normalized (sandbox.NormalizeConfigID) and ConfigTenantID resolved.
|
|
type UserMachine struct {
|
|
OwnerTenantID uint64
|
|
OwnerID string
|
|
ConfigTenantID uint64
|
|
ConfigID string
|
|
}
|
|
|
|
// Validate rejects identities that cannot address a machine.
|
|
func (m UserMachine) Validate() error {
|
|
if m.OwnerTenantID == 0 {
|
|
return errors.New("allocation: user machine requires an owner tenant")
|
|
}
|
|
if err := ValidateOwnerID(m.OwnerID); err != nil {
|
|
return err
|
|
}
|
|
if m.ConfigTenantID == 0 {
|
|
return errors.New("allocation: user machine requires a resolved config tenant")
|
|
}
|
|
if strings.TrimSpace(m.ConfigID) == "" {
|
|
return errors.New("allocation: user machine requires a config id")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Digest is the hex SHA-256 of a length-prefixed canonical encoding, so no
|
|
// two identities share a digest by field-boundary ambiguity. The namespace is
|
|
// part of it: two deployments sharing one Redis never address each other's
|
|
// machines. It is the Redis hash tag, the DB key and the provider metadata.
|
|
func (m UserMachine) Digest(namespace string) string {
|
|
h := sha256.New()
|
|
write := func(s string) {
|
|
var n [8]byte
|
|
binary.BigEndian.PutUint64(n[:], uint64(len(s)))
|
|
h.Write(n[:])
|
|
h.Write([]byte(s))
|
|
}
|
|
write("academy-user-sandbox/v1")
|
|
write(namespace)
|
|
write(strconv.FormatUint(m.OwnerTenantID, 10))
|
|
write(m.OwnerID)
|
|
write(strconv.FormatUint(m.ConfigTenantID, 10))
|
|
write(m.ConfigID)
|
|
return hex.EncodeToString(h.Sum(nil))
|
|
}
|