github.com/opsramp/moby@v1.13.1/daemon/cluster/convert/secret.go (about) 1 package convert 2 3 import ( 4 swarmtypes "github.com/docker/docker/api/types/swarm" 5 swarmapi "github.com/docker/swarmkit/api" 6 "github.com/docker/swarmkit/protobuf/ptypes" 7 ) 8 9 // SecretFromGRPC converts a grpc Secret to a Secret. 10 func SecretFromGRPC(s *swarmapi.Secret) swarmtypes.Secret { 11 secret := swarmtypes.Secret{ 12 ID: s.ID, 13 Spec: swarmtypes.SecretSpec{ 14 Annotations: swarmtypes.Annotations{ 15 Name: s.Spec.Annotations.Name, 16 Labels: s.Spec.Annotations.Labels, 17 }, 18 Data: s.Spec.Data, 19 }, 20 } 21 22 secret.Version.Index = s.Meta.Version.Index 23 // Meta 24 secret.CreatedAt, _ = ptypes.Timestamp(s.Meta.CreatedAt) 25 secret.UpdatedAt, _ = ptypes.Timestamp(s.Meta.UpdatedAt) 26 27 return secret 28 } 29 30 // SecretSpecToGRPC converts Secret to a grpc Secret. 31 func SecretSpecToGRPC(s swarmtypes.SecretSpec) swarmapi.SecretSpec { 32 return swarmapi.SecretSpec{ 33 Annotations: swarmapi.Annotations{ 34 Name: s.Name, 35 Labels: s.Labels, 36 }, 37 Data: s.Data, 38 } 39 } 40 41 // SecretReferencesFromGRPC converts a slice of grpc SecretReference to SecretReference 42 func SecretReferencesFromGRPC(s []*swarmapi.SecretReference) []*swarmtypes.SecretReference { 43 refs := []*swarmtypes.SecretReference{} 44 45 for _, r := range s { 46 ref := &swarmtypes.SecretReference{ 47 SecretID: r.SecretID, 48 SecretName: r.SecretName, 49 } 50 51 if t, ok := r.Target.(*swarmapi.SecretReference_File); ok { 52 ref.File = &swarmtypes.SecretReferenceFileTarget{ 53 Name: t.File.Name, 54 UID: t.File.UID, 55 GID: t.File.GID, 56 Mode: t.File.Mode, 57 } 58 } 59 60 refs = append(refs, ref) 61 } 62 63 return refs 64 }