2018-02-05 21:05:59 +00:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2017-01-29 00:54:32 +00:00
|
|
|
|
|
|
|
import (
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2017-01-29 00:54:32 +00:00
|
|
|
"io"
|
2023-07-10 14:44:59 +00:00
|
|
|
"net/http"
|
2017-01-29 00:54:32 +00:00
|
|
|
"net/url"
|
|
|
|
|
2023-08-30 16:31:46 +00:00
|
|
|
"github.com/distribution/reference"
|
2017-01-29 00:54:32 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
2021-08-26 19:08:38 +00:00
|
|
|
"github.com/docker/docker/api/types/registry"
|
2017-01-29 00:54:32 +00: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) {
|
2023-09-12 12:08:54 +00:00
|
|
|
if err := cli.NewVersionError(ctx, "1.26", "plugin upgrade"); err != nil {
|
2017-06-07 16:09:07 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2017-01-29 00:54:32 +00:00
|
|
|
query := url.Values{}
|
2017-01-26 00:54:18 +00:00
|
|
|
if _, err := reference.ParseNormalizedNamed(options.RemoteRef); err != nil {
|
2017-01-29 00:54:32 +00: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) {
|
2023-07-10 14:44:59 +00:00
|
|
|
return cli.post(ctx, "/plugins/"+name+"/upgrade", query, privileges, http.Header{
|
|
|
|
registry.AuthHeader: {registryAuth},
|
|
|
|
})
|
2017-01-29 00:54:32 +00:00
|
|
|
}
|