2016-10-19 12:22:02 -04:00
|
|
|
package convert
|
|
|
|
|
|
|
|
import (
|
|
|
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
|
|
|
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,
|
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
|
|
|
|
|
|
|
return secret
|
|
|
|
}
|
|
|
|
|
|
|
|
// SecretSpecToGRPC converts Secret to a grpc Secret.
|
2016-10-26 16:30:53 -04:00
|
|
|
func SecretSpecToGRPC(s swarmtypes.SecretSpec) swarmapi.SecretSpec {
|
|
|
|
return swarmapi.SecretSpec{
|
2016-10-19 12:22:02 -04:00
|
|
|
Annotations: swarmapi.Annotations{
|
|
|
|
Name: s.Name,
|
|
|
|
Labels: s.Labels,
|
|
|
|
},
|
|
|
|
Data: s.Data,
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
}
|