Skip to content

Commit

Permalink
Add keypairs list opts (#172)
Browse files Browse the repository at this point in the history
Added the ability to pass user_id as a filter to speed up the key list query.

Also fix GitHub Actions:
 - enable for PR from fork
 - add .semgrepignore for tests
 - remove wrong --severity flag for semgrep
  • Loading branch information
saydamir authored Nov 15, 2024
1 parent 7b58634 commit c100b32
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/secure.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Secure

on: push
on:
push:
branches:
- master
pull_request:

jobs:
# Sample GitHub Actions:
Expand All @@ -17,7 +21,7 @@ jobs:
security-events: write
steps:
- uses: actions/checkout@v4
- run: semgrep scan --sarif --output=semgrep.sarif --error --severity=WARNING
- run: semgrep scan --sarif --output=semgrep.sarif --error
env:
SEMGREP_RULES: >-
p/command-injection
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Verify

on: push
on:
push:
branches:
- master
pull_request:

jobs:
tests:
Expand Down
4 changes: 4 additions & 0 deletions .semgrepignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*/testing/*_test.go
*/testing/fixtures.go
README.md
selvpcclient/doc.go
16 changes: 16 additions & 0 deletions selvpcclient/resell/v2/keypairs/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"net/http"
"strings"

"github.com/google/go-querystring/query"

"github.com/selectel/go-selvpcclient/v3/selvpcclient"
clientservices "github.com/selectel/go-selvpcclient/v3/selvpcclient/clients/services"
)
Expand All @@ -13,12 +15,26 @@ const resourceURL = "keypairs"

// List gets a list of keypairs in the current domain.
func List(client *selvpcclient.Client) ([]*Keypair, *clientservices.ResponseResult, error) {
return ListWithOpts(client, ListOpts{})
}

// ListWithOpts gets a list of keypairs with filter options.
func ListWithOpts(client *selvpcclient.Client, opts ListOpts) ([]*Keypair, *clientservices.ResponseResult, error) {
endpoint, err := client.Resell.GetEndpoint()
if err != nil {
return nil, nil, fmt.Errorf("failed to get endpoint, err: %w", err)
}

url := strings.Join([]string{endpoint, resourceURL}, "/")
if opts.UserID != "" {
queryParams, err := query.Values(opts)
if err != nil {
return nil, nil, err
}

url = strings.Join([]string{url, queryParams.Encode()}, "?")
}

responseResult, err := client.Resell.Requests.Do(http.MethodGet, url, &clientservices.RequestOptions{
OkCodes: []int{200},
})
Expand Down
7 changes: 7 additions & 0 deletions selvpcclient/resell/v2/keypairs/requests_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ type KeypairOpts struct {
// this keypair.
UserID string `json:"user_id"`
}

// ListOpts represents options for the keypair ListWithFilter request.
type ListOpts struct {
// UserID contains an ID of an OpenStack Identity service user that owns
// this keypair.
UserID string `url:"user_id"`
}

0 comments on commit c100b32

Please sign in to comment.