Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugins: experimental support for new plugin management #23446

Merged
merged 3 commits into from
Jun 15, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
plugins: vendor engine-api to import new plugin types
Signed-off-by: Tibor Vass <tibor@docker.com>
  • Loading branch information
Tibor Vass committed Jun 14, 2016
commit e5b7d36e9954ffd8c199c0fcfaa0b9f4bfdeb196
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 6b2f24f16a7f1598635b6a99dbe38ec8a5eccaf8
clone git github.com/docker/engine-api f3b5ad20d4576de14c96603db522dec530d03f62
clone git github.com/RackSec/srslog 259aed10dfa74ea2961eddd1d9847619f6e98837
clone git github.com/imdario/mergo 0.2.1

Expand Down
15 changes: 15 additions & 0 deletions vendor/src/github.com/docker/engine-api/client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,18 @@ func IsErrTaskNotFound(err error) bool {
_, ok := err.(taskNotFoundError)
return ok
}

type pluginPermissionDenied struct {
name string
}

func (e pluginPermissionDenied) Error() string {
return "Permission denied while installing plugin " + e.name
}

// IsErrPluginPermissionDenied returns true if the error is caused
// when a user denies a plugin's permissions
func IsErrPluginPermissionDenied(err error) bool {
_, ok := err.(pluginPermissionDenied)
return ok
}
10 changes: 3 additions & 7 deletions vendor/src/github.com/docker/engine-api/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import (
"io"
"time"

"golang.org/x/net/context"

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

// APIClient is an interface that clients that talk with a docker server must implement.
type APIClient interface {
// CommonAPIClient is the common methods between stable and experimental versions of APIClient.
type CommonAPIClient interface {
ClientVersion() string
CheckpointCreate(ctx context.Context, container string, options types.CheckpointCreateOptions) error
CheckpointDelete(ctx context.Context, container string, checkpointID string) error
Expand Down Expand Up @@ -97,6 +96,3 @@ type APIClient interface {
VolumeList(ctx context.Context, filter filters.Args) (types.VolumesListResponse, error)
VolumeRemove(ctx context.Context, volumeID string) error
}

// Ensure that Client always implements APIClient.
var _ APIClient = &Client{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// +build experimental

package client

import (
"io"

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

// APIClient is an interface that clients that talk with a docker server must implement.
type APIClient interface {
CommonAPIClient
PluginList(ctx context.Context) (types.PluginsListResponse, error)
PluginRemove(ctx context.Context, name string) error
PluginEnable(ctx context.Context, name string) error
PluginDisable(ctx context.Context, name string) error
PluginInstall(ctx context.Context, name, registryAuth string, acceptAllPermissions, noEnable bool, in io.ReadCloser, out io.Writer) error
PluginPush(ctx context.Context, name string, registryAuth string) error
PluginSet(ctx context.Context, name string, args []string) error
PluginInspect(ctx context.Context, name string) (*types.Plugin, error)
}

// Ensure that Client always implements APIClient.
var _ APIClient = &Client{}
11 changes: 11 additions & 0 deletions vendor/src/github.com/docker/engine-api/client/interface_stable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !experimental

package client

// APIClient is an interface that clients that talk with a docker server must implement.
type APIClient interface {
CommonAPIClient
}

// Ensure that Client always implements APIClient.
var _ APIClient = &Client{}
14 changes: 14 additions & 0 deletions vendor/src/github.com/docker/engine-api/client/plugin_disable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// +build experimental

package client

import (
"golang.org/x/net/context"
)

// PluginDisable disables a plugin
func (cli *Client) PluginDisable(ctx context.Context, name string) error {
resp, err := cli.post(ctx, "/plugins/"+name+"/disable", nil, nil, nil)
ensureReaderClosed(resp)
return err
}
14 changes: 14 additions & 0 deletions vendor/src/github.com/docker/engine-api/client/plugin_enable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// +build experimental

package client

import (
"golang.org/x/net/context"
)

// PluginEnable enables a plugin
func (cli *Client) PluginEnable(ctx context.Context, name string) error {
resp, err := cli.post(ctx, "/plugins/"+name+"/enable", nil, nil, nil)
ensureReaderClosed(resp)
return err
}
22 changes: 22 additions & 0 deletions vendor/src/github.com/docker/engine-api/client/plugin_inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// +build experimental

package client

import (
"encoding/json"

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

// PluginInspect inspects an existing plugin
func (cli *Client) PluginInspect(ctx context.Context, name string) (*types.Plugin, error) {
var p types.Plugin
resp, err := cli.get(ctx, "/plugins/"+name, nil, nil)
if err != nil {
return nil, err
}
err = json.NewDecoder(resp.body).Decode(&p)
ensureReaderClosed(resp)
return &p, err
}
54 changes: 54 additions & 0 deletions vendor/src/github.com/docker/engine-api/client/plugin_install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// +build experimental

package client

import (
"bufio"
"encoding/json"
"fmt"
"io"
"net/url"
"strings"

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

// PluginInstall installs a plugin
func (cli *Client) PluginInstall(ctx context.Context, name, registryAuth string, acceptAllPermissions, noEnable bool, in io.ReadCloser, out io.Writer) error {
headers := map[string][]string{"X-Registry-Auth": {registryAuth}}
resp, err := cli.post(ctx, "/plugins/pull", url.Values{"name": []string{name}}, nil, headers)
if err != nil {
ensureReaderClosed(resp)
return err
}
var privileges types.PluginPrivileges
if err := json.NewDecoder(resp.body).Decode(&privileges); err != nil {
return err
}
ensureReaderClosed(resp)

if !acceptAllPermissions && len(privileges) > 0 {

fmt.Fprintf(out, "Plugin %q requested the following privileges:\n", name)
for _, privilege := range privileges {
fmt.Fprintf(out, " - %s: %v\n", privilege.Name, privilege.Value)
}

fmt.Fprint(out, "Do you grant the above permissions? [y/N] ")
reader := bufio.NewReader(in)
line, _, err := reader.ReadLine()
if err != nil {
return err
}
if strings.ToLower(string(line)) != "y" {
resp, _ := cli.delete(ctx, "/plugins/"+name, nil, nil)
ensureReaderClosed(resp)
return pluginPermissionDenied{name}
}
}
if noEnable {
return nil
}
return cli.PluginEnable(ctx, name)
}
23 changes: 23 additions & 0 deletions vendor/src/github.com/docker/engine-api/client/plugin_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// +build experimental

package client

import (
"encoding/json"

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

// PluginList returns the installed plugins
func (cli *Client) PluginList(ctx context.Context) (types.PluginsListResponse, error) {
var plugins types.PluginsListResponse
resp, err := cli.get(ctx, "/plugins", nil, nil)
if err != nil {
return plugins, err
}

err = json.NewDecoder(resp.body).Decode(&plugins)
ensureReaderClosed(resp)
return plugins, err
}
15 changes: 15 additions & 0 deletions vendor/src/github.com/docker/engine-api/client/plugin_push.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// +build experimental

package client

import (
"golang.org/x/net/context"
)

// PluginPush pushes a plugin to a registry
func (cli *Client) PluginPush(ctx context.Context, name string, registryAuth string) error {
headers := map[string][]string{"X-Registry-Auth": {registryAuth}}
resp, err := cli.post(ctx, "/plugins/"+name+"/push", nil, nil, headers)
ensureReaderClosed(resp)
return err
}
14 changes: 14 additions & 0 deletions vendor/src/github.com/docker/engine-api/client/plugin_remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// +build experimental

package client

import (
"golang.org/x/net/context"
)

// PluginRemove removes a plugin
func (cli *Client) PluginRemove(ctx context.Context, name string) error {
resp, err := cli.delete(ctx, "/plugins/"+name, nil, nil)
ensureReaderClosed(resp)
return err
}
14 changes: 14 additions & 0 deletions vendor/src/github.com/docker/engine-api/client/plugin_set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// +build experimental

package client

import (
"golang.org/x/net/context"
)

// PluginSet modifies settings for an existing plugin
func (cli *Client) PluginSet(ctx context.Context, name string, args []string) error {
resp, err := cli.post(ctx, "/plugins/"+name+"/set", nil, args, nil)
ensureReaderClosed(resp)
return err
}
Loading