Skip to content

Commit

Permalink
re-vendor engine-api
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
  • Loading branch information
Brian Goff authored and cpuguy83 committed Jul 7, 2016
1 parent a04a11f commit 140ec59
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 19 deletions.
7 changes: 4 additions & 3 deletions api/client/service/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/docker/docker/api/client"
"github.com/docker/docker/cli"
"github.com/docker/engine-api/types"
"github.com/spf13/cobra"
"golang.org/x/net/context"
)
Expand Down Expand Up @@ -33,7 +34,7 @@ func newCreateCommand(dockerCli *client.DockerCli) *cobra.Command {

func runCreate(dockerCli *client.DockerCli, opts *serviceOptions) error {
apiClient := dockerCli.Client()
headers := map[string][]string{}
createOpts := types.ServiceCreateOptions{}

service, err := opts.ToService()
if err != nil {
Expand All @@ -49,10 +50,10 @@ func runCreate(dockerCli *client.DockerCli, opts *serviceOptions) error {
if err != nil {
return err
}
headers["X-Registry-Auth"] = []string{encodedAuth}
createOpts.EncodedRegistryAuth = encodedAuth
}

response, err := apiClient.ServiceCreate(ctx, service, headers)
response, err := apiClient.ServiceCreate(ctx, service, createOpts)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion api/client/service/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func printContainerSpec(out io.Writer, containerSpec swarm.ContainerSpec) {
for _, v := range containerSpec.Mounts {
fmt.Fprintf(out, " Target = %s\n", v.Target)
fmt.Fprintf(out, " Source = %s\n", v.Source)
fmt.Fprintf(out, " Writable = %v\n", v.Writable)
fmt.Fprintf(out, " ReadOnly = %v\n", v.ReadOnly)
fmt.Fprintf(out, " Type = %v\n", v.Type)
}
}
Expand Down
3 changes: 2 additions & 1 deletion api/client/service/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/docker/docker/api/client"
"github.com/docker/docker/cli"
"github.com/docker/engine-api/types"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -77,7 +78,7 @@ func runServiceScale(dockerCli *client.DockerCli, serviceID string, scale string
}
serviceMode.Replicated.Replicas = &uintScale

err = client.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, nil)
err = client.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, types.ServiceUpdateOptions{})
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions api/client/service/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/docker/docker/cli"
"github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/swarm"
"github.com/docker/go-connections/nat"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -39,7 +40,7 @@ func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command {
func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, serviceID string) error {
apiClient := dockerCli.Client()
ctx := context.Background()
headers := map[string][]string{}
updateOpts := types.ServiceUpdateOptions{}

service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID)
if err != nil {
Expand All @@ -64,10 +65,10 @@ func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, serviceID stri
if err != nil {
return err
}
headers["X-Registry-Auth"] = []string{encodedAuth}
updateOpts.EncodedRegistryAuth = encodedAuth
}

err = apiClient.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, headers)
err = apiClient.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, updateOpts)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions api/client/stack/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,21 @@ func deployServices(
if service, exists := existingServiceMap[name]; exists {
fmt.Fprintf(out, "Updating service %s (id: %s)\n", name, service.ID)

// TODO(nishanttotla): Pass headers with X-Registry-Auth
// TODO(nishanttotla): Pass auth token
if err := apiClient.ServiceUpdate(
ctx,
service.ID,
service.Version,
serviceSpec,
nil,
types.ServiceUpdateOptions{},
); err != nil {
return err
}
} else {
fmt.Fprintf(out, "Creating service %s\n", name)

// TODO(nishanttotla): Pass headers with X-Registry-Auth
if _, err := apiClient.ServiceCreate(ctx, serviceSpec, nil); err != nil {
if _, err := apiClient.ServiceCreate(ctx, serviceSpec, types.ServiceCreateOptions{}); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion hack/vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ clone git golang.org/x/net 2beffdc2e92c8a3027590f898fe88f69af48a3f8 https://gith
clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git
clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3
clone git github.com/docker/go-connections fa2850ff103453a9ad190da0df0af134f0314b3d
clone git github.com/docker/engine-api 62043eb79d581a32ea849645277023c550732e52
clone git github.com/docker/engine-api 139c221fcbe6e67dfac3c8807870e7136884a45b
clone git github.com/RackSec/srslog 259aed10dfa74ea2961eddd1d9847619f6e98837
clone git github.com/imdario/mergo 0.2.1

Expand Down
4 changes: 2 additions & 2 deletions vendor/src/github.com/docker/engine-api/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ type NodeAPIClient interface {

// ServiceAPIClient defines API client methods for the services
type ServiceAPIClient interface {
ServiceCreate(ctx context.Context, service swarm.ServiceSpec, headers map[string][]string) (types.ServiceCreateResponse, error)
ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (types.ServiceCreateResponse, error)
ServiceInspectWithRaw(ctx context.Context, serviceID string) (swarm.Service, []byte, error)
ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
ServiceRemove(ctx context.Context, serviceID string) error
ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, headers map[string][]string) error
ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) error
TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error)
TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ import (
)

// ServiceCreate creates a new Service.
func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, headers map[string][]string) (types.ServiceCreateResponse, error) {
func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (types.ServiceCreateResponse, error) {
var headers map[string][]string

if options.EncodedRegistryAuth != "" {
headers = map[string][]string{
"X-Registry-Auth": []string{options.EncodedRegistryAuth},
}
}

var response types.ServiceCreateResponse
resp, err := cli.post(ctx, "/services/create", nil, service, headers)
if err != nil {
Expand Down
16 changes: 14 additions & 2 deletions vendor/src/github.com/docker/engine-api/client/service_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@ import (
"net/url"
"strconv"

"github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/swarm"
"golang.org/x/net/context"
)

// ServiceUpdate updates a Service.
func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, headers map[string][]string) error {
query := url.Values{}
func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) error {
var (
headers map[string][]string
query = url.Values{}
)

if options.EncodedRegistryAuth != "" {
headers = map[string][]string{
"X-Registry-Auth": []string{options.EncodedRegistryAuth},
}
}

query.Set("version", strconv.FormatUint(version.Index, 10))

resp, err := cli.post(ctx, "/services/"+serviceID+"/update", query, service, headers)
ensureReaderClosed(resp)
return err
Expand Down
22 changes: 22 additions & 0 deletions vendor/src/github.com/docker/engine-api/types/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,35 @@ type NodeListOptions struct {
Filter filters.Args
}

// ServiceCreateOptions contains the options to use when creating a service.
type ServiceCreateOptions struct {
// EncodedRegistryAuth is the encoded registry authorization credentials to
// use when updating the service.
//
// This field follows the format of the X-Registry-Auth header.
EncodedRegistryAuth string
}

// ServiceCreateResponse contains the information returned to a client
// on the creation of a new service.
type ServiceCreateResponse struct {
// ID is the ID of the created service.
ID string
}

// ServiceUpdateOptions contains the options to be used for updating services.
type ServiceUpdateOptions struct {
// EncodedRegistryAuth is the encoded registry authorization credentials to
// use when updating the service.
//
// This field follows the format of the X-Registry-Auth header.
EncodedRegistryAuth string

// TODO(stevvooe): Consider moving the version parameter of ServiceUpdate
// into this field. While it does open API users up to racy writes, most
// users may not need that level of consistency in practice.
}

// ServiceListOptions holds parameters to list services with.
type ServiceListOptions struct {
Filter filters.Args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Mount struct {
Type MountType `json:",omitempty"`
Source string `json:",omitempty"`
Target string `json:",omitempty"`
Writable bool `json:",omitempty"`
ReadOnly bool `json:",omitempty"`

BindOptions *BindOptions `json:",omitempty"`
VolumeOptions *VolumeOptions `json:",omitempty"`
Expand Down Expand Up @@ -61,7 +61,7 @@ type BindOptions struct {

// VolumeOptions represents the options for a mount of type volume.
type VolumeOptions struct {
Populate bool `json:",omitempty"`
NoCopy bool `json:",omitempty"`
Labels map[string]string `json:",omitempty"`
DriverConfig *Driver `json:",omitempty"`
}

0 comments on commit 140ec59

Please sign in to comment.