types.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. StackDelete
  19. )
  20. type LogConsumer interface {
  21. Log(service, container, message string)
  22. }
  23. type Secret struct {
  24. ID string `json:"ID"`
  25. Name string `json:"Name"`
  26. Labels map[string]string `json:"Labels"`
  27. Description string `json:"Description"`
  28. username string
  29. password string
  30. }
  31. func NewSecret(name, username, password, description string) Secret {
  32. return Secret{
  33. Name: name,
  34. username: username,
  35. password: password,
  36. Description: description,
  37. }
  38. }
  39. func (s Secret) ToJSON() (string, error) {
  40. b, err := json.MarshalIndent(&s, "", "\t")
  41. if err != nil {
  42. return "", err
  43. }
  44. return string(b), nil
  45. }
  46. func (s Secret) GetCredString() (string, error) {
  47. creds := map[string]string{
  48. "username": s.username,
  49. "password": s.password,
  50. }
  51. b, err := json.Marshal(&creds)
  52. if err != nil {
  53. return "", err
  54. }
  55. return string(b), nil
  56. }