github.com/lazyboychen7/engine@v17.12.1-ce-rc2+incompatible/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 gogotypes "github.com/gogo/protobuf/types" 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: annotationsFromGRPC(s.Spec.Annotations), 15 Data: s.Spec.Data, 16 Driver: driverFromGRPC(s.Spec.Driver), 17 }, 18 } 19 20 secret.Version.Index = s.Meta.Version.Index 21 // Meta 22 secret.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt) 23 secret.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt) 24 25 return secret 26 } 27 28 // SecretSpecToGRPC converts Secret to a grpc Secret. 29 func SecretSpecToGRPC(s swarmtypes.SecretSpec) swarmapi.SecretSpec { 30 return swarmapi.SecretSpec{ 31 Annotations: swarmapi.Annotations{ 32 Name: s.Name, 33 Labels: s.Labels, 34 }, 35 Data: s.Data, 36 Driver: driverToGRPC(s.Driver), 37 } 38 } 39 40 // SecretReferencesFromGRPC converts a slice of grpc SecretReference to SecretReference 41 func SecretReferencesFromGRPC(s []*swarmapi.SecretReference) []*swarmtypes.SecretReference { 42 refs := []*swarmtypes.SecretReference{} 43 44 for _, r := range s { 45 ref := &swarmtypes.SecretReference{ 46 SecretID: r.SecretID, 47 SecretName: r.SecretName, 48 } 49 50 if t, ok := r.Target.(*swarmapi.SecretReference_File); ok { 51 ref.File = &swarmtypes.SecretReferenceFileTarget{ 52 Name: t.File.Name, 53 UID: t.File.UID, 54 GID: t.File.GID, 55 Mode: t.File.Mode, 56 } 57 } 58 59 refs = append(refs, ref) 60 } 61 62 return refs 63 }