config.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package convert
  2. import (
  3. swarmtypes "github.com/docker/docker/api/types/swarm"
  4. swarmapi "github.com/docker/swarmkit/api"
  5. gogotypes "github.com/gogo/protobuf/types"
  6. )
  7. // ConfigFromGRPC converts a grpc Config to a Config.
  8. func ConfigFromGRPC(s *swarmapi.Config) swarmtypes.Config {
  9. config := swarmtypes.Config{
  10. ID: s.ID,
  11. Spec: swarmtypes.ConfigSpec{
  12. Annotations: annotationsFromGRPC(s.Spec.Annotations),
  13. Data: s.Spec.Data,
  14. },
  15. }
  16. config.Version.Index = s.Meta.Version.Index
  17. // Meta
  18. config.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt)
  19. config.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt)
  20. return config
  21. }
  22. // ConfigSpecToGRPC converts Config to a grpc Config.
  23. func ConfigSpecToGRPC(s swarmtypes.ConfigSpec) swarmapi.ConfigSpec {
  24. return swarmapi.ConfigSpec{
  25. Annotations: swarmapi.Annotations{
  26. Name: s.Name,
  27. Labels: s.Labels,
  28. },
  29. Data: s.Data,
  30. }
  31. }
  32. // ConfigReferencesFromGRPC converts a slice of grpc ConfigReference to ConfigReference
  33. func ConfigReferencesFromGRPC(s []*swarmapi.ConfigReference) []*swarmtypes.ConfigReference {
  34. refs := []*swarmtypes.ConfigReference{}
  35. for _, r := range s {
  36. ref := &swarmtypes.ConfigReference{
  37. ConfigID: r.ConfigID,
  38. ConfigName: r.ConfigName,
  39. }
  40. if t, ok := r.Target.(*swarmapi.ConfigReference_File); ok {
  41. ref.File = &swarmtypes.ConfigReferenceFileTarget{
  42. Name: t.File.Name,
  43. UID: t.File.UID,
  44. GID: t.File.GID,
  45. Mode: t.File.Mode,
  46. }
  47. }
  48. refs = append(refs, ref)
  49. }
  50. return refs
  51. }