github.com/jiasir/docker@v1.3.3-0.20170609024000-252e610103e7/daemon/cluster/convert/secret.go (about)

     1  package convert
     2  
     3  import (
     4  	swarmtypes "github.com/docker/docker/api/types/swarm"
     5  	swarmapi "github.com/docker/swarmkit/api"
     6  	gogotypes "github.com/gogo/protobuf/types"
     7  )
     8  
     9  // SecretFromGRPC converts a grpc Secret to a Secret.
    10  func SecretFromGRPC(s *swarmapi.Secret) swarmtypes.Secret {
    11  	secret := swarmtypes.Secret{
    12  		ID: s.ID,
    13  		Spec: swarmtypes.SecretSpec{
    14  			Annotations: annotationsFromGRPC(s.Spec.Annotations),
    15  			Data:        s.Spec.Data,
    16  		},
    17  	}
    18  
    19  	secret.Version.Index = s.Meta.Version.Index
    20  	// Meta
    21  	secret.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt)
    22  	secret.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt)
    23  
    24  	return secret
    25  }
    26  
    27  // SecretSpecToGRPC converts Secret to a grpc Secret.
    28  func SecretSpecToGRPC(s swarmtypes.SecretSpec) swarmapi.SecretSpec {
    29  	return swarmapi.SecretSpec{
    30  		Annotations: swarmapi.Annotations{
    31  			Name:   s.Name,
    32  			Labels: s.Labels,
    33  		},
    34  		Data: s.Data,
    35  	}
    36  }
    37  
    38  // SecretReferencesFromGRPC converts a slice of grpc SecretReference to SecretReference
    39  func SecretReferencesFromGRPC(s []*swarmapi.SecretReference) []*swarmtypes.SecretReference {
    40  	refs := []*swarmtypes.SecretReference{}
    41  
    42  	for _, r := range s {
    43  		ref := &swarmtypes.SecretReference{
    44  			SecretID:   r.SecretID,
    45  			SecretName: r.SecretName,
    46  		}
    47  
    48  		if t, ok := r.Target.(*swarmapi.SecretReference_File); ok {
    49  			ref.File = &swarmtypes.SecretReferenceFileTarget{
    50  				Name: t.File.Name,
    51  				UID:  t.File.UID,
    52  				GID:  t.File.GID,
    53  				Mode: t.File.Mode,
    54  			}
    55  		}
    56  
    57  		refs = append(refs, ref)
    58  	}
    59  
    60  	return refs
    61  }