MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / getFunction

Method getFunction

pkg/controller/invoke.go:116–178  ·  view source on GitHub ↗
(ctx *InvokeContext)

Source from the content-addressed store, hash-verified

114}
115
116func (controller *Controller) getFunction(ctx *InvokeContext) (hitCache bool, err error) {
117 if ctx.RunOptions.RecommendedOptions.Features.EnableMetrics {
118 ctx.Metrics.StepStart(StageGetFunction)
119 ctx.Metrics.StepStart(StageGetFunctionHitCache)
120 defer func() {
121 if hitCache {
122 ctx.Metrics.StepDone(StageGetFunctionHitCache)
123 ctx.Metrics.ScrapStage(StageGetFunction)
124 } else {
125 ctx.Metrics.StepDone(StageGetFunction)
126 ctx.Metrics.ScrapStage(StageGetFunctionHitCache)
127 }
128 ctx.Metrics.SetLabel(getFunctionBrnLabel, ctx.FunctionBRN)
129 ctx.Metrics.SetLabel(getFunctionHitCacheLabel, strconv.FormatBool(hitCache))
130 }()
131 }
132
133 ctx.Logger.V(9).Info("get function configuration")
134 hitCache = false
135
136 input := api.GetFunctionInput{
137 Authorization: ctx.Authorization,
138 RequestID: ctx.RequestID,
139 AccountID: ctx.AccountID,
140 WithCache: true,
141 }
142
143 if ctx.InvokeType == api.InvokeTypeEvent || ctx.InvokeType == api.InvokeTypeHttpTrigger || ctx.InvokeType == api.InvokeTypeMqhub {
144 input.SimpleAuth = true
145 }
146 if ctx.TriggerType == api.TriggerTypeVscode {
147 input.SimpleAuth = true
148 }
149
150 if ctx.FunctionBRN != "" {
151 hitCache, err = controller.getFunctionByFunctionBrn(ctx, &input)
152 } else {
153 hitCache, err = controller.getFunctionByFunctionName(ctx, &input)
154 }
155 if err != nil {
156 return false, err
157 }
158
159 ctx.OwnerUser = &api.User{
160 ID: ctx.Function.Configuration.Uid,
161 }
162
163 // TODO: implement the authenticate policies
164
165 // TODO: or caller user has access to invoke function?
166 if controller.runOptions.SimpleAuth {
167 if ctx.AccountID != ctx.OwnerUser.ID {
168 ctx.Logger.Warnf("invalid caller id, owner id %s caller id %s", ctx.OwnerUser.ID, ctx.AccountID)
169 err = innerErr.NewInvalidInvokeCallerException(fmt.Sprintf("owner id %s caller id %s", ctx.OwnerUser.ID, ctx.AccountID), nil)
170 return
171 }
172 }
173

Callers 1

DoMethod · 0.95

Calls 11

StepStartMethod · 0.80
ScrapStageMethod · 0.80
SetLabelMethod · 0.80
VMethod · 0.80
WarnfMethod · 0.80
DebugfMethod · 0.80
InfofMethod · 0.80
InfoMethod · 0.65
StepDoneMethod · 0.45

Tested by

no test coverage detected