cluster_integration.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package router
  2. import (
  3. "github.com/go-chi/chi"
  4. awsClusterInt "github.com/porter-dev/porter/api/server/handlers/cluster_integration/aws"
  5. "github.com/porter-dev/porter/api/server/shared"
  6. "github.com/porter-dev/porter/api/server/shared/config"
  7. "github.com/porter-dev/porter/api/server/shared/router"
  8. "github.com/porter-dev/porter/api/types"
  9. )
  10. func NewClusterIntegrationScopedRegisterer(children ...*router.Registerer) *router.Registerer {
  11. return &router.Registerer{
  12. GetRoutes: GetClusterIntegrationScopedRoutes,
  13. Children: children,
  14. }
  15. }
  16. func GetClusterIntegrationScopedRoutes(
  17. r chi.Router,
  18. config *config.Config,
  19. basePath *types.Path,
  20. factory shared.APIEndpointFactory,
  21. children ...*router.Registerer,
  22. ) []*router.Route {
  23. routes, projPath := getClusterIntegrationRoutes(r, config, basePath, factory)
  24. if len(children) > 0 {
  25. r.Route(projPath.RelativePath, func(r chi.Router) {
  26. for _, child := range children {
  27. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  28. routes = append(routes, childRoutes...)
  29. }
  30. })
  31. }
  32. return routes
  33. }
  34. func getClusterIntegrationRoutes(
  35. r chi.Router,
  36. config *config.Config,
  37. basePath *types.Path,
  38. factory shared.APIEndpointFactory,
  39. ) ([]*router.Route, *types.Path) {
  40. relPath := "/integrations"
  41. newPath := &types.Path{
  42. Parent: basePath,
  43. RelativePath: relPath,
  44. }
  45. routes := make([]*router.Route, 0)
  46. // GET /api/projects/{project_id}/clusters/{cluster_id}/integrations/aws/info -> awsClusterInt.NewGetClusterInfoHandler
  47. getAWSClusterInfoEndpoint := factory.NewAPIEndpoint(
  48. &types.APIRequestMetadata{
  49. Verb: types.APIVerbGet,
  50. Method: types.HTTPVerbGet,
  51. Path: &types.Path{
  52. Parent: basePath,
  53. RelativePath: relPath + "/aws/info",
  54. },
  55. Scopes: []types.PermissionScope{
  56. types.UserScope,
  57. types.ProjectScope,
  58. types.ClusterScope,
  59. },
  60. },
  61. )
  62. getAWSClusterInfoHandler := awsClusterInt.NewGetClusterInfoHandler(
  63. config,
  64. factory.GetDecoderValidator(),
  65. factory.GetResultWriter(),
  66. )
  67. routes = append(routes, &router.Route{
  68. Endpoint: getAWSClusterInfoEndpoint,
  69. Handler: getAWSClusterInfoHandler,
  70. Router: r,
  71. })
  72. return routes, newPath
  73. }