namespace.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 getNamespace deleteNamespace createRelease
  10. type namespacePathParams struct {
  11. // The project id
  12. // in: path
  13. // required: true
  14. // minimum: 1
  15. ProjectID uint `json:"project_id"`
  16. // The cluster id
  17. // in: path
  18. // required: true
  19. // minimum: 1
  20. ClusterID uint `json:"cluster_id"`
  21. // The namespace name
  22. // in: path
  23. // required: true
  24. Namespace string `json:"namespace"`
  25. }
  26. func NewV1NamespaceScopedRegisterer(children ...*router.Registerer) *router.Registerer {
  27. return &router.Registerer{
  28. GetRoutes: GetV1NamespaceScopedRoutes,
  29. Children: children,
  30. }
  31. }
  32. func GetV1NamespaceScopedRoutes(
  33. r chi.Router,
  34. config *config.Config,
  35. basePath *types.Path,
  36. factory shared.APIEndpointFactory,
  37. children ...*router.Registerer,
  38. ) []*router.Route {
  39. routes, projPath := getV1NamespaceRoutes(r, config, basePath, factory)
  40. if len(children) > 0 {
  41. r.Route(projPath.RelativePath, func(r chi.Router) {
  42. for _, child := range children {
  43. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  44. routes = append(routes, childRoutes...)
  45. }
  46. })
  47. }
  48. return routes
  49. }
  50. func getV1NamespaceRoutes(
  51. r chi.Router,
  52. config *config.Config,
  53. basePath *types.Path,
  54. factory shared.APIEndpointFactory,
  55. ) ([]*router.Route, *types.Path) {
  56. relPath := "/namespaces/{namespace}"
  57. newPath := &types.Path{
  58. Parent: basePath,
  59. RelativePath: relPath,
  60. }
  61. var routes []*router.Route
  62. return routes, newPath
  63. }