types.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package compose
  2. import "encoding/json"
  3. type StackResource struct {
  4. LogicalID string
  5. Type string
  6. ARN string
  7. Status string
  8. }
  9. type ServiceStatus struct {
  10. ID string
  11. Name string
  12. Replicas int
  13. Desired int
  14. Ports []string
  15. }
  16. const (
  17. StackCreate = iota
  18. StackUpdate
  19. StackDelete
  20. )
  21. type LogConsumer interface {
  22. Log(service, container, message string)
  23. }
  24. type Secret struct {
  25. ID string `json:"ID"`
  26. Name string `json:"Name"`
  27. Labels map[string]string `json:"Labels"`
  28. Description string `json:"Description"`
  29. username string
  30. password string
  31. }
  32. func NewSecret(name, username, password, description string) Secret {
  33. return Secret{
  34. Name: name,
  35. username: username,
  36. password: password,
  37. Description: description,
  38. }
  39. }
  40. func (s Secret) ToJSON() (string, error) {
  41. b, err := json.MarshalIndent(&s, "", "\t")
  42. if err != nil {
  43. return "", err
  44. }
  45. return string(b), nil
  46. }
  47. func (s Secret) GetCredString() (string, error) {
  48. creds := map[string]string{
  49. "username": s.username,
  50. "password": s.password,
  51. }
  52. b, err := json.Marshal(&creds)
  53. if err != nil {
  54. return "", err
  55. }
  56. return string(b), nil
  57. }