MCPcopy Index your code
hub / github.com/smallstep/cli / InjectContext

Function InjectContext

internal/command/inject.go:14–23  ·  view source on GitHub ↗

InjectContext injects an existing Context as the first middleware and then wraps a function with middleware using that context. It returns a cli.ActionFunc with the cli.Context added to the Context. By injecting the existing context as the first middleware, we ensure that it's the Context all later

(injectedCtx context.Context, fn func(context.Context) error, middleware ...func(context.Context) (context.Context, error))

Source from the content-addressed store, hash-verified

12// By injecting the existing context as the first middleware, we ensure
13// that it's the Context all later middlewares operate on.
14func InjectContext(injectedCtx context.Context, fn func(context.Context) error, middleware ...func(context.Context) (context.Context, error)) cli.ActionFunc {
15 injectedMiddleware := []func(context.Context) (context.Context, error){
16 func(context.Context) (context.Context, error) {
17 return injectedCtx, nil
18 },
19 }
20 injectedMiddleware = append(injectedMiddleware, middleware...)
21 //nolint:contextcheck // context is injected in fn
22 return wrap(fn, injectedMiddleware...)
23}
24
25type cliCtxKey struct{}
26

Callers 13

EmailCommandFunction · 0.92
RemoveCommandFunction · 0.92
DNSCommandFunction · 0.92
PrincipalsCommandFunction · 0.92
CommonNamesCommandFunction · 0.92
IPCommandFunction · 0.92
URICommandFunction · 0.92
ViewCommandFunction · 0.92
allowWildcardsCommandFunction · 0.92
denyWildcardsCommandFunction · 0.92
TestInjectContextFunction · 0.85

Calls 1

wrapFunction · 0.85

Tested by 3

TestInjectContextFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…