stack.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. package v1
  2. import (
  3. "github.com/go-chi/chi"
  4. "github.com/porter-dev/porter/api/server/handlers/stack"
  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. // swagger:parameters getStack deleteStack putStackSource rollbackStack listStackRevisions addApplication addEnvGroup updateStack
  11. type stackPathParams struct {
  12. // The project id
  13. // in: path
  14. // required: true
  15. // minimum: 1
  16. ProjectID uint `json:"project_id"`
  17. // The cluster id
  18. // in: path
  19. // required: true
  20. // minimum: 1
  21. ClusterID uint `json:"cluster_id"`
  22. // The namespace
  23. // in: path
  24. // required: true
  25. Namespace string `json:"namespace"`
  26. // The stack id
  27. // in: path
  28. // required: true
  29. StackID string `json:"stack_id"`
  30. }
  31. // swagger:parameters getStackRevision
  32. type stackRevisionPathParams struct {
  33. // The project id
  34. // in: path
  35. // required: true
  36. // minimum: 1
  37. ProjectID uint `json:"project_id"`
  38. // The cluster id
  39. // in: path
  40. // required: true
  41. // minimum: 1
  42. ClusterID uint `json:"cluster_id"`
  43. // The namespace
  44. // in: path
  45. // required: true
  46. Namespace string `json:"namespace"`
  47. // The stack id
  48. // in: path
  49. // required: true
  50. StackID string `json:"stack_id"`
  51. // The stack revision id
  52. // in: path
  53. // required: true
  54. // minimum: 1
  55. RevisionID string `json:"revision_id"`
  56. }
  57. // swagger:parameters removeApplication
  58. type stackRemoveApplicationPathParams struct {
  59. // The project id
  60. // in: path
  61. // required: true
  62. // minimum: 1
  63. ProjectID uint `json:"project_id"`
  64. // The cluster id
  65. // in: path
  66. // required: true
  67. // minimum: 1
  68. ClusterID uint `json:"cluster_id"`
  69. // The namespace
  70. // in: path
  71. // required: true
  72. Namespace string `json:"namespace"`
  73. // The stack id
  74. // in: path
  75. // required: true
  76. StackID string `json:"stack_id"`
  77. // The name of the application
  78. // in: path
  79. // required: true
  80. AppResourceName string `json:"app_resource_name"`
  81. }
  82. // swagger:parameters removeEnvGroup
  83. type stackRemoveEnvGroupPathParams struct {
  84. // The project id
  85. // in: path
  86. // required: true
  87. // minimum: 1
  88. ProjectID uint `json:"project_id"`
  89. // The cluster id
  90. // in: path
  91. // required: true
  92. // minimum: 1
  93. ClusterID uint `json:"cluster_id"`
  94. // The namespace
  95. // in: path
  96. // required: true
  97. Namespace string `json:"namespace"`
  98. // The stack id
  99. // in: path
  100. // required: true
  101. StackID string `json:"stack_id"`
  102. // The name of the environment group
  103. // in: path
  104. // required: true
  105. EnvGroupName string `json:"env_group_name"`
  106. }
  107. func NewV1StackScopedRegisterer(children ...*router.Registerer) *router.Registerer {
  108. return &router.Registerer{
  109. GetRoutes: GetV1StackScopedRoutes,
  110. Children: children,
  111. }
  112. }
  113. func GetV1StackScopedRoutes(
  114. r chi.Router,
  115. config *config.Config,
  116. basePath *types.Path,
  117. factory shared.APIEndpointFactory,
  118. children ...*router.Registerer,
  119. ) []*router.Route {
  120. routes, projPath := getV1StackRoutes(r, config, basePath, factory)
  121. if len(children) > 0 {
  122. r.Route(projPath.RelativePath, func(r chi.Router) {
  123. for _, child := range children {
  124. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  125. routes = append(routes, childRoutes...)
  126. }
  127. })
  128. }
  129. return routes
  130. }
  131. func getV1StackRoutes(
  132. r chi.Router,
  133. config *config.Config,
  134. basePath *types.Path,
  135. factory shared.APIEndpointFactory,
  136. ) ([]*router.Route, *types.Path) {
  137. relPath := "/stacks"
  138. newPath := &types.Path{
  139. Parent: basePath,
  140. RelativePath: relPath,
  141. }
  142. var routes []*router.Route
  143. // POST /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks -> stack.NewStackCreateHandler
  144. // swagger:operation POST /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks createStack
  145. //
  146. // Creates a new stack and triggers a deployment for all resources in the stack.
  147. //
  148. // ---
  149. // produces:
  150. // - application/json
  151. // summary: Create a stack
  152. // tags:
  153. // - Stacks
  154. // parameters:
  155. // - name: project_id
  156. // - name: cluster_id
  157. // - name: namespace
  158. // - in: body
  159. // name: CreateStackRequest
  160. // description: The stack to create
  161. // schema:
  162. // $ref: '#/definitions/CreateStackRequest'
  163. // responses:
  164. // '201':
  165. // description: Successfully created the stack
  166. // schema:
  167. // $ref: '#/definitions/Stack'
  168. // '403':
  169. // description: Forbidden
  170. createEndpoint := factory.NewAPIEndpoint(
  171. &types.APIRequestMetadata{
  172. Verb: types.APIVerbCreate,
  173. Method: types.HTTPVerbPost,
  174. Path: &types.Path{
  175. Parent: basePath,
  176. RelativePath: relPath,
  177. },
  178. Scopes: []types.PermissionScope{
  179. types.UserScope,
  180. types.ProjectScope,
  181. types.ClusterScope,
  182. types.NamespaceScope,
  183. },
  184. },
  185. )
  186. createHandler := stack.NewStackCreateHandler(
  187. config,
  188. factory.GetDecoderValidator(),
  189. factory.GetResultWriter(),
  190. )
  191. routes = append(routes, &router.Route{
  192. Endpoint: createEndpoint,
  193. Handler: createHandler,
  194. Router: r,
  195. })
  196. // GET /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks -> stack.NewStackListHandler
  197. // swagger:operation GET /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks listStacks
  198. //
  199. // Lists stacks in a namespace
  200. //
  201. // ---
  202. // produces:
  203. // - application/json
  204. // summary: List stacks
  205. // tags:
  206. // - Stacks
  207. // parameters:
  208. // - name: project_id
  209. // - name: cluster_id
  210. // - name: namespace
  211. // responses:
  212. // '200':
  213. // description: Successfully listed stacks
  214. // schema:
  215. // $ref: '#/definitions/StackListResponse'
  216. // '403':
  217. // description: Forbidden
  218. listEndpoint := factory.NewAPIEndpoint(
  219. &types.APIRequestMetadata{
  220. Verb: types.APIVerbGet,
  221. Method: types.HTTPVerbGet,
  222. Path: &types.Path{
  223. Parent: basePath,
  224. RelativePath: relPath,
  225. },
  226. Scopes: []types.PermissionScope{
  227. types.UserScope,
  228. types.ProjectScope,
  229. types.ClusterScope,
  230. types.NamespaceScope,
  231. },
  232. },
  233. )
  234. listHandler := stack.NewStackListHandler(
  235. config,
  236. factory.GetResultWriter(),
  237. )
  238. routes = append(routes, &router.Route{
  239. Endpoint: listEndpoint,
  240. Handler: listHandler,
  241. Router: r,
  242. })
  243. // GET /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id} -> stack.NewStackGetHandler
  244. // swagger:operation GET /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id} getStack
  245. //
  246. // Gets a stack
  247. //
  248. // ---
  249. // produces:
  250. // - application/json
  251. // summary: Get a stack
  252. // tags:
  253. // - Stacks
  254. // parameters:
  255. // - name: project_id
  256. // - name: cluster_id
  257. // - name: namespace
  258. // - name: stack_id
  259. // responses:
  260. // '200':
  261. // description: Successfully got the stack
  262. // schema:
  263. // $ref: '#/definitions/Stack'
  264. // '403':
  265. // description: Forbidden
  266. getEndpoint := factory.NewAPIEndpoint(
  267. &types.APIRequestMetadata{
  268. Verb: types.APIVerbGet,
  269. Method: types.HTTPVerbGet,
  270. Path: &types.Path{
  271. Parent: basePath,
  272. RelativePath: relPath + "/{stack_id}",
  273. },
  274. Scopes: []types.PermissionScope{
  275. types.UserScope,
  276. types.ProjectScope,
  277. types.ClusterScope,
  278. types.NamespaceScope,
  279. types.StackScope,
  280. },
  281. },
  282. )
  283. getHandler := stack.NewStackGetHandler(
  284. config,
  285. factory.GetResultWriter(),
  286. )
  287. routes = append(routes, &router.Route{
  288. Endpoint: getEndpoint,
  289. Handler: getHandler,
  290. Router: r,
  291. })
  292. // GET /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/revisions -> stack.NewStackListRevisionsHandler
  293. // swagger:operation GET /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/revisions listStackRevisions
  294. //
  295. // Lists revisions in a stack. A max of 100 revisions will be returned, sorted from most recent to least recent.
  296. //
  297. // ---
  298. // produces:
  299. // - application/json
  300. // summary: List stack revisions
  301. // tags:
  302. // - Stacks
  303. // parameters:
  304. // - name: project_id
  305. // - name: cluster_id
  306. // - name: namespace
  307. // - name: stack_id
  308. // responses:
  309. // '200':
  310. // description: Successfully listed stack revisions
  311. // schema:
  312. // $ref: '#/definitions/ListStackRevisionsResponse'
  313. // '403':
  314. // description: Forbidden
  315. listRevisionsEndpoint := factory.NewAPIEndpoint(
  316. &types.APIRequestMetadata{
  317. Verb: types.APIVerbGet,
  318. Method: types.HTTPVerbGet,
  319. Path: &types.Path{
  320. Parent: basePath,
  321. RelativePath: relPath + "/{stack_id}/revisions",
  322. },
  323. Scopes: []types.PermissionScope{
  324. types.UserScope,
  325. types.ProjectScope,
  326. types.ClusterScope,
  327. types.NamespaceScope,
  328. types.StackScope,
  329. },
  330. },
  331. )
  332. listRevisionsHandler := stack.NewStackListRevisionsHandler(
  333. config,
  334. factory.GetResultWriter(),
  335. )
  336. routes = append(routes, &router.Route{
  337. Endpoint: listRevisionsEndpoint,
  338. Handler: listRevisionsHandler,
  339. Router: r,
  340. })
  341. // GET /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/{revision_id} -> stack.NewStackGetRevisionHandler
  342. // swagger:operation GET /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/{revision_id} getStackRevision
  343. //
  344. // Gets a stack revision
  345. //
  346. // ---
  347. // produces:
  348. // - application/json
  349. // summary: Get a stack revision
  350. // tags:
  351. // - Stacks
  352. // parameters:
  353. // - name: project_id
  354. // - name: cluster_id
  355. // - name: namespace
  356. // - name: stack_id
  357. // - name: revision_id
  358. // responses:
  359. // '200':
  360. // description: Successfully got the stack revision
  361. // schema:
  362. // $ref: '#/definitions/StackRevision'
  363. // '403':
  364. // description: Forbidden
  365. getRevisionEndpoint := factory.NewAPIEndpoint(
  366. &types.APIRequestMetadata{
  367. Verb: types.APIVerbGet,
  368. Method: types.HTTPVerbGet,
  369. Path: &types.Path{
  370. Parent: basePath,
  371. RelativePath: relPath + "/{stack_id}/{stack_revision_number}",
  372. },
  373. Scopes: []types.PermissionScope{
  374. types.UserScope,
  375. types.ProjectScope,
  376. types.ClusterScope,
  377. types.NamespaceScope,
  378. types.StackScope,
  379. },
  380. },
  381. )
  382. getRevisionHandler := stack.NewStackGetRevisionHandler(
  383. config,
  384. factory.GetResultWriter(),
  385. )
  386. routes = append(routes, &router.Route{
  387. Endpoint: getRevisionEndpoint,
  388. Handler: getRevisionHandler,
  389. Router: r,
  390. })
  391. // PUT /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/source -> stack.NewStackPutSourceConfig
  392. // swagger:operation PUT /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/source putStackSource
  393. //
  394. // Updates a stack's source configuration
  395. //
  396. // ---
  397. // produces:
  398. // - application/json
  399. // summary: Update source configuration
  400. // tags:
  401. // - Stacks
  402. // parameters:
  403. // - name: project_id
  404. // - name: cluster_id
  405. // - name: namespace
  406. // - name: stack_id
  407. // - in: body
  408. // name: PutStackSourceConfigRequest
  409. // description: The source configurations to update
  410. // schema:
  411. // $ref: '#/definitions/PutStackSourceConfigRequest'
  412. // responses:
  413. // '200':
  414. // description: Successfully updated the source configuration
  415. // schema:
  416. // $ref: '#/definitions/Stack'
  417. // '403':
  418. // description: Forbidden
  419. putSourceEndpoint := factory.NewAPIEndpoint(
  420. &types.APIRequestMetadata{
  421. Verb: types.APIVerbUpdate,
  422. Method: types.HTTPVerbPut,
  423. Path: &types.Path{
  424. Parent: basePath,
  425. RelativePath: relPath + "/{stack_id}/source",
  426. },
  427. Scopes: []types.PermissionScope{
  428. types.UserScope,
  429. types.ProjectScope,
  430. types.ClusterScope,
  431. types.NamespaceScope,
  432. types.StackScope,
  433. },
  434. },
  435. )
  436. putSourceHandler := stack.NewStackPutSourceConfigHandler(
  437. config,
  438. factory.GetDecoderValidator(),
  439. factory.GetResultWriter(),
  440. )
  441. routes = append(routes, &router.Route{
  442. Endpoint: putSourceEndpoint,
  443. Handler: putSourceHandler,
  444. Router: r,
  445. })
  446. // POST /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/rollback -> stack.NewStackRollbackHandler
  447. // swagger:operation POST /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/rollback rollbackStack
  448. //
  449. // Performs a rollback for a stack
  450. //
  451. // ---
  452. // produces:
  453. // - application/json
  454. // summary: Rollback stack
  455. // tags:
  456. // - Stacks
  457. // parameters:
  458. // - name: project_id
  459. // - name: cluster_id
  460. // - name: namespace
  461. // - name: stack_id
  462. // - in: body
  463. // name: StackRollbackRequest
  464. // description: The target revision to roll back to
  465. // schema:
  466. // $ref: '#/definitions/StackRollbackRequest'
  467. // responses:
  468. // '200':
  469. // description: Successfully rolled the stack back
  470. // schema:
  471. // $ref: '#/definitions/Stack'
  472. // '403':
  473. // description: Forbidden
  474. rollbackEndpoint := factory.NewAPIEndpoint(
  475. &types.APIRequestMetadata{
  476. Verb: types.APIVerbUpdate,
  477. Method: types.HTTPVerbPost,
  478. Path: &types.Path{
  479. Parent: basePath,
  480. RelativePath: relPath + "/{stack_id}/rollback",
  481. },
  482. Scopes: []types.PermissionScope{
  483. types.UserScope,
  484. types.ProjectScope,
  485. types.ClusterScope,
  486. types.NamespaceScope,
  487. types.StackScope,
  488. },
  489. },
  490. )
  491. rollbackHandler := stack.NewStackRollbackHandler(
  492. config,
  493. factory.GetDecoderValidator(),
  494. factory.GetResultWriter(),
  495. )
  496. routes = append(routes, &router.Route{
  497. Endpoint: rollbackEndpoint,
  498. Handler: rollbackHandler,
  499. Router: r,
  500. })
  501. // DELETE /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id} -> stack.NewStackDeleteHandler
  502. // swagger:operation DELETE /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id} deleteStack
  503. //
  504. // Deletes a stack
  505. //
  506. // ---
  507. // produces:
  508. // - application/json
  509. // summary: Delete a stack
  510. // tags:
  511. // - Stacks
  512. // parameters:
  513. // - name: project_id
  514. // - name: cluster_id
  515. // - name: namespace
  516. // - name: stack_id
  517. // responses:
  518. // '200':
  519. // description: Successfully deleted the stack
  520. // '403':
  521. // description: Forbidden
  522. deleteEndpoint := factory.NewAPIEndpoint(
  523. &types.APIRequestMetadata{
  524. Verb: types.APIVerbDelete,
  525. Method: types.HTTPVerbDelete,
  526. Path: &types.Path{
  527. Parent: basePath,
  528. RelativePath: relPath + "/{stack_id}",
  529. },
  530. Scopes: []types.PermissionScope{
  531. types.UserScope,
  532. types.ProjectScope,
  533. types.ClusterScope,
  534. types.NamespaceScope,
  535. types.StackScope,
  536. },
  537. },
  538. )
  539. deleteHandler := stack.NewStackDeleteHandler(
  540. config,
  541. factory.GetResultWriter(),
  542. )
  543. routes = append(routes, &router.Route{
  544. Endpoint: deleteEndpoint,
  545. Handler: deleteHandler,
  546. Router: r,
  547. })
  548. // PATCH /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/add_application -> stack.NewStackAddApplicationHandler
  549. // swagger:operation PATCH /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/add_application addApplication
  550. //
  551. // Adds an application to an existing stack
  552. //
  553. // ---
  554. // produces:
  555. // - application/json
  556. // summary: Add an application to a stack
  557. // tags:
  558. // - Stacks
  559. // parameters:
  560. // - name: project_id
  561. // - name: cluster_id
  562. // - name: namespace
  563. // - name: stack_id
  564. // - in: body
  565. // name: AddApplicationToStack
  566. // description: The application to add
  567. // schema:
  568. // $ref: '#/definitions/CreateStackAppResourceRequest'
  569. // responses:
  570. // '200':
  571. // description: Successfully added the application to the stack
  572. // '400':
  573. // description: Stack does not have any revisions
  574. // '403':
  575. // description: Forbidden
  576. addApplicationEndpoint := factory.NewAPIEndpoint(
  577. &types.APIRequestMetadata{
  578. Verb: types.APIVerbUpdate,
  579. Method: types.HTTPVerbPatch,
  580. Path: &types.Path{
  581. Parent: basePath,
  582. RelativePath: relPath + "/{stack_id}/add_application",
  583. },
  584. Scopes: []types.PermissionScope{
  585. types.UserScope,
  586. types.ProjectScope,
  587. types.ClusterScope,
  588. types.NamespaceScope,
  589. types.StackScope,
  590. },
  591. },
  592. )
  593. addApplicationHandler := stack.NewStackAddApplicationHandler(
  594. config,
  595. factory.GetDecoderValidator(),
  596. factory.GetResultWriter(),
  597. )
  598. routes = append(routes, &router.Route{
  599. Endpoint: addApplicationEndpoint,
  600. Handler: addApplicationHandler,
  601. Router: r,
  602. })
  603. // DELETE /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/remove_application/{app_resource_name} -> stack.NewStackRemoveApplicationHandler
  604. // swagger:operation DELETE /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/remove_application/{app_resource_name} removeApplication
  605. //
  606. // Removes an existing application from a stack
  607. //
  608. // ---
  609. // produces:
  610. // - application/json
  611. // summary: Remove an application from a stack
  612. // tags:
  613. // - Stacks
  614. // parameters:
  615. // - name: project_id
  616. // - name: cluster_id
  617. // - name: namespace
  618. // - name: stack_id
  619. // - name: app_resource_name
  620. // responses:
  621. // '200':
  622. // description: Successfully deleted the application from the stack
  623. // '400':
  624. // description: Stack does not have any revisions
  625. // '403':
  626. // description: Forbidden
  627. removeApplicationEndpoint := factory.NewAPIEndpoint(
  628. &types.APIRequestMetadata{
  629. Verb: types.APIVerbDelete,
  630. Method: types.HTTPVerbDelete,
  631. Path: &types.Path{
  632. Parent: basePath,
  633. RelativePath: relPath + "/{stack_id}/remove_application/{app_resource_name}",
  634. },
  635. Scopes: []types.PermissionScope{
  636. types.UserScope,
  637. types.ProjectScope,
  638. types.ClusterScope,
  639. types.NamespaceScope,
  640. types.StackScope,
  641. },
  642. },
  643. )
  644. removeApplicationHandler := stack.NewStackRemoveApplicationHandler(
  645. config,
  646. factory.GetResultWriter(),
  647. )
  648. routes = append(routes, &router.Route{
  649. Endpoint: removeApplicationEndpoint,
  650. Handler: removeApplicationHandler,
  651. Router: r,
  652. })
  653. // PATCH /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/add_env_group -> stack.NewStackAddEnvGroupHandler
  654. // swagger:operation PATCH /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/add_env_group addEnvGroup
  655. //
  656. // Adds an environment group to an existing stack
  657. //
  658. // ---
  659. // produces:
  660. // - application/json
  661. // summary: Add an environment group to a stack
  662. // tags:
  663. // - Stacks
  664. // parameters:
  665. // - name: project_id
  666. // - name: cluster_id
  667. // - name: namespace
  668. // - name: stack_id
  669. // - in: body
  670. // name: AddEnvGroupToStack
  671. // description: The environment group to add
  672. // schema:
  673. // $ref: '#/definitions/CreateStackEnvGroupRequest'
  674. // responses:
  675. // '200':
  676. // description: Successfully added the environment group to the stack
  677. // '400':
  678. // description: Stack does not have any revisions
  679. // '403':
  680. // description: Forbidden
  681. addEnvGroupEndpoint := factory.NewAPIEndpoint(
  682. &types.APIRequestMetadata{
  683. Verb: types.APIVerbUpdate,
  684. Method: types.HTTPVerbPatch,
  685. Path: &types.Path{
  686. Parent: basePath,
  687. RelativePath: relPath + "/{stack_id}/add_env_group",
  688. },
  689. Scopes: []types.PermissionScope{
  690. types.UserScope,
  691. types.ProjectScope,
  692. types.ClusterScope,
  693. types.NamespaceScope,
  694. types.StackScope,
  695. },
  696. },
  697. )
  698. addEnvGroupHandler := stack.NewStackAddEnvGroupHandler(
  699. config,
  700. factory.GetDecoderValidator(),
  701. factory.GetResultWriter(),
  702. )
  703. routes = append(routes, &router.Route{
  704. Endpoint: addEnvGroupEndpoint,
  705. Handler: addEnvGroupHandler,
  706. Router: r,
  707. })
  708. // DELETE /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/remove_env_group/{env_group_name} -> stack.NewStackRemoveEnvGroupHandler
  709. // swagger:operation DELETE /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/remove_env_group/{env_group_name} removeEnvGroup
  710. //
  711. // Removes an existing environment group from a stack
  712. //
  713. // ---
  714. // produces:
  715. // - application/json
  716. // summary: Remove an environment group from a stack
  717. // tags:
  718. // - Stacks
  719. // parameters:
  720. // - name: project_id
  721. // - name: cluster_id
  722. // - name: namespace
  723. // - name: stack_id
  724. // - name: env_group_name
  725. // responses:
  726. // '200':
  727. // description: Successfully deleted the environment group from the stack
  728. // '400':
  729. // description: Stack does not have any revisions
  730. // '403':
  731. // description: Forbidden
  732. removeEnvGroupEndpoint := factory.NewAPIEndpoint(
  733. &types.APIRequestMetadata{
  734. Verb: types.APIVerbDelete,
  735. Method: types.HTTPVerbDelete,
  736. Path: &types.Path{
  737. Parent: basePath,
  738. RelativePath: relPath + "/{stack_id}/remove_env_group/{env_group_name}",
  739. },
  740. Scopes: []types.PermissionScope{
  741. types.UserScope,
  742. types.ProjectScope,
  743. types.ClusterScope,
  744. types.NamespaceScope,
  745. types.StackScope,
  746. },
  747. },
  748. )
  749. removeEnvGroupHandler := stack.NewStackRemoveEnvGroupHandler(
  750. config,
  751. factory.GetResultWriter(),
  752. )
  753. routes = append(routes, &router.Route{
  754. Endpoint: removeEnvGroupEndpoint,
  755. Handler: removeEnvGroupHandler,
  756. Router: r,
  757. })
  758. // PATCH /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id} -> stack.NewStackUpdateStackHandler
  759. // swagger:operation PATCH /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id} updateStack
  760. //
  761. // Updates a stack. Currently the only value available to update is the stack name.
  762. //
  763. // ---
  764. // produces:
  765. // - application/json
  766. // summary: Update Stack
  767. // tags:
  768. // - Stacks
  769. // parameters:
  770. // - name: project_id
  771. // - name: cluster_id
  772. // - name: namespace
  773. // - name: stack_id
  774. // - in: body
  775. // name: UpdateStack
  776. // description: The stack to update
  777. // schema:
  778. // $ref: '#/definitions/UpdateStackRequest'
  779. // responses:
  780. // '200':
  781. // description: Successfully updated the stack
  782. // '403':
  783. // description: Forbidden
  784. updateStackEndpoint := factory.NewAPIEndpoint(
  785. &types.APIRequestMetadata{
  786. Verb: types.APIVerbUpdate,
  787. Method: types.HTTPVerbPatch,
  788. Path: &types.Path{
  789. Parent: basePath,
  790. RelativePath: relPath + "/{stack_id}",
  791. },
  792. Scopes: []types.PermissionScope{
  793. types.UserScope,
  794. types.ProjectScope,
  795. types.ClusterScope,
  796. types.NamespaceScope,
  797. types.StackScope,
  798. },
  799. },
  800. )
  801. updateStackHandler := stack.NewStackUpdateStackHandler(
  802. config,
  803. factory.GetDecoderValidator(),
  804. factory.GetResultWriter(),
  805. )
  806. routes = append(routes, &router.Route{
  807. Endpoint: updateStackEndpoint,
  808. Handler: updateStackHandler,
  809. Router: r,
  810. })
  811. return routes, newPath
  812. }