From eb39b6ee7edd81009fdccfc0c62ac01e397e9be4 Mon Sep 17 00:00:00 2001 From: tangowithfoxtrot <5676771+tangowithfoxtrot@users.noreply.github.com> Date: Tue, 20 Feb 2024 09:45:01 -0800 Subject: [PATCH 1/2] add get-by-ids to Go wrapper --- languages/go/example/example.go | 23 ++++++++++++++++++++++- languages/go/secrets.go | 17 +++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/languages/go/example/example.go b/languages/go/example/example.go index deb353565..249fa748b 100644 --- a/languages/go/example/example.go +++ b/languages/go/example/example.go @@ -1,7 +1,9 @@ package main import ( + "encoding/json" "fmt" + "log" "os" sdk "github.com/bitwarden/sdk/languages/go" @@ -83,9 +85,28 @@ func main() { panic(err) } - if _, err = bitwardenClient.Projects.Delete([]string{projectID}); err != nil { + 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() } diff --git a/languages/go/secrets.go b/languages/go/secrets.go index e6863c459..2c56538f7 100644 --- a/languages/go/secrets.go +++ b/languages/go/secrets.go @@ -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) } @@ -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{ From e96bb3d018b50cb94aaea75a7a1dd2d1f2ef2f3e Mon Sep 17 00:00:00 2001 From: tangowithfoxtrot <5676771+tangowithfoxtrot@users.noreply.github.com> Date: Tue, 20 Feb 2024 19:14:26 -0800 Subject: [PATCH 2/2] restore deleted line --- languages/go/example/example.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/languages/go/example/example.go b/languages/go/example/example.go index 249fa748b..eb4d34612 100644 --- a/languages/go/example/example.go +++ b/languages/go/example/example.go @@ -85,6 +85,10 @@ func main() { panic(err) } + if _, err = bitwardenClient.Projects.Delete([]string{projectID}); err != nil { + panic(err) + } + secretIdentifiers, err := bitwardenClient.Secrets.List(organizationID.String()) if err != nil { panic(err)