- Notifications
You must be signed in to change notification settings - Fork 30
feat(cdn): add cdn client, config, list command #1100
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
Open
cgoetz-inovex wants to merge 56 commits into main Choose a base branch from feat/STACKITCLI-70-add-cdn-distribution-beta-cmds
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
56 commits Select commit Hold shift + click to select a range
863828c feat(cdn): add cdn client, config, list command
cgoetz-inovex f198a95 fix(cdn): generate docs
cgoetz-inovex d5f4304 fix(cdn) fix linting issues
cgoetz-inovex 8c71293 Update internal/cmd/beta/cdn/distribution/list/list.go
cgoetz-inovex 82f7d49 Update internal/cmd/beta/cdn/distribution/list/list.go
cgoetz-inovex a87cd60 fix(cdn): rename sortBy params, use EnumSliceToStringSlice
cgoetz-inovex 42d1196 fix(cdn): make `testNextPageID`, `testID` and `testStatus` constant
cgoetz-inovex 0d7729a fix(cdn): add cdn subcommand to beta, generate docs
cgoetz-inovex c3095c5 Merge branch 'main' into feat/STACKITCLI-70-add-cdn-distribution-beta…
cgoetz-inovex 7e50687 feat(cdn) add limit flag to distribution list
cgoetz-inovex 9e049a0 feat(cdn): add distribution create cmd
cgoetz-inovex cbf7a9f fix(cdn): generate distribution create docs
cgoetz-inovex 7296ee0 squash this
cgoetz-inovex 1235792 feat(cdn) implement cdn distribution create/delete/describe/update
cgoetz-inovex 568659c squash
cgoetz-inovex a183846 squash
cgoetz-inovex 4f4e0b1 fix(cdn) regenerate docs
cgoetz-inovex dbfea3d fix(cdn) linting issues
cgoetz-inovex 9d512ea chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/sec…
dependabot[bot] cd065fd chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/ser…
dependabot[bot] c5d46b4 chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/ske…
dependabot[bot] 50ebc7c chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/ser…
dependabot[bot] 13cb16c chore(deps): bump renovatebot/github-action from 44.0.3 to 44.0.4 (#1…
dependabot[bot] b950c06 feat(kms) describe key, keyring, wrappingkey (#1107)
cgoetz-inovex 0b693ec chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/rab…
dependabot[bot] d29f75a chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/alb…
dependabot[bot] e95f987 chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/mon…
dependabot[bot] be30de5 chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/ser…
dependabot[bot] f6a0b1a chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/ser…
dependabot[bot] 8faa48d chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/dns…
dependabot[bot] 8cda53b chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/iaa…
dependabot[bot] 4ae1761 fix(alb): print valid JSON/YAML output for list cmds (#1045)
rubenhoenle 0edc3c7 chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/mar…
dependabot[bot] f0a12ee chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/red…
dependabot[bot] 1580200 chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/run…
dependabot[bot] 3cc971e chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/aut…
dependabot[bot] 784d53a chore: increase linter timeout (#1131)
marceljk 97cde20 chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/int…
dependabot[bot] 9ccaaf8 chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/loa…
dependabot[bot] e93e347 fix: log browser url to stderr instead of stdout (#1136)
marceljk 589ce8f fix(deps): update module github.com/goccy/go-yaml to v1.19.0 (#1137)
stackit-pipeline 0908904 feat(mongodbflex): add readAnyDatabase and stackitAdmin roles for use…
PietvanderMeulen 2b014bc fix: refresh token flow uses x-www-form encoding (#1135)
JorTurFer fb6d721 chore(deps): update renovatebot/github-action action to v44.0.5 (#1141)
stackit-pipeline a228bda chore(deps): bump github.com/stackitcloud/stackit-sdk-go/services/sql…
dependabot[bot] 883acc3 feat(cdn): add cdn client, config, list command
cgoetz-inovex 5241898 feat(cdn) implement cdn distribution create/delete/describe/update
cgoetz-inovex 180fa38 Merge branch 'main' into feat/STACKITCLI-70-add-cdn-distribution-beta…
cgoetz-inovex 90f05e9 fix(cdn) manual merge fixes
cgoetz-inovex 76d91fb fix(cdn) review fixes
cgoetz-inovex 3d0f111 fix(cdn) replace utils.Min usage with builtin min
cgoetz-inovex d6160f1 Update internal/cmd/beta/cdn/distribution/list/list.go
cgoetz-inovex b2a1c41 fix(cdn) apply review comments
cgoetz-inovex fe7496c Merge branch 'main' into feat/STACKITCLI-70-add-cdn-distribution-beta…
cgoetz-inovex 2f93697 fix(cdn) fix merge errors
cgoetz-inovex bb81dac fix(cdn) more merge errors, and single char renames
cgoetz-inovex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package cdn | ||
| | ||
| import ( | ||
| "github.com/spf13/cobra" | ||
| "github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/distribution" | ||
| "github.com/stackitcloud/stackit-cli/internal/cmd/params" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/args" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/utils" | ||
| ) | ||
| | ||
| func NewCmd(params *params.CmdParams) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "cdn", | ||
| Short: "Manage CDN resources", | ||
| Long: "Manage the lifecycle of CDN resources.", | ||
| Args: args.NoArgs, | ||
| Run: utils.CmdHelp, | ||
| } | ||
| addSubcommands(cmd, params) | ||
| return cmd | ||
| } | ||
| | ||
| func addSubcommands(cmd *cobra.Command, params *params.CmdParams) { | ||
| cmd.AddCommand(distribution.NewCommand(params)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package distribution | ||
| | ||
| import ( | ||
| "github.com/spf13/cobra" | ||
| "github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/distribution/list" | ||
| "github.com/stackitcloud/stackit-cli/internal/cmd/params" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/utils" | ||
| ) | ||
| | ||
| func NewCommand(params *params.CmdParams) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "distribution", | ||
| Short: "Manage CDN distributions", | ||
| Long: "Manage the lifecycle of CDN distributions.", | ||
| Args: cobra.NoArgs, | ||
| Run: utils.CmdHelp, | ||
| } | ||
| addSubcommands(cmd, params) | ||
| return cmd | ||
| } | ||
| | ||
| func addSubcommands(cmd *cobra.Command, params *params.CmdParams) { | ||
| cmd.AddCommand(list.NewCmd(params)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| package list | ||
| | ||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
| | ||
| "github.com/spf13/cobra" | ||
| "github.com/stackitcloud/stackit-cli/internal/cmd/params" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/args" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/errors" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/examples" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/flags" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/print" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/services/cdn/client" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/tables" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/utils" | ||
| "github.com/stackitcloud/stackit-sdk-go/services/cdn" | ||
| ) | ||
| | ||
| type inputModel struct { | ||
| *globalflags.GlobalFlagModel | ||
| SortBy string | ||
| } | ||
| | ||
| const ( | ||
| sortByFlag = "sort-by" | ||
| ) | ||
| | ||
| func NewCmd(params *params.CmdParams) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List CDN distributions", | ||
| Long: "List all CDN distributions in your account.", | ||
| Args: args.NoArgs, | ||
| Example: examples.Build( | ||
| examples.NewExample( | ||
| `List all CDN distributions`, | ||
| `$ stackit beta dns distribution list`, | ||
| ), | ||
| examples.NewExample( | ||
| `List all CDN distributions sorted by id`, | ||
| `$ stackit beta dns distribution list --sort-by=id`, | ||
cgoetz-inovex marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| ), | ||
| ), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := context.Background() // should this be cancellable? | ||
cgoetz-inovex marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| | ||
| model, err := parseInput(params.Printer, cmd, args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| | ||
| apiClient, err := client.ConfigureClient(params.Printer, params.CliVersion) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| | ||
| distributions, err := fetchDistributions(ctx, model, apiClient) | ||
| if err != nil { | ||
| return fmt.Errorf("fetch distributions: %w", err) | ||
| } | ||
| | ||
| return outputResult(params.Printer, model.OutputFormat, distributions) | ||
| }, | ||
| } | ||
| | ||
| configureFlags(cmd) | ||
| return cmd | ||
| } | ||
| | ||
| var sortByFlagOptions = []string{"id", "created", "updated", "origin-url", "status"} | ||
cgoetz-inovex marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| | ||
| func configureFlags(cmd *cobra.Command) { | ||
| // same default as apiClient | ||
| cmd.Flags().Var(flags.EnumFlag(false, "created", sortByFlagOptions...), sortByFlag, fmt.Sprintf("Sort entries by a specific field, one of %q", sortByFlagOptions)) | ||
| } | ||
| | ||
| func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) { | ||
| globalFlags := globalflags.Parse(p, cmd) | ||
| if globalFlags.ProjectId == "" { | ||
| return nil, &errors.ProjectIdError{} | ||
| } | ||
| | ||
| model := inputModel{ | ||
| GlobalFlagModel: globalFlags, | ||
| SortBy: flags.FlagWithDefaultToStringValue(p, cmd, sortByFlag), | ||
| } | ||
| | ||
| p.DebugInputModel(model) | ||
| return &model, nil | ||
| } | ||
| | ||
| func buildRequest(ctx context.Context, model *inputModel, apiClient *cdn.APIClient, nextPageID cdn.ListDistributionsResponseGetNextPageIdentifierAttributeType) cdn.ApiListDistributionsRequest { | ||
| req := apiClient.ListDistributions(ctx, model.GlobalFlagModel.ProjectId) | ||
| req = req.SortBy(toAPISortBy(model.SortBy)) | ||
| req = req.PageSize(100) | ||
| if nextPageID != nil { | ||
| req = req.PageIdentifier(*nextPageID) | ||
| } | ||
| return req | ||
| } | ||
| | ||
| func toAPISortBy(sortBy string) string { | ||
| switch sortBy { | ||
| case "id": | ||
| return "id" | ||
| case "created": | ||
| return "createdAt" | ||
| case "updated": | ||
| return "updatedAt" | ||
| case "origin-url": | ||
| return "originUrl" | ||
| case "status": | ||
| return "status" | ||
| default: | ||
| panic("invalid sortBy value, programmer error") | ||
| } | ||
| } | ||
| | ||
| func outputResult(p *print.Printer, outputFormat string, distributions []cdn.Distribution) error { | ||
| if distributions == nil { | ||
| distributions = make([]cdn.Distribution, 0) // otherwise prints null in json output | ||
rubenhoenle marked this conversation as resolved. Show resolved Hide resolved | ||
| } | ||
| return p.OutputResult(outputFormat, distributions, func() error { | ||
| if len(distributions) == 0 { | ||
| p.Outputln("No CDN distributions found") | ||
| return nil | ||
| } | ||
| | ||
| table := tables.NewTable() | ||
| table.SetHeader("ID", "REGIONS", "STATUS") | ||
cgoetz-inovex marked this conversation as resolved. Show resolved Hide resolved | ||
| for i := range distributions { | ||
cgoetz-inovex marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| d := &distributions[i] | ||
| regions := make([]string, 0, len(*d.Config.Regions)) | ||
| for _, r := range *d.Config.Regions { | ||
| regions = append(regions, string(r)) | ||
| } | ||
| joinedRegions := strings.Join(regions, ", ") | ||
| table.AddRow( | ||
| utils.PtrString(d.Id), | ||
| joinedRegions, | ||
cgoetz-inovex marked this conversation as resolved. Show resolved Hide resolved | ||
| utils.PtrString(d.Status), | ||
| ) | ||
| } | ||
| err := table.Display(p) | ||
| if err != nil { | ||
| return fmt.Errorf("render table: %w", err) | ||
| } | ||
| return nil | ||
| }) | ||
| } | ||
| | ||
| func fetchDistributions(ctx context.Context, model *inputModel, apiClient *cdn.APIClient) ([]cdn.Distribution, error) { | ||
| var nextPageID cdn.ListDistributionsResponseGetNextPageIdentifierAttributeType | ||
| var distributions []cdn.Distribution | ||
| for { | ||
| request := buildRequest(ctx, model, apiClient, nextPageID) | ||
| response, err := request.Execute() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("list distributions: %w", err) | ||
| } | ||
| nextPageID = response.NextPageIdentifier | ||
| if response.Distributions != nil { | ||
| distributions = append(distributions, *response.Distributions...) | ||
| } | ||
| if nextPageID == nil { | ||
| break | ||
| } | ||
| } | ||
| return distributions, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.