| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069 |
- package router
- import (
- "fmt"
- "github.com/go-chi/chi/v5"
- "github.com/porter-dev/porter/api/server/handlers/porter_app"
- "github.com/porter-dev/porter/api/server/shared"
- "github.com/porter-dev/porter/api/server/shared/config"
- "github.com/porter-dev/porter/api/server/shared/router"
- "github.com/porter-dev/porter/api/types"
- )
- func NewPorterAppScopedRegisterer(children ...*router.Registerer) *router.Registerer {
- return &router.Registerer{
- GetRoutes: GetPorterAppScopedRoutes,
- Children: children,
- }
- }
- func GetPorterAppScopedRoutes(
- r chi.Router,
- config *config.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- children ...*router.Registerer,
- ) []*router.Route {
- routes, projPath := getPorterAppRoutes(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 getPorterAppRoutes(
- r chi.Router,
- config *config.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- ) ([]*router.Route, *types.Path) {
- relPath := "/applications"
- newPath := &types.Path{
- Parent: basePath,
- RelativePath: relPath,
- }
- var routes []*router.Route
- // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/{name} -> porter_app.NewPorterAppGetHandler
- getPorterAppEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/{%s}", relPath, types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getPorterAppHandler := porter_app.NewGetPorterAppHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: getPorterAppEndpoint,
- Handler: getPorterAppHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/{name}/releases/{version} -> porter_app.NewPorterAppReleaseGetHandler
- getPorterAppHelmReleaseEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbList,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/{%s}/releases/{%s}", relPath, types.URLParamPorterAppName, types.URLParamReleaseVersion),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getPorterAppHelmReleaseHandler := porter_app.NewPorterAppHelmReleaseGetHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: getPorterAppHelmReleaseEndpoint,
- Handler: getPorterAppHelmReleaseHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/{name}/release-history -> porter_app.NewPorterAppHelmReleaseHistoryGetHandler
- getPorterAppHelmReleaseHistoryGetEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbList,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/{%s}/release-history", relPath, types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getPorterAppHelmReleaseHistoryGetHandler := porter_app.NewPorterAppHelmReleaseHistoryGetHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: getPorterAppHelmReleaseHistoryGetEndpoint,
- Handler: getPorterAppHelmReleaseHistoryGetHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/{name}/releases/{version}/pods/all -> porter_app.NewPorterAppPodsGetHandler
- getPorterAppPodsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbList,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/{%s}/releases/{%s}/pods/all", relPath, types.URLParamPorterAppName, types.URLParamReleaseVersion),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getPorterAppPodsHandler := porter_app.NewPorterAppPodsGetHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: getPorterAppPodsEndpoint,
- Handler: getPorterAppPodsHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/applications -> porter_app.NewPorterAppListHandler
- listPorterAppEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbList,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath,
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- listPorterAppHandler := porter_app.NewPorterAppListHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: listPorterAppEndpoint,
- Handler: listPorterAppHandler,
- Router: r,
- })
- // DELETE /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name} -> release.NewDeletePorterAppByNameHandler
- deletePorterAppByNameEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbDelete,
- Method: types.HTTPVerbDelete,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/{%s}", relPath, types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- deletePorterAppByNameHandler := porter_app.NewDeletePorterAppByNameHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: deletePorterAppByNameEndpoint,
- Handler: deletePorterAppByNameHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name} -> porter_app.NewCreatePorterAppHandler
- createPorterAppEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/{%s}", relPath, types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- createPorterAppHandler := porter_app.NewCreatePorterAppHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: createPorterAppEndpoint,
- Handler: createPorterAppHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name}/rollback -> porter_app.NewRollbackPorterAppHandler
- rollbackPorterAppEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/{%s}/rollback", relPath, types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- rollbackPorterAppHandler := porter_app.NewRollbackPorterAppHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: rollbackPorterAppEndpoint,
- Handler: rollbackPorterAppHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name}/pr -> porter_app.NewOpenStackPRHandler
- createSecretAndOpenGitHubPullRequestEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/{%s}/pr", relPath, types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- createSecretAndOpenGitHubPullRequestHandler := porter_app.NewOpenStackPRHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: createSecretAndOpenGitHubPullRequestEndpoint,
- Handler: createSecretAndOpenGitHubPullRequestHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name}/events -> porter_app.NewPorterAppEventListHandler
- listPorterAppEventsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbList,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/{%s}/events", relPath, types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- listPorterAppEventsHandler := porter_app.NewPorterAppEventListHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: listPorterAppEventsEndpoint,
- Handler: listPorterAppEventsHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{name}/events -> porter_app.NewCreatePorterAppEventHandler
- createPorterAppEventEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/{%s}/events", relPath, types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- createPorterAppEventHandler := porter_app.NewCreateUpdatePorterAppEventHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: createPorterAppEventEndpoint,
- Handler: createPorterAppEventHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/events/id -> porter_app.NewGetPorterAppEventHandler
- getPorterAppEventEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("/events/{%s}", types.URLParamPorterAppEventID),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getPorterAppEventHandler := porter_app.NewGetPorterAppEventHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: getPorterAppEventEndpoint,
- Handler: getPorterAppEventHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/analytics -> porter_app.NewPorterAppAnalyticsHandler
- porterAppAnalyticsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbUpdate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/analytics", relPath),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- porterAppAnalyticsHandler := porter_app.NewPorterAppAnalyticsHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: porterAppAnalyticsEndpoint,
- Handler: porterAppAnalyticsHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/logs -> cluster.NewGetChartLogsWithinTimeRangeHandler
- getChartLogsWithinTimeRangeEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/logs", relPath),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getChartLogsWithinTimeRangeHandler := porter_app.NewGetLogsWithinTimeRangeHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: getChartLogsWithinTimeRangeEndpoint,
- Handler: getChartLogsWithinTimeRangeHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name}/run -> porter_app.NewRunPorterAppCommandHandler
- runPorterAppCommandEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("%s/{%s}/run", relPath, types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- runPorterAppCommandHandler := porter_app.NewRunPorterAppCommandHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: runPorterAppCommandEndpoint,
- Handler: runPorterAppCommandHandler,
- Router: r,
- })
- // TODO: remove these three endpoints once these three 'stacks' routes are no longer used in telemetry
- // GET /api/projects/{project_id}/clusters/{cluster_id}/stacks/{name} -> porter_app.NewPorterAppGetHandler
- LEGACY_getPorterAppEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("/stacks/{%s}", types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- LEGACY_getPorterAppHandler := porter_app.NewGetPorterAppHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: LEGACY_getPorterAppEndpoint,
- Handler: LEGACY_getPorterAppHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/stacks/{porter_app_name} -> porter_app.NewCreatePorterAppHandler
- LEGACY_createPorterAppEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("/stacks/{%s}", types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- LEGACY_createPorterAppHandler := porter_app.NewCreatePorterAppHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: LEGACY_createPorterAppEndpoint,
- Handler: LEGACY_createPorterAppHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/stacks/{name}/events -> porter_app.NewCreatePorterAppEventHandler
- LEGACY_createPorterAppEventEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("/stacks/{%s}/events", types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- LEGACY_createPorterAppEventHandler := porter_app.NewCreateUpdatePorterAppEventHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: LEGACY_createPorterAppEventEndpoint,
- Handler: LEGACY_createPorterAppEventHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/parse -> porter_app.NewParsePorterYAMLToProtoHandler
- parsePorterYAMLToProtoEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/apps/parse",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- parsePorterYAMLToProtoHandler := porter_app.NewParsePorterYAMLToProtoHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: parsePorterYAMLToProtoEndpoint,
- Handler: parsePorterYAMLToProtoHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/validate -> porter_app.NewValidatePorterAppHandler
- validatePorterAppEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/apps/validate",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- validatePorterAppHandler := porter_app.NewValidatePorterAppHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: validatePorterAppEndpoint,
- Handler: validatePorterAppHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/create -> porter_app.NewCreateAppHandler
- createAppEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/apps/create",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- createAppHandler := porter_app.NewCreateAppHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: createAppEndpoint,
- Handler: createAppHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/apply -> porter_app.NewApplyPorterAppHandler
- applyPorterAppEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbUpdate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/apps/apply",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- applyPorterAppHandler := porter_app.NewApplyPorterAppHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: applyPorterAppEndpoint,
- Handler: applyPorterAppHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/default-deployment-target -> porter_app.NewDefaultDeploymentTargetHandler
- defaultDeploymentTargetEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/default-deployment-target",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- defaultDeploymentTargetHandler := porter_app.NewDefaultDeploymentTargetHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: defaultDeploymentTargetEndpoint,
- Handler: defaultDeploymentTargetHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/latest -> porter_app.NewCurrentAppRevisionHandler
- currentAppRevisionEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("/apps/{%s}/latest", types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- currentAppRevisionHandler := porter_app.NewLatestAppRevisionHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: currentAppRevisionEndpoint,
- Handler: currentAppRevisionHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions -> porter_app.NewCurrentAppRevisionHandler
- listAppRevisionsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("/apps/{%s}/revisions", types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- listAppRevisionsHandler := porter_app.NewListAppRevisionsHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: listAppRevisionsEndpoint,
- Handler: listAppRevisionsHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/revisions -> porter_app.NewCurrentAppRevisionHandler
- latestAppRevisionsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/apps/revisions",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- latestAppRevisionsHandler := porter_app.NewLatestAppRevisionsHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: latestAppRevisionsEndpoint,
- Handler: latestAppRevisionsHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/subdomain -> porter_app.NewCreateSubdomainHandler
- createSubdomainEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbUpdate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("/apps/{%s}/subdomain", types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- createSubdomainHandler := porter_app.NewCreateSubdomainHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: createSubdomainEndpoint,
- Handler: createSubdomainHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/{app_revision_id}/predeploy-status -> porter_app.NewPredeployStatusHandler
- predeployStatusEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("/apps/{%s}/{%s}/predeploy-status", types.URLParamPorterAppName, types.URLParamAppRevisionID),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- predeployStatusHandler := porter_app.NewPredeployStatusHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: predeployStatusEndpoint,
- Handler: predeployStatusHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/logs -> cluster.NewAppLogsHandler
- appLogsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/apps/logs",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- appLogsHandler := porter_app.NewAppLogsHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: appLogsEndpoint,
- Handler: appLogsHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/logs/loki -> namespace.NewStreamLogsLokiHandler
- streamLogsLokiEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/apps/logs/loki",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- IsWebsocket: true,
- },
- )
- streamLogsLokiHandler := porter_app.NewStreamLogsLokiHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: streamLogsLokiEndpoint,
- Handler: streamLogsLokiHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/metrics -> cluster.NewGetPodMetricsHandler
- appMetricsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/apps/metrics",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- appMetricsHandler := porter_app.NewAppMetricsHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: appMetricsEndpoint,
- Handler: appMetricsHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id} -> porter_app.NewUpdateAppRevisionStatusHandler
- updateAppRevisionStatusEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbUpdate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}", types.URLParamPorterAppName, types.URLParamAppRevisionID),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- updateAppRevisionStatusHandler := porter_app.NewUpdateAppRevisionStatusHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: updateAppRevisionStatusEndpoint,
- Handler: updateAppRevisionStatusHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/build-env -> porter_app.NewGetBuildEnvHandler
- getBuildEnvEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/build-env", types.URLParamPorterAppName, types.URLParamAppRevisionID),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getBuildEnvHandler := porter_app.NewGetBuildEnvHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: getBuildEnvEndpoint,
- Handler: getBuildEnvHandler,
- Router: r,
- })
- // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/update-environment -> porter_app.NewUpdateAppEnvironmentHandler
- updateAppEnvironmentGroupEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbUpdate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("/apps/{%s}/update-environment", types.URLParamPorterAppName),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- updateAppEnvironmentGroupHandler := porter_app.NewUpdateAppEnvironmentHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: updateAppEnvironmentGroupEndpoint,
- Handler: updateAppEnvironmentGroupHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/env -> porter_app.NewGetAppEnvHandler
- getAppEnvEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/env", types.URLParamPorterAppName, types.URLParamAppRevisionID),
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- },
- },
- )
- getAppEnvHandler := porter_app.NewGetAppEnvHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: getAppEnvEndpoint,
- Handler: getAppEnvHandler,
- Router: r,
- })
- return routes, newPath
- }
|