2
0

env_groups.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package client
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/porter-dev/porter/api/server/handlers/environment_groups"
  6. )
  7. // GetLatestEnvGroupVariables gets the latest environment group variables for a given environment group
  8. func (c *Client) GetLatestEnvGroupVariables(
  9. ctx context.Context,
  10. projID, clusterID uint,
  11. envGroupName string,
  12. ) (*environment_groups.LatestEnvGroupVariablesResponse, error) {
  13. resp := &environment_groups.LatestEnvGroupVariablesResponse{}
  14. err := c.getRequest(
  15. fmt.Sprintf("/projects/%d/clusters/%d/environment-groups/%s/latest", projID, clusterID, envGroupName),
  16. nil,
  17. resp,
  18. )
  19. return resp, err
  20. }
  21. // UpdateEnvGroupInput is the input for the UpdateEnvGroup method
  22. type UpdateEnvGroupInput struct {
  23. ProjectID uint
  24. ClusterID uint
  25. EnvGroupName string
  26. Variables map[string]string
  27. Secrets map[string]string
  28. Deletions environment_groups.EnvVariableDeletions
  29. SkipRedeploys bool
  30. }
  31. // UpdateEnvGroup creates or updates an environment group with the provided variables
  32. func (c *Client) UpdateEnvGroup(
  33. ctx context.Context,
  34. inp UpdateEnvGroupInput,
  35. ) error {
  36. req := &environment_groups.UpdateEnvironmentGroupRequest{
  37. Name: inp.EnvGroupName,
  38. Variables: inp.Variables,
  39. SecretVariables: inp.Secrets,
  40. Deletions: inp.Deletions,
  41. SkipAppAutoDeploy: inp.SkipRedeploys,
  42. }
  43. return c.postRequest(
  44. fmt.Sprintf("/projects/%d/clusters/%d/environment-groups", inp.ProjectID, inp.ClusterID),
  45. req,
  46. nil,
  47. )
  48. }