secret.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // SecretFromGRPC converts a grpc Secret to a Secret.
  8. func SecretFromGRPC(s *swarmapi.Secret) swarmtypes.Secret {
  9. secret := swarmtypes.Secret{
  10. ID: s.ID,
  11. Spec: swarmtypes.SecretSpec{
  12. Annotations: annotationsFromGRPC(s.Spec.Annotations),
  13. Data: s.Spec.Data,
  14. Driver: driverFromGRPC(s.Spec.Driver),
  15. },
  16. }
  17. secret.Version.Index = s.Meta.Version.Index
  18. // Meta
  19. secret.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt)
  20. secret.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt)
  21. return secret
  22. }
  23. // SecretSpecToGRPC converts Secret to a grpc Secret.
  24. func SecretSpecToGRPC(s swarmtypes.SecretSpec) swarmapi.SecretSpec {
  25. return swarmapi.SecretSpec{
  26. Annotations: swarmapi.Annotations{
  27. Name: s.Name,
  28. Labels: s.Labels,
  29. },
  30. Data: s.Data,
  31. Driver: driverToGRPC(s.Driver),
  32. }
  33. }
  34. // SecretReferencesFromGRPC converts a slice of grpc SecretReference to SecretReference
  35. func SecretReferencesFromGRPC(s []*swarmapi.SecretReference) []*swarmtypes.SecretReference {
  36. refs := []*swarmtypes.SecretReference{}
  37. for _, r := range s {
  38. ref := &swarmtypes.SecretReference{
  39. SecretID: r.SecretID,
  40. SecretName: r.SecretName,
  41. }
  42. if t, ok := r.Target.(*swarmapi.SecretReference_File); ok {
  43. ref.File = &swarmtypes.SecretReferenceFileTarget{
  44. Name: t.File.Name,
  45. UID: t.File.UID,
  46. GID: t.File.GID,
  47. Mode: t.File.Mode,
  48. }
  49. }
  50. refs = append(refs, ref)
  51. }
  52. return refs
  53. }