types.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 LoadBalancer struct {
  10. URL string
  11. TargetPort int
  12. PublishedPort int
  13. Protocol string
  14. }
  15. type ServiceStatus struct {
  16. ID string
  17. Name string
  18. Replicas int
  19. Desired int
  20. Ports []string
  21. LoadBalancers []LoadBalancer
  22. }
  23. const (
  24. StackCreate = iota
  25. StackUpdate
  26. StackDelete
  27. )
  28. type LogConsumer interface {
  29. Log(service, container, message string)
  30. }
  31. type Secret struct {
  32. ID string `json:"ID"`
  33. Name string `json:"Name"`
  34. Labels map[string]string `json:"Labels"`
  35. Description string `json:"Description"`
  36. username string
  37. password string
  38. }
  39. func NewSecret(name, username, password, description string) Secret {
  40. return Secret{
  41. Name: name,
  42. username: username,
  43. password: password,
  44. Description: description,
  45. }
  46. }
  47. func (s Secret) ToJSON() (string, error) {
  48. b, err := json.MarshalIndent(&s, "", "\t")
  49. if err != nil {
  50. return "", err
  51. }
  52. return string(b), nil
  53. }
  54. func (s Secret) GetCredString() (string, error) {
  55. creds := map[string]string{
  56. "username": s.username,
  57. "password": s.password,
  58. }
  59. b, err := json.Marshal(&creds)
  60. if err != nil {
  61. return "", err
  62. }
  63. return string(b), nil
  64. }