github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/daemon/cluster/convert/config.go (about)

     1  package convert // import "github.com/docker/docker/daemon/cluster/convert"
     2  
     3  import (
     4  	swarmtypes "github.com/docker/docker/api/types/swarm"
     5  	types "github.com/docker/docker/api/types/swarm"
     6  	swarmapi "github.com/docker/swarmkit/api"
     7  	gogotypes "github.com/gogo/protobuf/types"
     8  )
     9  
    10  // ConfigFromGRPC converts a grpc Config to a Config.
    11  func ConfigFromGRPC(s *swarmapi.Config) swarmtypes.Config {
    12  	config := swarmtypes.Config{
    13  		ID: s.ID,
    14  		Spec: swarmtypes.ConfigSpec{
    15  			Annotations: annotationsFromGRPC(s.Spec.Annotations),
    16  			Data:        s.Spec.Data,
    17  		},
    18  	}
    19  
    20  	config.Version.Index = s.Meta.Version.Index
    21  	// Meta
    22  	config.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt)
    23  	config.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt)
    24  
    25  	if s.Spec.Templating != nil {
    26  		config.Spec.Templating = &types.Driver{
    27  			Name:    s.Spec.Templating.Name,
    28  			Options: s.Spec.Templating.Options,
    29  		}
    30  	}
    31  
    32  	return config
    33  }
    34  
    35  // ConfigSpecToGRPC converts Config to a grpc Config.
    36  func ConfigSpecToGRPC(s swarmtypes.ConfigSpec) swarmapi.ConfigSpec {
    37  	spec := swarmapi.ConfigSpec{
    38  		Annotations: swarmapi.Annotations{
    39  			Name:   s.Name,
    40  			Labels: s.Labels,
    41  		},
    42  		Data: s.Data,
    43  	}
    44  
    45  	if s.Templating != nil {
    46  		spec.Templating = &swarmapi.Driver{
    47  			Name:    s.Templating.Name,
    48  			Options: s.Templating.Options,
    49  		}
    50  	}
    51  
    52  	return spec
    53  }
    54  
    55  // ConfigReferencesFromGRPC converts a slice of grpc ConfigReference to ConfigReference
    56  func ConfigReferencesFromGRPC(s []*swarmapi.ConfigReference) []*swarmtypes.ConfigReference {
    57  	refs := []*swarmtypes.ConfigReference{}
    58  
    59  	for _, r := range s {
    60  		ref := &swarmtypes.ConfigReference{
    61  			ConfigID:   r.ConfigID,
    62  			ConfigName: r.ConfigName,
    63  		}
    64  
    65  		if t, ok := r.Target.(*swarmapi.ConfigReference_File); ok {
    66  			ref.File = &swarmtypes.ConfigReferenceFileTarget{
    67  				Name: t.File.Name,
    68  				UID:  t.File.UID,
    69  				GID:  t.File.GID,
    70  				Mode: t.File.Mode,
    71  			}
    72  		}
    73  
    74  		refs = append(refs, ref)
    75  	}
    76  
    77  	return refs
    78  }