project.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package v1
  2. import (
  3. "github.com/go-chi/chi"
  4. "github.com/porter-dev/porter/api/server/shared"
  5. "github.com/porter-dev/porter/api/server/shared/config"
  6. "github.com/porter-dev/porter/api/server/shared/router"
  7. "github.com/porter-dev/porter/api/types"
  8. )
  9. // swagger:parameters createRegistry listRegistries
  10. type projectPathParams struct {
  11. // The project id
  12. // in: path
  13. // required: true
  14. // minimum: 1
  15. ProjectID uint `json:"project_id"`
  16. }
  17. func NewV1ProjectScopedRegisterer(children ...*router.Registerer) *router.Registerer {
  18. return &router.Registerer{
  19. GetRoutes: GetV1ProjectScopedRoutes,
  20. Children: children,
  21. }
  22. }
  23. func GetV1ProjectScopedRoutes(
  24. r chi.Router,
  25. config *config.Config,
  26. basePath *types.Path,
  27. factory shared.APIEndpointFactory,
  28. children ...*router.Registerer,
  29. ) []*router.Route {
  30. routes, projPath := getV1ProjectRoutes(r, config, basePath, factory)
  31. if len(children) > 0 {
  32. r.Route(projPath.RelativePath, func(r chi.Router) {
  33. for _, child := range children {
  34. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  35. routes = append(routes, childRoutes...)
  36. }
  37. })
  38. }
  39. return routes
  40. }
  41. func getV1ProjectRoutes(
  42. r chi.Router,
  43. config *config.Config,
  44. basePath *types.Path,
  45. factory shared.APIEndpointFactory,
  46. ) ([]*router.Route, *types.Path) {
  47. relPath := "/projects/{project_id}"
  48. newPath := &types.Path{
  49. Parent: basePath,
  50. RelativePath: relPath,
  51. }
  52. var routes []*router.Route
  53. return routes, newPath
  54. }