2018-02-05 16:05:59 -05:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2017-01-28 19:54:32 -05:00
|
|
|
|
|
|
|
import (
|
2018-04-19 18:30:59 -04:00
|
|
|
"context"
|
2017-01-28 19:54:32 -05:00
|
|
|
"io"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/docker/distribution/reference"
|
|
|
|
"github.com/docker/docker/api/types"
|
2021-08-26 15:08:38 -04:00
|
|
|
"github.com/docker/docker/api/types/registry"
|
2017-01-28 19:54:32 -05:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PluginUpgrade upgrades a plugin
|
|
|
|
func (cli *Client) PluginUpgrade(ctx context.Context, name string, options types.PluginInstallOptions) (rc io.ReadCloser, err error) {
|
2017-06-07 12:09:07 -04:00
|
|
|
if err := cli.NewVersionError("1.26", "plugin upgrade"); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-01-28 19:54:32 -05:00
|
|
|
query := url.Values{}
|
2017-01-25 19:54:18 -05:00
|
|
|
if _, err := reference.ParseNormalizedNamed(options.RemoteRef); err != nil {
|
2017-01-28 19:54:32 -05:00
|
|
|
return nil, errors.Wrap(err, "invalid remote reference")
|
|
|
|
}
|
|
|
|
query.Set("remote", options.RemoteRef)
|
|
|
|
|
|
|
|
privileges, err := cli.checkPluginPermissions(ctx, query, options)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := cli.tryPluginUpgrade(ctx, query, privileges, name, options.RegistryAuth)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp.body, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *Client) tryPluginUpgrade(ctx context.Context, query url.Values, privileges types.PluginPrivileges, name, registryAuth string) (serverResponse, error) {
|
2021-08-26 15:08:38 -04:00
|
|
|
headers := map[string][]string{registry.AuthHeader: {registryAuth}}
|
2017-06-02 08:00:56 -04:00
|
|
|
return cli.post(ctx, "/plugins/"+name+"/upgrade", query, privileges, headers)
|
2017-01-28 19:54:32 -05:00
|
|
|
}
|