env_groups.go 1.3 KB

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