env_groups.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. }
  30. // UpdateEnvGroup creates or updates an environment group with the provided variables
  31. func (c *Client) UpdateEnvGroup(
  32. ctx context.Context,
  33. inp UpdateEnvGroupInput,
  34. ) error {
  35. req := &environment_groups.UpdateEnvironmentGroupRequest{
  36. Name: inp.EnvGroupName,
  37. Variables: inp.Variables,
  38. SecretVariables: inp.Secrets,
  39. Deletions: inp.Deletions,
  40. }
  41. return c.postRequest(
  42. fmt.Sprintf("/projects/%d/clusters/%d/environment-groups", inp.ProjectID, inp.ClusterID),
  43. req,
  44. nil,
  45. )
  46. }