secret.go 1.5 KB

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