Skip to content

Commit

Permalink
add get-by-ids to Go wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
tangowithfoxtrot committed Feb 20, 2024
1 parent d5c04a9 commit eb39b6e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
23 changes: 22 additions & 1 deletion 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 @@ -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()
}
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

0 comments on commit eb39b6e

Please sign in to comment.