environment.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package client
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/porter-dev/porter/api/types"
  6. )
  7. func (c *Client) ListEnvironments(
  8. ctx context.Context,
  9. projID, clusterID uint,
  10. ) (*types.ListEnvironmentsResponse, error) {
  11. resp := &types.ListEnvironmentsResponse{}
  12. err := c.getRequest(
  13. fmt.Sprintf("/projects/%d/clusters/%d/environments", projID, clusterID),
  14. nil,
  15. resp,
  16. )
  17. return resp, err
  18. }
  19. func (c *Client) CreateDeployment(
  20. ctx context.Context,
  21. projID, clusterID uint,
  22. req *types.CreateDeploymentRequest,
  23. ) (*types.Deployment, error) {
  24. resp := &types.Deployment{}
  25. err := c.postRequest(
  26. fmt.Sprintf("/projects/%d/clusters/%d/deployments", projID, clusterID),
  27. req,
  28. resp,
  29. )
  30. return resp, err
  31. }
  32. func (c *Client) GetDeployment(
  33. ctx context.Context,
  34. projID, clusterID, envID uint,
  35. req *types.GetDeploymentRequest,
  36. ) (*types.Deployment, error) {
  37. resp := &types.Deployment{}
  38. err := c.getRequest(
  39. fmt.Sprintf("/projects/%d/clusters/%d/environments/%d/deployment", projID, clusterID, envID),
  40. req,
  41. resp,
  42. )
  43. return resp, err
  44. }
  45. func (c *Client) UpdateDeployment(
  46. ctx context.Context,
  47. projID, clusterID uint,
  48. req *types.UpdateDeploymentByClusterRequest,
  49. ) (*types.Deployment, error) {
  50. resp := &types.Deployment{}
  51. err := c.patchRequest(
  52. fmt.Sprintf("/projects/%d/clusters/%d/deployments", projID, clusterID),
  53. req,
  54. resp,
  55. )
  56. return resp, err
  57. }
  58. func (c *Client) UpdateDeploymentStatus(
  59. ctx context.Context,
  60. projID, clusterID uint,
  61. req *types.UpdateDeploymentStatusByClusterRequest,
  62. ) (*types.Deployment, error) {
  63. resp := &types.Deployment{}
  64. err := c.patchRequest(
  65. fmt.Sprintf("/projects/%d/clusters/%d/deployments/status", projID, clusterID),
  66. req,
  67. resp,
  68. )
  69. return resp, err
  70. }
  71. func (c *Client) FinalizeDeployment(
  72. ctx context.Context,
  73. projID, clusterID uint,
  74. req *types.FinalizeDeploymentByClusterRequest,
  75. ) (*types.Deployment, error) {
  76. resp := &types.Deployment{}
  77. err := c.postRequest(
  78. fmt.Sprintf("/projects/%d/clusters/%d/deployments/finalize", projID, clusterID),
  79. req,
  80. resp,
  81. )
  82. return resp, err
  83. }
  84. func (c *Client) FinalizeDeploymentWithErrors(
  85. ctx context.Context,
  86. projID, clusterID uint,
  87. req *types.FinalizeDeploymentWithErrorsByClusterRequest,
  88. ) (*types.Deployment, error) {
  89. resp := &types.Deployment{}
  90. err := c.postRequest(
  91. fmt.Sprintf("/projects/%d/clusters/%d/deployments/finalize_errors", projID, clusterID),
  92. req,
  93. resp,
  94. )
  95. return resp, err
  96. }
  97. func (c *Client) DeleteDeployment(
  98. ctx context.Context,
  99. projID, clusterID, deploymentID uint,
  100. ) error {
  101. return c.deleteRequest(
  102. fmt.Sprintf(
  103. "/projects/%d/clusters/%d/deployments/%d",
  104. projID, clusterID, deploymentID,
  105. ),
  106. nil, nil,
  107. )
  108. }