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

Function getProjectOAuthCallback

cmd/cql-proxy/api/project.go:429–474  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

427}
428
429func getProjectOAuthCallback(c *gin.Context) {
430 r := struct {
431 DB proto.DatabaseID `json:"db" json:"project" form:"db" form:"project" uri:"db" uri:"project" binding:"required,len=64"`
432 Provider string `json:"provider" form:"provider" uri:"provider" binding:"required,max=256"`
433 }{}
434
435 _ = c.ShouldBindUri(&r)
436
437 if err := c.ShouldBind(&r); err != nil {
438 abortWithError(c, http.StatusBadRequest, err)
439 return
440 }
441
442 developer := getDeveloperID(c)
443
444 p, err := model.GetProjectByID(model.GetDB(c), r.DB, developer)
445 if err != nil {
446 _ = c.Error(err)
447 abortWithError(c, http.StatusForbidden, ErrGetProjectFailed)
448 return
449 }
450
451 cfg := getConfig(c)
452 if cfg == nil || len(cfg.Hosts) == 0 {
453 abortWithError(c, http.StatusInternalServerError, ErrNoPublicServiceHosts)
454 return
455 }
456
457 var (
458 authorize []string
459 callback []string
460 )
461
462 for _, h := range cfg.Hosts {
463 // project alias happy and host api.covenantsql.io will produce happy.api.covenantsql.io as service host
464 authorize = append(authorize,
465 fmt.Sprintf("http://%s.%s/auth/authorize/%s", p.Alias, strings.TrimLeft(h, "."), r.Provider))
466 callback = append(callback,
467 fmt.Sprintf("http://%s.%s/auth/callback/%s", p.Alias, strings.TrimLeft(h, "."), r.Provider))
468 }
469
470 responseWithData(c, http.StatusOK, gin.H{
471 "authorizes": authorize,
472 "callbacks": callback,
473 })
474}
475
476func updateProjectOAuthConfig(c *gin.Context) {
477 r := struct {

Callers

nothing calls this directly

Calls 7

GetProjectByIDFunction · 0.92
GetDBFunction · 0.92
abortWithErrorFunction · 0.85
getDeveloperIDFunction · 0.85
getConfigFunction · 0.85
responseWithDataFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected