2018-02-05 16:05:59 -05:00
|
|
|
package convert // import "github.com/docker/docker/daemon/cluster/convert"
|
2017-03-15 17:52:17 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
2017-06-15 14:28:41 -04:00
|
|
|
types "github.com/docker/docker/api/types/swarm"
|
2017-03-15 17:52:17 -04:00
|
|
|
swarmapi "github.com/docker/swarmkit/api"
|
|
|
|
gogotypes "github.com/gogo/protobuf/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ConfigFromGRPC converts a grpc Config to a Config.
|
|
|
|
func ConfigFromGRPC(s *swarmapi.Config) swarmtypes.Config {
|
|
|
|
config := swarmtypes.Config{
|
|
|
|
ID: s.ID,
|
|
|
|
Spec: swarmtypes.ConfigSpec{
|
|
|
|
Annotations: annotationsFromGRPC(s.Spec.Annotations),
|
|
|
|
Data: s.Spec.Data,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Version.Index = s.Meta.Version.Index
|
|
|
|
// Meta
|
|
|
|
config.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt)
|
|
|
|
config.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt)
|
|
|
|
|
2017-06-15 14:28:41 -04:00
|
|
|
if s.Spec.Templating != nil {
|
|
|
|
config.Spec.Templating = &types.Driver{
|
|
|
|
Name: s.Spec.Templating.Name,
|
|
|
|
Options: s.Spec.Templating.Options,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 17:52:17 -04:00
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigSpecToGRPC converts Config to a grpc Config.
|
|
|
|
func ConfigSpecToGRPC(s swarmtypes.ConfigSpec) swarmapi.ConfigSpec {
|
2017-06-15 14:28:41 -04:00
|
|
|
spec := swarmapi.ConfigSpec{
|
2017-03-15 17:52:17 -04:00
|
|
|
Annotations: swarmapi.Annotations{
|
|
|
|
Name: s.Name,
|
|
|
|
Labels: s.Labels,
|
|
|
|
},
|
|
|
|
Data: s.Data,
|
|
|
|
}
|
2017-06-15 14:28:41 -04:00
|
|
|
|
|
|
|
if s.Templating != nil {
|
|
|
|
spec.Templating = &swarmapi.Driver{
|
|
|
|
Name: s.Templating.Name,
|
|
|
|
Options: s.Templating.Options,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return spec
|
2017-03-15 17:52:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigReferencesFromGRPC converts a slice of grpc ConfigReference to ConfigReference
|
|
|
|
func ConfigReferencesFromGRPC(s []*swarmapi.ConfigReference) []*swarmtypes.ConfigReference {
|
|
|
|
refs := []*swarmtypes.ConfigReference{}
|
|
|
|
|
|
|
|
for _, r := range s {
|
|
|
|
ref := &swarmtypes.ConfigReference{
|
|
|
|
ConfigID: r.ConfigID,
|
|
|
|
ConfigName: r.ConfigName,
|
|
|
|
}
|
|
|
|
|
|
|
|
if t, ok := r.Target.(*swarmapi.ConfigReference_File); ok {
|
|
|
|
ref.File = &swarmtypes.ConfigReferenceFileTarget{
|
|
|
|
Name: t.File.Name,
|
|
|
|
UID: t.File.UID,
|
|
|
|
GID: t.File.GID,
|
|
|
|
Mode: t.File.Mode,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
refs = append(refs, ref)
|
|
|
|
}
|
|
|
|
|
|
|
|
return refs
|
|
|
|
}
|