github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/daemon/cluster/convert/secret.go (about) 1 package convert // import "github.com/demonoid81/moby/daemon/cluster/convert" 2 3 import ( 4 swarmtypes "github.com/demonoid81/moby/api/types/swarm" 5 types "github.com/demonoid81/moby/api/types/swarm" 6 swarmapi "github.com/docker/swarmkit/api" 7 gogotypes "github.com/gogo/protobuf/types" 8 ) 9 10 // SecretFromGRPC converts a grpc Secret to a Secret. 11 func SecretFromGRPC(s *swarmapi.Secret) swarmtypes.Secret { 12 secret := swarmtypes.Secret{ 13 ID: s.ID, 14 Spec: swarmtypes.SecretSpec{ 15 Annotations: annotationsFromGRPC(s.Spec.Annotations), 16 Data: s.Spec.Data, 17 Driver: driverFromGRPC(s.Spec.Driver), 18 }, 19 } 20 21 secret.Version.Index = s.Meta.Version.Index 22 // Meta 23 secret.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt) 24 secret.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt) 25 26 if s.Spec.Templating != nil { 27 secret.Spec.Templating = &types.Driver{ 28 Name: s.Spec.Templating.Name, 29 Options: s.Spec.Templating.Options, 30 } 31 } 32 33 return secret 34 } 35 36 // SecretSpecToGRPC converts Secret to a grpc Secret. 37 func SecretSpecToGRPC(s swarmtypes.SecretSpec) swarmapi.SecretSpec { 38 spec := swarmapi.SecretSpec{ 39 Annotations: swarmapi.Annotations{ 40 Name: s.Name, 41 Labels: s.Labels, 42 }, 43 Data: s.Data, 44 Driver: driverToGRPC(s.Driver), 45 } 46 47 if s.Templating != nil { 48 spec.Templating = &swarmapi.Driver{ 49 Name: s.Templating.Name, 50 Options: s.Templating.Options, 51 } 52 } 53 54 return spec 55 } 56 57 // SecretReferencesFromGRPC converts a slice of grpc SecretReference to SecretReference 58 func SecretReferencesFromGRPC(s []*swarmapi.SecretReference) []*swarmtypes.SecretReference { 59 refs := []*swarmtypes.SecretReference{} 60 61 for _, r := range s { 62 ref := &swarmtypes.SecretReference{ 63 SecretID: r.SecretID, 64 SecretName: r.SecretName, 65 } 66 67 if t, ok := r.Target.(*swarmapi.SecretReference_File); ok { 68 ref.File = &swarmtypes.SecretReferenceFileTarget{ 69 Name: t.File.Name, 70 UID: t.File.UID, 71 GID: t.File.GID, 72 Mode: t.File.Mode, 73 } 74 } 75 76 refs = append(refs, ref) 77 } 78 79 return refs 80 }