From d7ef714a4c500276b2c1ba8e7d3482dbdd1d1c41 Mon Sep 17 00:00:00 2001 From: Martin Norbury Date: Mon, 13 Nov 2023 16:58:30 +0000 Subject: [PATCH 1/4] feat: Allow plugins to be downloaded using a user `team_name` context --- go.mod | 2 +- go.sum | 4 +- managedplugin/download.go | 71 ++++++++++++++++++++++------------ managedplugin/download_test.go | 2 +- managedplugin/options.go | 6 +++ managedplugin/plugin.go | 3 +- 6 files changed, 59 insertions(+), 29 deletions(-) diff --git a/go.mod b/go.mod index f55a00a..2d08a91 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21.1 require ( github.com/apache/arrow/go/v14 v14.0.0-20231031200323-c49e24273160 github.com/avast/retry-go/v4 v4.5.0 - github.com/cloudquery/cloudquery-api-go v1.4.4 + github.com/cloudquery/cloudquery-api-go v1.4.5 github.com/docker/docker v24.0.7+incompatible github.com/docker/go-connections v0.4.0 github.com/ghodss/yaml v1.0.0 diff --git a/go.sum b/go.sum index 2484290..e76801c 100644 --- a/go.sum +++ b/go.sum @@ -38,8 +38,8 @@ github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= github.com/cloudquery/arrow/go/v14 v14.0.0-20231029080147-50d3871d0804 h1:y4EwAGtbzVFz1w9sXggukJmYMVO12925D12Bak7s0vI= github.com/cloudquery/arrow/go/v14 v14.0.0-20231029080147-50d3871d0804/go.mod h1:TqWp9yvMb9yZSxFNiij6cmZefm+1jw3oZU0L0w9lT7E= -github.com/cloudquery/cloudquery-api-go v1.4.4 h1:9VQoRxjWi9/rj1esfL3n6o6OwotoGtCNUAs3onnVwho= -github.com/cloudquery/cloudquery-api-go v1.4.4/go.mod h1:03fojQg0UpdgqXZ9tzZ5gF5CPad/F0sok66bsX6u4RA= +github.com/cloudquery/cloudquery-api-go v1.4.5 h1:nZyHuzodDSZJLjNi12raFpX1ErGACLBehBFN6LZ+d0k= +github.com/cloudquery/cloudquery-api-go v1.4.5/go.mod h1:03fojQg0UpdgqXZ9tzZ5gF5CPad/F0sok66bsX6u4RA= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/managedplugin/download.go b/managedplugin/download.go index 56b84cd..00b30c6 100644 --- a/managedplugin/download.go +++ b/managedplugin/download.go @@ -92,7 +92,7 @@ func getURLLocation(ctx context.Context, org string, name string, version string return "", fmt.Errorf("failed to find plugin %s/%s version %s", org, name, version) } -func DownloadPluginFromHub(ctx context.Context, authToken, localPath, team, name, version string, typ PluginType) error { +func DownloadPluginFromHub(ctx context.Context, authToken, teamName, localPath, pluginTeam, name, version string, typ PluginType) error { downloadDir := filepath.Dir(localPath) if _, err := os.Stat(localPath); err == nil { return nil @@ -102,39 +102,26 @@ func DownloadPluginFromHub(ctx context.Context, authToken, localPath, team, name return fmt.Errorf("failed to create plugin directory %s: %w", downloadDir, err) } - target := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH) - c, err := cloudquery_api.NewClientWithResponses(APIBaseURL(), - cloudquery_api.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error { - if authToken != "" { - req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", authToken)) - } - return nil - })) - if err != nil { - return fmt.Errorf("failed to create Hub API client: %w", err) - } - - aj := "application/json" - resp, err := c.DownloadPluginAssetWithResponse(ctx, team, cloudquery_api.PluginKind(typ.String()), name, version, target, &cloudquery_api.DownloadPluginAssetParams{Accept: &aj}) + pluginAsset, statusCode, err := downloadPluginAssetFromHub(ctx, authToken, teamName, pluginTeam, name, version, typ) if err != nil { return fmt.Errorf("failed to get plugin url: %w", err) } - switch resp.StatusCode() { + switch statusCode { case http.StatusOK: // we allow this status code case http.StatusUnauthorized: return fmt.Errorf("unauthorized. Try logging in via `cloudquery login`") case http.StatusNotFound: - return fmt.Errorf("failed to download plugin %v %v/%v@%v: plugin version not found. If you're trying to use a private plugin you'll need to run `cloudquery login` first", typ, team, name, version) + return fmt.Errorf("failed to download plugin %v %v/%v@%v: plugin version not found. If you're trying to use a private plugin you'll need to run `cloudquery login` first", typ, pluginTeam, name, version) case http.StatusTooManyRequests: return fmt.Errorf("too many download requests. Try logging in via `cloudquery login` to increase rate limits") default: - return fmt.Errorf("failed to download plugin %v %v/%v@%v: unexpected status code %v", typ, team, name, version, resp.StatusCode()) + return fmt.Errorf("failed to download plugin %v %v/%v@%v: unexpected status code %v", typ, pluginTeam, name, version, statusCode) } - if resp.JSON200 == nil { - return fmt.Errorf("failed to get plugin url for %v %v/%v@%v: missing json response", typ, team, name, version) + if pluginAsset == nil { + return fmt.Errorf("failed to get plugin url for %v %v/%v@%v: missing json response", typ, pluginTeam, name, version) } - location := resp.JSON200.Location + location := pluginAsset.Location if len(location) == 0 { return fmt.Errorf("failed to get plugin url: empty location from response") } @@ -144,10 +131,10 @@ func DownloadPluginFromHub(ctx context.Context, authToken, localPath, team, name return fmt.Errorf("failed to download plugin: %w", err) } - if resp.JSON200.Checksum == "" { + if pluginAsset.Checksum == "" { fmt.Printf("Warning - checksum not verified: %s\n", writtenChecksum) - } else if writtenChecksum != resp.JSON200.Checksum { - return fmt.Errorf("checksum mismatch: expected %s, got %s", resp.JSON200.Checksum, writtenChecksum) + } else if writtenChecksum != pluginAsset.Checksum { + return fmt.Errorf("checksum mismatch: expected %s, got %s", pluginAsset.Checksum, writtenChecksum) } archive, err := zip.OpenReader(pluginZipPath) @@ -176,6 +163,42 @@ func DownloadPluginFromHub(ctx context.Context, authToken, localPath, team, name return nil } +func downloadPluginAssetFromHub(ctx context.Context, authToken, teamName, pluginTeam, name, version string, typ PluginType) (*cloudquery_api.PluginAsset, int, error) { + var pluginAsset *cloudquery_api.PluginAsset + var statusCode int + + c, err := cloudquery_api.NewClientWithResponses(APIBaseURL(), + cloudquery_api.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error { + if authToken != "" { + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", authToken)) + } + return nil + })) + if err != nil { + return pluginAsset, statusCode, fmt.Errorf("failed to create Hub API client: %w", err) + } + + target := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH) + + aj := "application/json" + + if teamName != "" { + resp, err := c.DownloadPluginAssetByTeamWithResponse(ctx, teamName, pluginTeam, cloudquery_api.PluginKind(typ.String()), name, version, target, &cloudquery_api.DownloadPluginAssetByTeamParams{Accept: &aj}) + if err != nil { + return pluginAsset, statusCode, fmt.Errorf("failed to get plugin url: %w", err) + } + pluginAsset, statusCode = resp.JSON200, resp.StatusCode() + } else { + resp, err := c.DownloadPluginAssetWithResponse(ctx, pluginTeam, cloudquery_api.PluginKind(typ.String()), name, version, target, &cloudquery_api.DownloadPluginAssetParams{Accept: &aj}) + if err != nil { + return pluginAsset, statusCode, fmt.Errorf("failed to get plugin url: %w", err) + } + pluginAsset, statusCode = resp.JSON200, resp.StatusCode() + } + + return pluginAsset, statusCode, nil +} + func DownloadPluginFromGithub(ctx context.Context, localPath string, org string, name string, version string, typ PluginType) error { downloadDir := filepath.Dir(localPath) pluginZipPath := localPath + ".zip" diff --git a/managedplugin/download_test.go b/managedplugin/download_test.go index dd75667..83ad108 100644 --- a/managedplugin/download_test.go +++ b/managedplugin/download_test.go @@ -48,7 +48,7 @@ func TestDownloadPluginFromCloudQueryHub(t *testing.T) { } for _, tc := range cases { t.Run(tc.testName, func(t *testing.T) { - err := DownloadPluginFromHub(context.Background(), "", path.Join(tmp, tc.testName), tc.team, tc.plugin, tc.version, tc.typ) + err := DownloadPluginFromHub(context.Background(), "", "", path.Join(tmp, tc.testName), tc.team, tc.plugin, tc.version, tc.typ) if (err != nil) != tc.wantErr { t.Errorf("TestDownloadPluginFromCloudQueryIntegration() error = %v, wantErr %v", err, tc.wantErr) return diff --git a/managedplugin/options.go b/managedplugin/options.go index ceddb71..229361f 100644 --- a/managedplugin/options.go +++ b/managedplugin/options.go @@ -45,3 +45,9 @@ func WithAuthToken(authToken string) Option { c.authToken = authToken } } + +func WithTeamName(teamName string) Option { + return func(c *Client) { + c.teamName = teamName + } +} diff --git a/managedplugin/plugin.go b/managedplugin/plugin.go index a733088..9069512 100644 --- a/managedplugin/plugin.go +++ b/managedplugin/plugin.go @@ -91,6 +91,7 @@ type Client struct { metrics *Metrics registry Registry authToken string + teamName string } // typ will be deprecated soon but now required for a transition period @@ -182,7 +183,7 @@ func (c *Client) downloadPlugin(ctx context.Context, typ PluginType) error { org, name := pathSplit[0], pathSplit[1] c.LocalPath = filepath.Join(c.directory, "plugins", typ.String(), org, name, c.config.Version, "plugin") c.LocalPath = WithBinarySuffix(c.LocalPath) - return DownloadPluginFromHub(ctx, c.authToken, c.LocalPath, org, name, c.config.Version, typ) + return DownloadPluginFromHub(ctx, c.authToken, c.teamName, c.LocalPath, org, name, c.config.Version, typ) default: return fmt.Errorf("unknown registry %s", c.config.Registry.String()) } From 2eeea5e5eace640b7b993be6a0f4fabd44195796 Mon Sep 17 00:00:00 2001 From: Martin Norbury Date: Mon, 13 Nov 2023 17:47:22 +0000 Subject: [PATCH 2/4] Addressing comments --- managedplugin/download.go | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/managedplugin/download.go b/managedplugin/download.go index 00b30c6..b5c3636 100644 --- a/managedplugin/download.go +++ b/managedplugin/download.go @@ -164,9 +164,6 @@ func DownloadPluginFromHub(ctx context.Context, authToken, teamName, localPath, } func downloadPluginAssetFromHub(ctx context.Context, authToken, teamName, pluginTeam, name, version string, typ PluginType) (*cloudquery_api.PluginAsset, int, error) { - var pluginAsset *cloudquery_api.PluginAsset - var statusCode int - c, err := cloudquery_api.NewClientWithResponses(APIBaseURL(), cloudquery_api.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error { if authToken != "" { @@ -175,28 +172,26 @@ func downloadPluginAssetFromHub(ctx context.Context, authToken, teamName, plugin return nil })) if err != nil { - return pluginAsset, statusCode, fmt.Errorf("failed to create Hub API client: %w", err) + return nil, -1, fmt.Errorf("failed to create Hub API client: %w", err) } target := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH) - aj := "application/json" - if teamName != "" { - resp, err := c.DownloadPluginAssetByTeamWithResponse(ctx, teamName, pluginTeam, cloudquery_api.PluginKind(typ.String()), name, version, target, &cloudquery_api.DownloadPluginAssetByTeamParams{Accept: &aj}) + switch teamName { + case "": + resp, err := c.DownloadPluginAssetWithResponse(ctx, pluginTeam, cloudquery_api.PluginKind(typ.String()), name, version, target, &cloudquery_api.DownloadPluginAssetParams{Accept: &aj}) if err != nil { - return pluginAsset, statusCode, fmt.Errorf("failed to get plugin url: %w", err) + return nil, -1, fmt.Errorf("failed to get plugin url: %w", err) } - pluginAsset, statusCode = resp.JSON200, resp.StatusCode() - } else { - resp, err := c.DownloadPluginAssetWithResponse(ctx, pluginTeam, cloudquery_api.PluginKind(typ.String()), name, version, target, &cloudquery_api.DownloadPluginAssetParams{Accept: &aj}) + return resp.JSON200, resp.StatusCode(), nil + default: + resp, err := c.DownloadPluginAssetByTeamWithResponse(ctx, teamName, pluginTeam, cloudquery_api.PluginKind(typ.String()), name, version, target, &cloudquery_api.DownloadPluginAssetByTeamParams{Accept: &aj}) if err != nil { - return pluginAsset, statusCode, fmt.Errorf("failed to get plugin url: %w", err) + return nil, -1, fmt.Errorf("failed to get plugin url with team: %w", err) } - pluginAsset, statusCode = resp.JSON200, resp.StatusCode() + return resp.JSON200, resp.StatusCode(), nil } - - return pluginAsset, statusCode, nil } func DownloadPluginFromGithub(ctx context.Context, localPath string, org string, name string, version string, typ PluginType) error { From 9fad7ba55dfcbd9516ff98225dbe956a2e817b26 Mon Sep 17 00:00:00 2001 From: Martin Norbury Date: Mon, 13 Nov 2023 18:05:09 +0000 Subject: [PATCH 3/4] Further comment changes --- managedplugin/download.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/managedplugin/download.go b/managedplugin/download.go index b5c3636..399c9ca 100644 --- a/managedplugin/download.go +++ b/managedplugin/download.go @@ -178,17 +178,17 @@ func downloadPluginAssetFromHub(ctx context.Context, authToken, teamName, plugin target := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH) aj := "application/json" - switch teamName { - case "": - resp, err := c.DownloadPluginAssetWithResponse(ctx, pluginTeam, cloudquery_api.PluginKind(typ.String()), name, version, target, &cloudquery_api.DownloadPluginAssetParams{Accept: &aj}) + switch { + case teamName != "": + resp, err := c.DownloadPluginAssetByTeamWithResponse(ctx, teamName, pluginTeam, cloudquery_api.PluginKind(typ.String()), name, version, target, &cloudquery_api.DownloadPluginAssetByTeamParams{Accept: &aj}) if err != nil { - return nil, -1, fmt.Errorf("failed to get plugin url: %w", err) + return nil, -1, fmt.Errorf("failed to get plugin url with team: %w", err) } return resp.JSON200, resp.StatusCode(), nil default: - resp, err := c.DownloadPluginAssetByTeamWithResponse(ctx, teamName, pluginTeam, cloudquery_api.PluginKind(typ.String()), name, version, target, &cloudquery_api.DownloadPluginAssetByTeamParams{Accept: &aj}) + resp, err := c.DownloadPluginAssetWithResponse(ctx, pluginTeam, cloudquery_api.PluginKind(typ.String()), name, version, target, &cloudquery_api.DownloadPluginAssetParams{Accept: &aj}) if err != nil { - return nil, -1, fmt.Errorf("failed to get plugin url with team: %w", err) + return nil, -1, fmt.Errorf("failed to get plugin url: %w", err) } return resp.JSON200, resp.StatusCode(), nil } From 2bdb2218412f68e9432ab57d100b5b1506130739 Mon Sep 17 00:00:00 2001 From: Martin Norbury Date: Mon, 13 Nov 2023 22:04:27 +0000 Subject: [PATCH 4/4] Refactor to `HubDownloadOptions` --- managedplugin/download.go | 61 ++++++++++++++++++++++++---------- managedplugin/download_test.go | 10 +++++- managedplugin/plugin.go | 10 +++++- 3 files changed, 62 insertions(+), 19 deletions(-) diff --git a/managedplugin/download.go b/managedplugin/download.go index 399c9ca..0914e0b 100644 --- a/managedplugin/download.go +++ b/managedplugin/download.go @@ -92,9 +92,19 @@ func getURLLocation(ctx context.Context, org string, name string, version string return "", fmt.Errorf("failed to find plugin %s/%s version %s", org, name, version) } -func DownloadPluginFromHub(ctx context.Context, authToken, teamName, localPath, pluginTeam, name, version string, typ PluginType) error { - downloadDir := filepath.Dir(localPath) - if _, err := os.Stat(localPath); err == nil { +type HubDownloadOptions struct { + AuthToken string + TeamName string + LocalPath string + PluginTeam string + PluginKind string + PluginName string + PluginVersion string +} + +func DownloadPluginFromHub(ctx context.Context, ops HubDownloadOptions) error { + downloadDir := filepath.Dir(ops.LocalPath) + if _, err := os.Stat(ops.LocalPath); err == nil { return nil } @@ -102,7 +112,7 @@ func DownloadPluginFromHub(ctx context.Context, authToken, teamName, localPath, return fmt.Errorf("failed to create plugin directory %s: %w", downloadDir, err) } - pluginAsset, statusCode, err := downloadPluginAssetFromHub(ctx, authToken, teamName, pluginTeam, name, version, typ) + pluginAsset, statusCode, err := downloadPluginAssetFromHub(ctx, ops) if err != nil { return fmt.Errorf("failed to get plugin url: %w", err) } @@ -112,20 +122,20 @@ func DownloadPluginFromHub(ctx context.Context, authToken, teamName, localPath, case http.StatusUnauthorized: return fmt.Errorf("unauthorized. Try logging in via `cloudquery login`") case http.StatusNotFound: - return fmt.Errorf("failed to download plugin %v %v/%v@%v: plugin version not found. If you're trying to use a private plugin you'll need to run `cloudquery login` first", typ, pluginTeam, name, version) + return fmt.Errorf("failed to download plugin %v %v/%v@%v: plugin version not found. If you're trying to use a private plugin you'll need to run `cloudquery login` first", ops.PluginKind, ops.PluginTeam, ops.PluginName, ops.PluginVersion) case http.StatusTooManyRequests: return fmt.Errorf("too many download requests. Try logging in via `cloudquery login` to increase rate limits") default: - return fmt.Errorf("failed to download plugin %v %v/%v@%v: unexpected status code %v", typ, pluginTeam, name, version, statusCode) + return fmt.Errorf("failed to download plugin %v %v/%v@%v: unexpected status code %v", ops.PluginKind, ops.PluginTeam, ops.PluginName, ops.PluginVersion, statusCode) } if pluginAsset == nil { - return fmt.Errorf("failed to get plugin url for %v %v/%v@%v: missing json response", typ, pluginTeam, name, version) + return fmt.Errorf("failed to get plugin url for %v %v/%v@%v: missing json response", ops.PluginKind, ops.PluginTeam, ops.PluginName, ops.PluginVersion) } location := pluginAsset.Location if len(location) == 0 { return fmt.Errorf("failed to get plugin url: empty location from response") } - pluginZipPath := localPath + ".zip" + pluginZipPath := ops.LocalPath + ".zip" writtenChecksum, err := downloadFile(ctx, pluginZipPath, location) if err != nil { return fmt.Errorf("failed to download plugin: %w", err) @@ -143,14 +153,14 @@ func DownloadPluginFromHub(ctx context.Context, authToken, teamName, localPath, } defer archive.Close() - fileInArchive, err := archive.Open(fmt.Sprintf("plugin-%s-%s-%s-%s", name, version, runtime.GOOS, runtime.GOARCH)) + fileInArchive, err := archive.Open(fmt.Sprintf("plugin-%s-%s-%s-%s", ops.PluginName, ops.PluginVersion, runtime.GOOS, runtime.GOARCH)) if err != nil { return fmt.Errorf("failed to open plugin archive: %w", err) } - out, err := os.OpenFile(localPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0744) + out, err := os.OpenFile(ops.LocalPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0744) if err != nil { - return fmt.Errorf("failed to create file %s: %w", localPath, err) + return fmt.Errorf("failed to create file %s: %w", ops.LocalPath, err) } _, err = io.Copy(out, fileInArchive) if err != nil { @@ -163,11 +173,11 @@ func DownloadPluginFromHub(ctx context.Context, authToken, teamName, localPath, return nil } -func downloadPluginAssetFromHub(ctx context.Context, authToken, teamName, pluginTeam, name, version string, typ PluginType) (*cloudquery_api.PluginAsset, int, error) { +func downloadPluginAssetFromHub(ctx context.Context, ops HubDownloadOptions) (*cloudquery_api.PluginAsset, int, error) { c, err := cloudquery_api.NewClientWithResponses(APIBaseURL(), cloudquery_api.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error { - if authToken != "" { - req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", authToken)) + if ops.AuthToken != "" { + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", ops.AuthToken)) } return nil })) @@ -179,14 +189,31 @@ func downloadPluginAssetFromHub(ctx context.Context, authToken, teamName, plugin aj := "application/json" switch { - case teamName != "": - resp, err := c.DownloadPluginAssetByTeamWithResponse(ctx, teamName, pluginTeam, cloudquery_api.PluginKind(typ.String()), name, version, target, &cloudquery_api.DownloadPluginAssetByTeamParams{Accept: &aj}) + case ops.TeamName != "": + resp, err := c.DownloadPluginAssetByTeamWithResponse( + ctx, + ops.TeamName, + ops.PluginTeam, + cloudquery_api.PluginKind(ops.PluginKind), + ops.PluginName, + ops.PluginVersion, + target, + &cloudquery_api.DownloadPluginAssetByTeamParams{Accept: &aj}, + ) if err != nil { return nil, -1, fmt.Errorf("failed to get plugin url with team: %w", err) } return resp.JSON200, resp.StatusCode(), nil default: - resp, err := c.DownloadPluginAssetWithResponse(ctx, pluginTeam, cloudquery_api.PluginKind(typ.String()), name, version, target, &cloudquery_api.DownloadPluginAssetParams{Accept: &aj}) + resp, err := c.DownloadPluginAssetWithResponse( + ctx, + ops.PluginTeam, + cloudquery_api.PluginKind(ops.PluginKind), + ops.PluginName, + ops.PluginVersion, + target, + &cloudquery_api.DownloadPluginAssetParams{Accept: &aj}, + ) if err != nil { return nil, -1, fmt.Errorf("failed to get plugin url: %w", err) } diff --git a/managedplugin/download_test.go b/managedplugin/download_test.go index 83ad108..8a416d1 100644 --- a/managedplugin/download_test.go +++ b/managedplugin/download_test.go @@ -48,7 +48,15 @@ func TestDownloadPluginFromCloudQueryHub(t *testing.T) { } for _, tc := range cases { t.Run(tc.testName, func(t *testing.T) { - err := DownloadPluginFromHub(context.Background(), "", "", path.Join(tmp, tc.testName), tc.team, tc.plugin, tc.version, tc.typ) + err := DownloadPluginFromHub(context.Background(), HubDownloadOptions{ + LocalPath: path.Join(tmp, tc.testName), + AuthToken: "", + TeamName: "", + PluginTeam: tc.team, + PluginKind: tc.typ.String(), + PluginName: tc.plugin, + PluginVersion: tc.version, + }) if (err != nil) != tc.wantErr { t.Errorf("TestDownloadPluginFromCloudQueryIntegration() error = %v, wantErr %v", err, tc.wantErr) return diff --git a/managedplugin/plugin.go b/managedplugin/plugin.go index 9069512..a16f804 100644 --- a/managedplugin/plugin.go +++ b/managedplugin/plugin.go @@ -183,7 +183,15 @@ func (c *Client) downloadPlugin(ctx context.Context, typ PluginType) error { org, name := pathSplit[0], pathSplit[1] c.LocalPath = filepath.Join(c.directory, "plugins", typ.String(), org, name, c.config.Version, "plugin") c.LocalPath = WithBinarySuffix(c.LocalPath) - return DownloadPluginFromHub(ctx, c.authToken, c.teamName, c.LocalPath, org, name, c.config.Version, typ) + return DownloadPluginFromHub(ctx, HubDownloadOptions{ + AuthToken: c.authToken, + TeamName: c.teamName, + LocalPath: c.LocalPath, + PluginTeam: org, + PluginKind: typ.String(), + PluginName: name, + PluginVersion: c.config.Version, + }) default: return fmt.Errorf("unknown registry %s", c.config.Registry.String()) }