Skip to content

Commit 0b1fad4

Browse files
committed
Add extra values to API explorer request contexts.
1 parent 4d51bee commit 0b1fad4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

server/console_api_explorer.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import (
1616
"reflect"
1717
"sort"
1818
"strings"
19+
"time"
1920
)
2021

2122
type MethodName string
2223

2324
type rpcReflectCache struct {
2425
endpoints map[MethodName]*methodReflection
25-
rpcs map[MethodName]*console.ApiEndpointDescriptor
26+
rpcs map[MethodName]*console.ApiEndpointDescriptor
2627
}
2728

2829
type methodReflection struct {
@@ -135,10 +136,12 @@ func (s *ConsoleServer) extractApiCallContext(ctx context.Context, in *console.C
135136
s.logger.Error("Error looking up user account.", zap.String("method", in.Method), zap.Error(err))
136137
return nil, status.Error(codes.Internal, "Error looking up user account.")
137138
}
138-
callCtx = context.WithValue(context.WithValue(ctx, ctxUserIDKey{}, userUUID), ctxUsernameKey{}, dbUsername)
139+
callCtx = context.WithValue(ctx, ctxUserIDKey{}, userUUID)
140+
callCtx = context.WithValue(callCtx, ctxUsernameKey{}, dbUsername)
141+
callCtx = context.WithValue(callCtx, ctxVarsKey{}, map[string]string{})
142+
callCtx = context.WithValue(callCtx, ctxExpiryKey{}, time.Now().Add(24*time.Hour).Unix())
139143
}
140144
return callCtx, nil
141-
142145
}
143146

144147
func (s *ConsoleServer) ListApiEndpoints(ctx context.Context, _ *empty.Empty) (*console.ApiEndpointList, error) {
@@ -152,7 +155,7 @@ func (s *ConsoleServer) ListApiEndpoints(ctx context.Context, _ *empty.Empty) (*
152155
for _, name := range endpointNames {
153156
endpoint := s.rpcMethodCache.endpoints[MethodName(name)]
154157
endpoints = append(endpoints, &console.ApiEndpointDescriptor{
155-
Method: name,
158+
Method: name,
156159
BodyTemplate: endpoint.requestBodyTemplate,
157160
})
158161
}
@@ -166,7 +169,7 @@ func (s *ConsoleServer) ListApiEndpoints(ctx context.Context, _ *empty.Empty) (*
166169
for _, name := range rpcs {
167170
endpoint := s.rpcMethodCache.rpcs[MethodName(name)]
168171
rpcEndpoints = append(rpcEndpoints, &console.ApiEndpointDescriptor{
169-
Method: name,
172+
Method: name,
170173
BodyTemplate: endpoint.BodyTemplate,
171174
})
172175
}
@@ -204,7 +207,7 @@ func (s *ConsoleServer) initRpcMethodCache() error {
204207
method: method,
205208
request: request,
206209
requestBodyTemplate: bodyTemplate,
207-
response: method.Type.In(0),
210+
response: method.Type.In(0),
208211
}
209212

210213
}

0 commit comments

Comments
 (0)