github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/daemon/cluster/convert/config.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 // ConfigFromGRPC converts a grpc Config to a Config. 10 func ConfigFromGRPC(s *swarmapi.Config) swarmtypes.Config { 11 config := swarmtypes.Config{ 12 ID: s.ID, 13 Spec: swarmtypes.ConfigSpec{ 14 Annotations: annotationsFromGRPC(s.Spec.Annotations), 15 Data: s.Spec.Data, 16 }, 17 } 18 19 config.Version.Index = s.Meta.Version.Index 20 // Meta 21 config.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt) 22 config.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt) 23 24 return config 25 } 26 27 // ConfigSpecToGRPC converts Config to a grpc Config. 28 func ConfigSpecToGRPC(s swarmtypes.ConfigSpec) swarmapi.ConfigSpec { 29 return swarmapi.ConfigSpec{ 30 Annotations: swarmapi.Annotations{ 31 Name: s.Name, 32 Labels: s.Labels, 33 }, 34 Data: s.Data, 35 } 36 } 37 38 // ConfigReferencesFromGRPC converts a slice of grpc ConfigReference to ConfigReference 39 func ConfigReferencesFromGRPC(s []*swarmapi.ConfigReference) []*swarmtypes.ConfigReference { 40 refs := []*swarmtypes.ConfigReference{} 41 42 for _, r := range s { 43 ref := &swarmtypes.ConfigReference{ 44 ConfigID: r.ConfigID, 45 ConfigName: r.ConfigName, 46 } 47 48 if t, ok := r.Target.(*swarmapi.ConfigReference_File); ok { 49 ref.File = &swarmtypes.ConfigReferenceFileTarget{ 50 Name: t.File.Name, 51 UID: t.File.UID, 52 GID: t.File.GID, 53 Mode: t.File.Mode, 54 } 55 } 56 57 refs = append(refs, ref) 58 } 59 60 return refs 61 }