MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / projectIDInject

Function projectIDInject

cmd/cql-proxy/api/user_oauth.go:291–342  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

289}
290
291func projectIDInject(c *gin.Context) {
292 // load project alias
293 cfg := getConfig(c)
294 if cfg == nil || len(cfg.Hosts) == 0 {
295 abortWithError(c, http.StatusInternalServerError, ErrNoPublicServiceHosts)
296 return
297 }
298
299 host := c.Request.Host
300 var (
301 p *model.Project
302 err error
303 )
304
305 for _, h := range cfg.Hosts {
306 if strings.HasSuffix(host, h) {
307 // treat prefix as string
308 projectAlias := strings.TrimRight(host[:len(host)-len(h)], ".")
309 p, err = model.GetProject(model.GetDB(c), projectAlias)
310 if err == nil {
311 break
312 }
313 }
314 }
315
316 // try use uri/json/form arguments
317 if p == nil {
318 r := struct {
319 Project string `form:"project" uri:"project" binding:"required,len=64"`
320 }{}
321
322 _ = c.ShouldBindUri(&r)
323
324 // should not use ShouldBind, json form bind is not repeatable
325 if err = c.ShouldBindQuery(&r); err != nil {
326 abortWithError(c, http.StatusBadRequest, err)
327 return
328 }
329
330 p, err = model.GetProject(model.GetDB(c), r.Project)
331 }
332
333 if p != nil {
334 c.Set("project", p)
335 } else {
336 _ = c.Error(err)
337 abortWithError(c, http.StatusBadRequest, ErrGetProjectFailed)
338 return
339 }
340
341 c.Next()
342}
343
344func getUserInfo(c *gin.Context) {
345 projectDB, err := getCurrentProjectDB(c)

Callers

nothing calls this directly

Calls 7

GetProjectFunction · 0.92
GetDBFunction · 0.92
getConfigFunction · 0.85
abortWithErrorFunction · 0.85
ErrorMethod · 0.80
SetMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected