porter_app.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package client
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/porter-dev/porter/api/types"
  6. )
  7. func (c *Client) NewGetPorterApp(
  8. ctx context.Context,
  9. projectID, clusterID uint,
  10. appName string,
  11. ) (*types.PorterApp, error) {
  12. resp := &types.PorterApp{}
  13. err := c.getRequest(
  14. fmt.Sprintf(
  15. "/projects/%d/clusters/%d/applications/%s",
  16. projectID, clusterID, appName,
  17. ),
  18. nil,
  19. resp,
  20. )
  21. return resp, err
  22. }
  23. func (c *Client) NewCreatePorterApp(
  24. ctx context.Context,
  25. projectID, clusterID uint,
  26. appName string,
  27. req *types.CreatePorterAppRequest,
  28. ) (*types.PorterApp, error) {
  29. resp := &types.PorterApp{}
  30. err := c.postRequest(
  31. fmt.Sprintf(
  32. "/projects/%d/clusters/%d/applications/%s",
  33. projectID, clusterID, appName,
  34. ),
  35. req,
  36. resp,
  37. )
  38. return resp, err
  39. }
  40. // NewCreateOrUpdatePorterAppEvent will create a porter app event if one does not exist, or else it will update the existing one if an ID is passed in the object
  41. func (c *Client) NewCreateOrUpdatePorterAppEvent(
  42. ctx context.Context,
  43. projectID, clusterID uint,
  44. appName string,
  45. req *types.CreateOrUpdatePorterAppEventRequest,
  46. ) (types.PorterAppEvent, error) {
  47. resp := &types.PorterAppEvent{}
  48. err := c.postRequest(
  49. fmt.Sprintf(
  50. "/projects/%d/clusters/%d/applications/%s/events",
  51. projectID, clusterID, appName,
  52. ),
  53. req,
  54. resp,
  55. )
  56. return *resp, err
  57. }
  58. // TODO: remove these functions once they are no longer called (check telemetry)
  59. func (c *Client) GetPorterApp(
  60. ctx context.Context,
  61. projectID, clusterID uint,
  62. stackName string,
  63. ) (*types.PorterApp, error) {
  64. resp := &types.PorterApp{}
  65. err := c.getRequest(
  66. fmt.Sprintf(
  67. "/projects/%d/clusters/%d/stacks/%s",
  68. projectID, clusterID, stackName,
  69. ),
  70. nil,
  71. resp,
  72. )
  73. return resp, err
  74. }
  75. func (c *Client) CreatePorterApp(
  76. ctx context.Context,
  77. projectID, clusterID uint,
  78. name string,
  79. req *types.CreatePorterAppRequest,
  80. ) (*types.PorterApp, error) {
  81. resp := &types.PorterApp{}
  82. err := c.postRequest(
  83. fmt.Sprintf(
  84. "/projects/%d/clusters/%d/stacks/%s",
  85. projectID, clusterID, name,
  86. ),
  87. req,
  88. resp,
  89. )
  90. return resp, err
  91. }
  92. // CreateOrUpdatePorterAppEvent will create a porter app event if one does not exist, or else it will update the existing one if an ID is passed in the object
  93. func (c *Client) CreateOrUpdatePorterAppEvent(
  94. ctx context.Context,
  95. projectID, clusterID uint,
  96. name string,
  97. req *types.CreateOrUpdatePorterAppEventRequest,
  98. ) (types.PorterAppEvent, error) {
  99. resp := &types.PorterAppEvent{}
  100. err := c.postRequest(
  101. fmt.Sprintf(
  102. "/projects/%d/clusters/%d/stacks/%s/events",
  103. projectID, clusterID, name,
  104. ),
  105. req,
  106. resp,
  107. )
  108. return *resp, err
  109. }
  110. // ListEnvGroups (List all Env Groups for a given cluster)
  111. func (c *Client) ListEnvGroups(
  112. ctx context.Context,
  113. projectID, clusterID uint,
  114. ) (types.ListEnvironmentGroupsResponse, error) {
  115. resp := &types.ListEnvironmentGroupsResponse{}
  116. err := c.getRequest(
  117. fmt.Sprintf(
  118. "/projects/%d/clusters/%d/environment-groups",
  119. projectID, clusterID,
  120. ),
  121. nil,
  122. resp,
  123. )
  124. return *resp, err
  125. }