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

add get-by-ids to Go wrapper #620

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions languages/go/example/example.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"encoding/json"
"fmt"
"log"
"os"

sdk "github.com/bitwarden/sdk/languages/go"
Expand Down Expand Up @@ -87,5 +89,28 @@ func main() {
panic(err)
}

secretIdentifiers, err := bitwardenClient.Secrets.List(organizationID.String())
if err != nil {
panic(err)
}

// Get secrets with a list of IDs
secretIDs := make([]string, len(secretIdentifiers.Data))
for i, identifier := range secretIdentifiers.Data {
secretIDs[i] = identifier.ID
}

secrets, err := bitwardenClient.Secrets.GetByIDS(secretIDs)
if err != nil {
log.Fatalf("Error getting secrets: %v", err)
}

jsonSecrets, err := json.MarshalIndent(secrets, "", " ")
if err != nil {
log.Fatalf("Error marshalling secrets to JSON: %v", err)
}

fmt.Println(string(jsonSecrets))

defer bitwardenClient.Close()
}
17 changes: 17 additions & 0 deletions languages/go/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type SecretsInterface interface {
Create(key, value, note string, organizationID string, projectIDs []string) (*SecretResponse, error)
List(organizationID string) (*SecretIdentifiersResponse, error)
Get(secretID string) (*SecretResponse, error)
GetByIDS(secretIDs []string) (*SecretsResponse, error)
Update(secretID string, key, value, note string, organizationID string, projectIDs []string) (*SecretResponse, error)
Delete(secretIDs []string) (*SecretsDeleteResponse, error)
}
Expand Down Expand Up @@ -76,6 +77,22 @@ func (s *Secrets) Get(id string) (*SecretResponse, error) {
return &response, nil
}

func (s *Secrets) GetByIDS(ids []string) (*SecretsResponse, error) {
command := Command{
Secrets: &SecretsCommand{
GetByIDS: &SecretsGetRequest{
IDS: ids,
},
},
}

var response SecretsResponse
if err := s.executeCommand(command, &response); err != nil {
return nil, err
}
return &response, nil
}

func (s *Secrets) Update(id string, key, value, note string, organizationID string, projectIDs []string) (*SecretResponse, error) {
command := Command{
Secrets: &SecretsCommand{
Expand Down
Loading