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"
|
|
|
|
"github.com/docker/swarmkit/protobuf/ptypes"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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{
|
|
|
|
Annotations: swarmtypes.Annotations{
|
|
|
|
Name: s.Spec.Annotations.Name,
|
|
|
|
Labels: s.Spec.Annotations.Labels,
|
|
|
|
},
|
|
|
|
Data: s.Spec.Data,
|
|
|
|
},
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
secret.Version.Index = s.Meta.Version.Index
|
2016-11-07 16:18:53 -05:00
|
|
|
// Meta
|
2016-10-19 12:22:02 -04:00
|
|
|
secret.CreatedAt, _ = ptypes.Timestamp(s.Meta.CreatedAt)
|
|
|
|
secret.UpdatedAt, _ = ptypes.Timestamp(s.Meta.UpdatedAt)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|