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

Function updateProjectOAuthConfig

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

Source from the content-addressed store, hash-verified

474}
475
476func updateProjectOAuthConfig(c *gin.Context) {
477 r := struct {
478 DB proto.DatabaseID `json:"db" json:"project" form:"db" form:"project" uri:"db" uri:"project" binding:"required,len=64"`
479 Provider string `json:"provider" form:"provider" uri:"provider" binding:"required,max=256"`
480 model.ProjectOAuthConfig
481 // additional parameters, see ProjectOAuthConfig structure
482 }{}
483
484 _ = c.ShouldBindUri(&r)
485
486 if err := c.ShouldBind(&r); err != nil {
487 abortWithError(c, http.StatusBadRequest, err)
488 return
489 }
490
491 _, projectDB, err := getProjectDB(c, r.DB)
492 if err != nil {
493 _ = c.Error(err)
494 abortWithError(c, http.StatusForbidden, ErrLoadProjectDatabaseFailed)
495 return
496 }
497
498 cfg := &r.ProjectOAuthConfig
499
500 if cfg.ClientID == "" && cfg.ClientSecret == "" {
501 // update nothing
502 _ = c.Error(err)
503 abortWithError(c, http.StatusBadRequest, ErrIncompleteOAuthConfig)
504 return
505 }
506
507 var (
508 p *model.ProjectConfig
509 poc *model.ProjectOAuthConfig
510 )
511
512 p, poc, err = model.GetProjectOAuthConfig(projectDB, r.Provider)
513 if err != nil {
514 // not exists, create
515 if cfg.ClientID == "" || cfg.ClientSecret == "" {
516 abortWithError(c, http.StatusBadRequest, ErrIncompleteOAuthConfig)
517 return
518 }
519 p, err = model.AddProjectConfig(projectDB, model.ProjectConfigOAuth, r.Provider, cfg)
520 if err != nil {
521 _ = c.Error(err)
522 abortWithError(c, http.StatusInternalServerError, ErrAddProjectOAuthConfigFailed)
523 return
524 }
525 poc = cfg
526 } else {
527 // update config
528 if cfg.ClientID != "" {
529 poc.ClientID = cfg.ClientID
530 }
531 if cfg.ClientSecret != "" {
532 poc.ClientSecret = cfg.ClientSecret
533 }

Callers

nothing calls this directly

Calls 7

GetProjectOAuthConfigFunction · 0.92
AddProjectConfigFunction · 0.92
UpdateProjectConfigFunction · 0.92
abortWithErrorFunction · 0.85
getProjectDBFunction · 0.85
responseWithDataFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected