/
runtime.go
102 lines (84 loc) · 2.63 KB
/
runtime.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fake
import (
"github.com/google/uuid"
v23 "v.io/v23"
"v.io/v23/context"
"v.io/v23/discovery"
"v.io/v23/namespace"
"v.io/v23/rpc"
"v.io/v23/security"
"v.io/v23/security/access"
"v.io/x/ref/internal/logger"
"v.io/x/ref/lib/flags"
tnaming "v.io/x/ref/runtime/internal/test/mocks/naming"
"v.io/x/ref/test/testutil"
)
type contextKey int
const (
clientKey = contextKey(iota)
principalKey
backgroundKey
listenSpecKey
clientFactoryKey
flowFactoryKey
serverFactoryKey
)
type Runtime struct {
ns namespace.T
}
func newRuntime(ctx *context.T) (*Runtime, *context.T, v23.Shutdown, error) {
ctx = context.WithValue(ctx, principalKey, testutil.NewPrincipal("fake"))
ctx = context.WithLogger(ctx, logger.Global())
return &Runtime{ns: tnaming.NewSimpleNamespace()}, ctx, func() {}, nil
}
func (r *Runtime) Init(ctx *context.T) error {
return nil
}
func (r *Runtime) WithPrincipal(ctx *context.T, principal security.Principal) (*context.T, error) {
return context.WithValue(ctx, principalKey, principal), nil
}
func (r *Runtime) GetPrincipal(ctx *context.T) security.Principal {
// nologcall
p, _ := ctx.Value(principalKey).(security.Principal)
return p
}
func (r *Runtime) WithBackgroundContext(ctx *context.T) *context.T {
// Note we add an extra context with a nil value here.
// This prevents users from travelling back through the
// chain of background contexts.
ctx = context.WithValue(ctx, backgroundKey, nil)
return context.WithValue(ctx, backgroundKey, ctx)
}
func (r *Runtime) GetBackgroundContext(ctx *context.T) *context.T {
// nologcall
bctx, _ := ctx.Value(backgroundKey).(*context.T)
if bctx == nil {
// There should always be a background context. If we don't find
// it, that means that the user passed us the background context
// in hopes of following the chain. Instead we just give them
// back what they sent in, which is correct.
return ctx
}
return bctx
}
func (r *Runtime) GetPermissionsSpec(ctx *context.T) access.PermissionsSpec {
return access.PermissionsSpec{}
}
func (r *Runtime) GetRequestID(ctx *context.T) uuid.UUID {
return uuid.UUID{}
}
func (r *Runtime) NewDiscovery(ctx *context.T) (discovery.T, error) {
panic("unimplemented")
}
func (*Runtime) WithReservedNameDispatcher(ctx *context.T, d rpc.Dispatcher) *context.T {
panic("unimplemented")
}
func (*Runtime) GetReservedNameDispatcher(ctx *context.T) rpc.Dispatcher {
panic("unimplmeneted")
}
func (*Runtime) GetFlags() flags.RuntimeFlags {
return flags.RuntimeFlags{}
}