2018-02-05 16:05:59 -05:00
|
|
|
package convert // import "github.com/docker/docker/daemon/cluster/convert"
|
2016-10-19 12:22:02 -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"
|
2016-10-19 12:22:02 -04:00
|
|
|
swarmapi "github.com/docker/swarmkit/api"
|
2017-01-23 18:50:10 -05:00
|
|
|
gogotypes "github.com/gogo/protobuf/types"
|
2016-10-19 12:22:02 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// SecretFromGRPC converts a grpc Secret to a Secret.
|
|
|
|
func SecretFromGRPC(s *swarmapi.Secret) swarmtypes.Secret {
|
|
|
|
secret := swarmtypes.Secret{
|
2016-11-22 16:37:02 -05:00
|
|
|
ID: s.ID,
|
2016-11-07 16:18:53 -05:00
|
|
|
Spec: swarmtypes.SecretSpec{
|
2017-02-13 03:07:03 -05:00
|
|
|
Annotations: annotationsFromGRPC(s.Spec.Annotations),
|
|
|
|
Data: s.Spec.Data,
|
2017-07-15 09:03:17 -04:00
|
|
|
Driver: driverFromGRPC(s.Spec.Driver),
|
2016-11-07 16:18:53 -05:00
|
|
|
},
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
secret.Version.Index = s.Meta.Version.Index
|
2016-11-07 16:18:53 -05:00
|
|
|
// Meta
|
2017-01-23 18:50:10 -05:00
|
|
|
secret.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt)
|
|
|
|
secret.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt)
|
2016-10-19 12:22:02 -04:00
|
|
|
|
2017-06-15 14:28:41 -04:00
|
|
|
if s.Spec.Templating != nil {
|
|
|
|
secret.Spec.Templating = &types.Driver{
|
|
|
|
Name: s.Spec.Templating.Name,
|
|
|
|
Options: s.Spec.Templating.Options,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-19 12:22:02 -04:00
|
|
|
return secret
|
|
|
|
}
|
|
|
|
|
|
|
|
// SecretSpecToGRPC converts Secret to a grpc Secret.
|
2016-10-26 16:30:53 -04:00
|
|
|
func SecretSpecToGRPC(s swarmtypes.SecretSpec) swarmapi.SecretSpec {
|
2017-06-15 14:28:41 -04:00
|
|
|
spec := swarmapi.SecretSpec{
|
2016-10-19 12:22:02 -04:00
|
|
|
Annotations: swarmapi.Annotations{
|
|
|
|
Name: s.Name,
|
|
|
|
Labels: s.Labels,
|
|
|
|
},
|
2017-07-15 09:03:17 -04:00
|
|
|
Data: s.Data,
|
|
|
|
Driver: driverToGRPC(s.Driver),
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|
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
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|
2016-11-15 10:04:36 -05:00
|
|
|
|
2016-11-18 13:04:08 -05:00
|
|
|
// SecretReferencesFromGRPC converts a slice of grpc SecretReference to SecretReference
|
2016-11-15 10:04:36 -05:00
|
|
|
func SecretReferencesFromGRPC(s []*swarmapi.SecretReference) []*swarmtypes.SecretReference {
|
|
|
|
refs := []*swarmtypes.SecretReference{}
|
|
|
|
|
|
|
|
for _, r := range s {
|
|
|
|
ref := &swarmtypes.SecretReference{
|
|
|
|
SecretID: r.SecretID,
|
|
|
|
SecretName: r.SecretName,
|
|
|
|
}
|
|
|
|
|
|
|
|
if t, ok := r.Target.(*swarmapi.SecretReference_File); ok {
|
|
|
|
ref.File = &swarmtypes.SecretReferenceFileTarget{
|
|
|
|
Name: t.File.Name,
|
|
|
|
UID: t.File.UID,
|
|
|
|
GID: t.File.GID,
|
|
|
|
Mode: t.File.Mode,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
refs = append(refs, ref)
|
|
|
|
}
|
|
|
|
|
|
|
|
return refs
|
|
|
|
}
|