(c *gin.Context)
| 427 | } |
| 428 | |
| 429 | func 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 | |
| 476 | func updateProjectOAuthConfig(c *gin.Context) { |
| 477 | r := struct { |
nothing calls this directly
no test coverage detected