Skip to content

Commit

Permalink
feat: Add tags to ssh_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ynhummel committed Mar 31, 2024
1 parent 649dcde commit 0bb175a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
45 changes: 45 additions & 0 deletions cli/get_project_ssh_keys_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func runOperationSSHKeysGetProjectSSHKeys(cmd *cobra.Command, args []string) err
if err, _ := retrieveOperationSSHKeysGetProjectSSHKeysProjectIDOrSlugFlag(params, "", cmd); err != nil {
return err
}
if err, _ := retrieveOperationSSHKeysFilterTagsFlag(params, "", cmd); err != nil {
return err
}
if dryRun {

logDebugf("dry-run flag specified. Skip sending request.")
Expand All @@ -61,6 +64,9 @@ func registerOperationSSHKeysGetProjectSSHKeysParamFlags(cmd *cobra.Command) err
if err := registerOperationSSHKeysGetProjectSSHKeysProjectIDOrSlugParamFlags("", cmd); err != nil {
return err
}
if err := registerOperationSSHKeysFilterTagsFlag("", cmd); err != nil {
return err
}
return nil
}

Expand All @@ -83,6 +89,24 @@ func registerOperationSSHKeysGetProjectSSHKeysProjectIDOrSlugParamFlags(cmdPrefi
return nil
}

func registerOperationSSHKeysFilterTagsFlag(cmdPrefix string, cmd *cobra.Command) error {

filterTagsDescription := `The Tags to filter by`

var filterTagsFlagName string
if cmdPrefix == "" {
filterTagsFlagName = "tags"
} else {
filterTagsFlagName = fmt.Sprintf("%v.tags", cmdPrefix)
}

var filterTagsFlagDefault = ""

_ = cmd.PersistentFlags().String(filterTagsFlagName, filterTagsFlagDefault, filterTagsDescription)

return nil
}

func retrieveOperationSSHKeysGetProjectSSHKeysProjectIDOrSlugFlag(m *ssh_keys.GetProjectSSHKeysParams, cmdPrefix string, cmd *cobra.Command) (error, bool) {
retAdded := false
if cmd.Flags().Changed("project") {
Expand All @@ -103,3 +127,24 @@ func retrieveOperationSSHKeysGetProjectSSHKeysProjectIDOrSlugFlag(m *ssh_keys.Ge
}
return nil, retAdded
}

func retrieveOperationSSHKeysFilterTagsFlag(m *ssh_keys.GetProjectSSHKeysParams, cmdPrefix string, cmd *cobra.Command) (error, bool) {
retAdded := false
if cmd.Flags().Changed("tags") {

var filterTagsFlagName string
if cmdPrefix == "" {
filterTagsFlagName = "tags"
} else {
filterTagsFlagName = fmt.Sprintf("%v.tags", cmdPrefix)
}

filterTagsFlagValue, err := cmd.Flags().GetString(filterTagsFlagName)
if err != nil {
return err, false
}
m.FilterTags = &filterTagsFlagValue

}
return nil, retAdded
}
6 changes: 6 additions & 0 deletions cli/put_project_ssh_key_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func (o *UpdateSSHKeyOperation) registerFlags(cmd *cobra.Command) {
Description: "Name of the SSH Key",
Required: true,
},
&cmdflag.StringSlice{
Name: "tags",
Label: "Tags",
Description: "Tags",
Required: false,
},
}

o.PathParamFlags.Register(pathParamsSchema)
Expand Down
27 changes: 27 additions & 0 deletions client/ssh_keys/get_project_ssh_keys_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions client/ssh_keys/put_project_ssh_key_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ type PutProjectSSHKeyParamsBodyDataAttributes struct {

// Name of the SSH Key
Name string `json:"name,omitempty"`

Tags []string `json:"tags,omitempty"`
}

// Validate validates this put project SSH key params body data attributes
Expand Down
6 changes: 5 additions & 1 deletion models/ssh_key_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ func (m *SSHKeyData) TableRow() table.Row {
Label: "ID",
Value: table.String(m.ID),
},
"tags": table.Cell{
Label: "Tags",
Value: table.StringList(tags(attr.Tags), ","),
},
"name": table.Cell{
Label: "Name",
Value: table.String(attr.Name),
Expand All @@ -193,7 +197,7 @@ func (m *SSHKeyData) TableRow() table.Row {
//
// swagger:model SSHKeyDataAttributes
type SSHKeyDataAttributes struct {

Tags []*TagsIncude `json:"tags,omitempty"`
// created at
CreatedAt string `json:"created_at,omitempty"`

Expand Down

0 comments on commit 0bb175a

Please sign in to comment.