feat: import Sea vHost single-server testing release
This commit is contained in:
commit
248badd33e
441 files changed
+63221
No files matched your search
@@ -0,0 +1,60 @@
|
||||
// Package scope carries server-authorized placement, never a browser supplied
|
||||
// filesystem path or panel identifier. HTTP handlers bind it after ownership
|
||||
// checks; background work binds it from the persisted resource/job.
|
||||
package scope
|
||||
|
||||
import "context"
|
||||
|
||||
type key uint8
|
||||
|
||||
const (
|
||||
nodeKey key = iota
|
||||
projectKey
|
||||
administratorKey
|
||||
accountKey
|
||||
batchItemKey
|
||||
integrationKey
|
||||
)
|
||||
|
||||
func WithNode(ctx context.Context, id uint64) context.Context {
|
||||
return context.WithValue(ctx, nodeKey, id)
|
||||
}
|
||||
func Node(ctx context.Context) uint64 {
|
||||
if id, ok := ctx.Value(nodeKey).(uint64); ok && id > 0 {
|
||||
return id
|
||||
}
|
||||
return 1
|
||||
}
|
||||
func ExplicitNode(ctx context.Context) (uint64, bool) {
|
||||
id, ok := ctx.Value(nodeKey).(uint64)
|
||||
return id, ok && id > 0
|
||||
}
|
||||
func WithProject(ctx context.Context, projectID, nodeID uint64) context.Context {
|
||||
return context.WithValue(WithNode(ctx, nodeID), projectKey, projectID)
|
||||
}
|
||||
func Project(ctx context.Context) uint64 { id, _ := ctx.Value(projectKey).(uint64); return id }
|
||||
func WithAdministrator(ctx context.Context, id uint64) context.Context {
|
||||
return context.WithValue(ctx, administratorKey, id)
|
||||
}
|
||||
func Administrator(ctx context.Context) uint64 {
|
||||
id, _ := ctx.Value(administratorKey).(uint64)
|
||||
return id
|
||||
}
|
||||
|
||||
// Account identifies the authenticated customer account independently from a
|
||||
// host's immutable internal namespace. Only HTTP authorization binds this value.
|
||||
func WithAccount(ctx context.Context, id uint64) context.Context {
|
||||
return context.WithValue(ctx, accountKey, id)
|
||||
}
|
||||
func Account(ctx context.Context) uint64 { id, _ := ctx.Value(accountKey).(uint64); return id }
|
||||
func WithBatchItem(ctx context.Context, id uint64) context.Context {
|
||||
return context.WithValue(ctx, batchItemKey, id)
|
||||
}
|
||||
func BatchItem(ctx context.Context) uint64 { id, _ := ctx.Value(batchItemKey).(uint64); return id }
|
||||
func WithIntegrationKey(ctx context.Context, id uint64) context.Context {
|
||||
return context.WithValue(ctx, integrationKey, id)
|
||||
}
|
||||
func IntegrationKey(ctx context.Context) uint64 {
|
||||
id, _ := ctx.Value(integrationKey).(uint64)
|
||||
return id
|
||||
}
|
||||
Reference in new issue
Block a user