types.go 1.4 KB

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