(ctx *InvokeContext)
| 114 | } |
| 115 | |
| 116 | func (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 |
no test coverage detected