secret.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. // 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. },
  15. }
  16. secret.Version.Index = s.Meta.Version.Index
  17. // Meta
  18. secret.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt)
  19. secret.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt)
  20. return secret
  21. }
  22. // SecretSpecToGRPC converts Secret to a grpc Secret.
  23. func SecretSpecToGRPC(s swarmtypes.SecretSpec) swarmapi.SecretSpec {
  24. return swarmapi.SecretSpec{
  25. Annotations: swarmapi.Annotations{
  26. Name: s.Name,
  27. Labels: s.Labels,
  28. },
  29. Data: s.Data,
  30. }
  31. }
  32. // SecretReferencesFromGRPC converts a slice of grpc SecretReference to SecretReference
  33. func SecretReferencesFromGRPC(s []*swarmapi.SecretReference) []*swarmtypes.SecretReference {
  34. refs := []*swarmtypes.SecretReference{}
  35. for _, r := range s {
  36. ref := &swarmtypes.SecretReference{
  37. SecretID: r.SecretID,
  38. SecretName: r.SecretName,
  39. }
  40. if t, ok := r.Target.(*swarmapi.SecretReference_File); ok {
  41. ref.File = &swarmtypes.SecretReferenceFileTarget{
  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. }