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

feat: Allow plugins to be downloaded using a user team_name context #162

Merged
merged 4 commits into from
Nov 14, 2023

Conversation

mnorbury
Copy link
Contributor

@mnorbury mnorbury commented Nov 13, 2023

Adding the ability to pass the team_name to the download. This will be passed in by the CLI as either the team_name in the user's saved configuration (i.e. cloudquery switch config) or the team_name associated with the API key being used.

Ref: https://github.com/cloudquery/cloudquery-issues/issues/835

@github-actions github-actions bot added feat and removed feat labels Nov 13, 2023
managedplugin/download.go Outdated Show resolved Hide resolved
managedplugin/download.go Outdated Show resolved Hide resolved
@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's time to use a struct here so it's not so easy to get the order of all the string parameters wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love that but how far to take it? This pattern is everywhere and technically the methods are public.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically public yes, but we're already breaking the signature with this change by adding a parameter, right? May as well make it a struct

Maybe something like func DownloadPluginFromHub(ctx context.Context, opts HubDownloadOptions) with

type HubDownloadOptions struct {
    AuthToken string
    TeamName string
    LocalPath string
    PluginTeam string
    PluginKind string
    PluginName string
    PluginVersion string
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion - added in 2bdb221

managedplugin/download.go Outdated Show resolved Hide resolved
aj := "application/json"

switch {
case ops.TeamName != "":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Personally I would have used if/else here (or even just if with return), as it's a switch with a single case :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree but leaned towards reviewer has final say

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to prefer a switch given it is a single case + default @disq ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subjectively it looks more symmetrical and clearer than an if block or an if else statement if it's the last thing a fn does.

@mnorbury mnorbury added the automerge Add to automerge PRs once requirements are met label Nov 14, 2023
@kodiakhq kodiakhq bot merged commit 5e33845 into main Nov 14, 2023
6 checks passed
@kodiakhq kodiakhq bot deleted the fix/download-by-team branch November 14, 2023 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Add to automerge PRs once requirements are met feat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants