| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066 |
- package router
- import (
- "fmt"
- "github.com/go-chi/chi"
- "github.com/porter-dev/porter/api/server/handlers/cluster"
- "github.com/porter-dev/porter/api/server/handlers/database"
- "github.com/porter-dev/porter/api/server/handlers/environment"
- "github.com/porter-dev/porter/api/server/handlers/kube_events"
- "github.com/porter-dev/porter/api/server/shared"
- "github.com/porter-dev/porter/api/server/shared/config"
- "github.com/porter-dev/porter/api/types"
- )
- func NewClusterScopedRegisterer(children ...*Registerer) *Registerer {
- return &Registerer{
- GetRoutes: GetClusterScopedRoutes,
- Children: children,
- }
- }
- func GetClusterScopedRoutes(
- r chi.Router,
- config *config.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- children ...*Registerer,
- ) []*Route {
- routes, projPath := getClusterRoutes(r, config, basePath, factory)
- if len(children) > 0 {
- r.Route(projPath.RelativePath, func(r chi.Router) {
- for _, child := range children {
- childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
- routes = append(routes, childRoutes...)
- }
- })
- }
- return routes
- }
- func getClusterRoutes(
- r chi.Router,
- config *config.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- ) ([]*Route, *types.Path) {
- relPath := "/clusters/{cluster_id}"
- newPath := &types.Path{
- Parent: basePath,
- RelativePath: relPath,
- }
- routes := make([]*Route, 0)
- // POST /api/projects/{project_id}/clusters -> project.NewCreateClusterManualHandler
- createEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/clusters",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- },
- },
- )
- createHandler := cluster.NewCreateClusterManualHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: createEndpoint,
- Handler: createHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/candidates -> project.NewCreateClusterCandidateHandler
- createCandidateEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/clusters/candidates",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- },
- CheckUsage: true,
- UsageMetric: types.Clusters,
- },
- )
- createCandidateHandler := cluster.NewCreateClusterCandidateHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: createCandidateEndpoint,
- Handler: createCandidateHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/candidates -> project.NewListClusterCandidatesHandler
- listCandidatesEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbList,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/clusters/candidates",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- },
- },
- )
- listCandidatesHandler := cluster.NewListClusterCandidatesHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: listCandidatesEndpoint,
- Handler: listCandidatesHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/candidates/{candidate_id}/resolve -> project.NewResolveClusterCandidateHandler
- resolveCandidateEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf(
- "/clusters/candidates/{%s}/resolve",
- types.URLParamCandidateID,
- ),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- },
- CheckUsage: true,
- UsageMetric: types.Clusters,
- },
- )
- resolveCandidateHandler := cluster.NewResolveClusterCandidateHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: resolveCandidateEndpoint,
- Handler: resolveCandidateHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id} -> project.NewClusterUpdateHandler
- updateClusterEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbUpdate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath,
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- updateClusterHandler := cluster.NewClusterUpdateHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: updateClusterEndpoint,
- Handler: updateClusterHandler,
- Router: r,
- })
- // DELETE /api/projects/{project_id}/clusters/{cluster_id} -> project.NewClusterDeleteHandler
- deleteClusterEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbDelete,
- Method: types.HTTPVerbDelete,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath,
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- deleteClusterHandler := cluster.NewClusterDeleteHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: deleteClusterEndpoint,
- Handler: deleteClusterHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id} -> project.NewClusterGetHandler
- getEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath,
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getHandler := cluster.NewClusterGetHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getEndpoint,
- Handler: getHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/databases -> database.NewDatabaseListHandler
- listDatabaseEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbList,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/databases",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- listDatabaseHandler := database.NewDatabaseListHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: listDatabaseEndpoint,
- Handler: listDatabaseHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/environments -> environment.NewListEnvironmentHandler
- listEnvEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/environments",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- listEnvHandler := environment.NewListEnvironmentHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: listEnvEndpoint,
- Handler: listEnvHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/deployments -> environment.NewListDeploymentsByClusterHandler
- listDeploymentsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/deployments",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- listDeploymentsHandler := environment.NewListDeploymentsByClusterHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: listDeploymentsEndpoint,
- Handler: listDeploymentsHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/{environment_id}/deployment -> environment.NewGetDeploymentByClusterHandler
- getDeploymentEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/{environment_id}/deployment",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getDeploymentHandler := environment.NewGetDeploymentByClusterHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getDeploymentEndpoint,
- Handler: getDeploymentHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces -> cluster.NewClusterListNamespacesHandler
- listNamespacesEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/namespaces",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- listNamespacesHandler := cluster.NewListNamespacesHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: listNamespacesEndpoint,
- Handler: listNamespacesHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes -> cluster.NewListNodesHandler
- listNodesEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/nodes",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- listNodesHandler := cluster.NewListNodesHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: listNodesEndpoint,
- Handler: listNodesHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes/{node_name} -> cluster.NewGetNodeHandler
- getNodeEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/nodes/{%s}", relPath, types.URLParamNodeName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getNodeHandler := cluster.NewGetNodeHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getNodeEndpoint,
- Handler: getNodeHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/create -> cluster.NewCreateNamespaceHandler
- createNamespaceEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/namespaces/create",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- createNamespaceHandler := cluster.NewCreateNamespaceHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: createNamespaceEndpoint,
- Handler: createNamespaceHandler,
- Router: r,
- })
- // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/delete -> cluster.NewDeleteNamespaceHandler
- deleteNamespaceEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbDelete,
- Method: types.HTTPVerbDelete,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/namespaces/delete",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- deleteNamespaceHandler := cluster.NewDeleteNamespaceHandler(
- config,
- factory.GetDecoderValidator(),
- )
- routes = append(routes, &Route{
- Endpoint: deleteNamespaceEndpoint,
- Handler: deleteNamespaceHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/kubeconfig -> cluster.NewGetTemporaryKubeconfigHandler
- getTemporaryKubeconfigEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/kubeconfig",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getTemporaryKubeconfigHandler := cluster.NewGetTemporaryKubeconfigHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getTemporaryKubeconfigEndpoint,
- Handler: getTemporaryKubeconfigHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/detect -> cluster.NewDetectPrometheusInstalledHandler
- detectPrometheusInstalledEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/prometheus/detect",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- detectPrometheusInstalledHandler := cluster.NewDetectPrometheusInstalledHandler(config)
- routes = append(routes, &Route{
- Endpoint: detectPrometheusInstalledEndpoint,
- Handler: detectPrometheusInstalledHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/agent/detect -> cluster.NewDetectAgentInstalledHandler
- detectAgentInstalledEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/agent/detect",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- detectAgentInstalledHandler := cluster.NewDetectAgentInstalledHandler(config, factory.GetResultWriter())
- routes = append(routes, &Route{
- Endpoint: detectAgentInstalledEndpoint,
- Handler: detectAgentInstalledHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/agent/install -> cluster.NewInstallAgentHandler
- installAgentEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/agent/install",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- installAgentHandler := cluster.NewInstallAgentHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: installAgentEndpoint,
- Handler: installAgentHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/agent/upgrade -> cluster.NewInstallAgentHandler
- upgradeAgentEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/agent/upgrade",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- upgradeAgentHandler := cluster.NewUpgradeAgentHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: upgradeAgentEndpoint,
- Handler: upgradeAgentHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewGetKubeEventHandler
- listKubeEventsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/kube_events",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- listKubeEventsHandler := kube_events.NewListKubeEventsHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: listKubeEventsEndpoint,
- Handler: listKubeEventsHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewGetKubeEventHandler
- getKubeEventEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/kube_events/{%s}", relPath, types.URLParamKubeEventID),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getKubeEventHandler := kube_events.NewGetKubeEventHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getKubeEventEndpoint,
- Handler: getKubeEventHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events/{kube_event_id}/logs -> kube_events.NewGetKubeEventLogsHandler
- getKubeEventLogsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/kube_events/{%s}/logs", relPath, types.URLParamKubeEventID),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getKubeEventLogsHandler := kube_events.NewGetKubeEventLogsHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getKubeEventLogsEndpoint,
- Handler: getKubeEventLogsHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events/{kube_event_id}/log_buckets -> kube_events.NewGetKubeEventLogBucketsHandler
- getKubeEventLogBucketsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/kube_events/{%s}/log_buckets", relPath, types.URLParamKubeEventID),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getKubeEventLogBucketsHandler := kube_events.NewGetKubeEventLogBucketsHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getKubeEventLogBucketsEndpoint,
- Handler: getKubeEventLogBucketsHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewCreateKubeEventHandler
- createKubeEventsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/kube_events",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- createKubeEventsHandler := kube_events.NewCreateKubeEventHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: createKubeEventsEndpoint,
- Handler: createKubeEventsHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/ingresses -> cluster.NewListNGINXIngressesHandler
- listNGINXIngressesEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/prometheus/ingresses",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- listNGINXIngressesHandler := cluster.NewListNGINXIngressesHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: listNGINXIngressesEndpoint,
- Handler: listNGINXIngressesHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/metrics -> cluster.NewGetPodMetricsHandler
- getPodMetricsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/metrics",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getPodMetricsHandler := cluster.NewGetPodMetricsHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getPodMetricsEndpoint,
- Handler: getPodMetricsHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/helm_release -> cluster.NewStreamHelmReleaseHandler
- streamHelmReleaseEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/helm_release",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- IsWebsocket: true,
- },
- )
- streamHelmReleaseHandler := cluster.NewStreamHelmReleaseHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: streamHelmReleaseEndpoint,
- Handler: streamHelmReleaseHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/{kind}/status -> cluster.NewStreamStatusHandler
- streamStatusEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf(
- "%s/{%s}/status",
- relPath,
- types.URLParamKind,
- ),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- IsWebsocket: true,
- },
- )
- streamStatusHandler := cluster.NewStreamStatusHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: streamStatusEndpoint,
- Handler: streamStatusHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/pods -> cluster.NewGetPodsHandler
- getPodsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/pods",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getPodsHandler := cluster.NewGetPodsHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getPodsEndpoint,
- Handler: getPodsHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/incidents -> cluster.NewGetIncidentsHandler
- getIncidentsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/incidents",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getIncidentsHandler := cluster.NewGetIncidentsHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getIncidentsEndpoint,
- Handler: getIncidentsHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/incidents/logs -> cluster.NewGetIncidentsHandler
- getIncidentEventLogsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/incidents/logs",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getIncidentEventLogsHandler := cluster.NewGetIncidentEventLogsHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getIncidentEventLogsEndpoint,
- Handler: getIncidentEventLogsHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/incidents/notify_new -> cluster.NewNotifyNewIncidentHandler
- notifyNewIncidentEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/incidents/notify_new",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- notifyNewIncidentHandler := cluster.NewNotifyNewIncidentHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: notifyNewIncidentEndpoint,
- Handler: notifyNewIncidentHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/incidents/notify_resolved -> cluster.NewNotifyResolvedIncidentHandler
- notifyResolvedIncidentEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/incidents/notify_resolved",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- notifyResolvedIncidentHandler := cluster.NewNotifyResolvedIncidentHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: notifyResolvedIncidentEndpoint,
- Handler: notifyResolvedIncidentHandler,
- Router: r,
- })
- return routes, newPath
- }
|