This SDK is designed to interact with Bitwarden services in Go. It includes implementations for managing projects and secrets, as well as a client interface to facilitate operations like login.
- Go installed
- C environment to run CGO
Follow the installation instructions here.
To initialize the client, you need to import the SDK and create a new BitwardenClient
instance.
import "github.com/bitwarden/sdk-go"
bitwardenClient, _ := sdk.NewBitwardenClient(&apiURL, &identityURL)
To login using an access token. Define some stateFile
and pass it to use state, or pass nil
instead to not use state.
stateFile := os.Getenv("STATE_FILE")
err := bitwardenClient.AccessTokenLogin(accessToken, &stateFile)
project, err := bitwardenClient.Projects().Create("organization_id", "project_name")
projects, err := bitwardenClient.Projects().List("organization_id")
project, err := bitwardenClient.Projects().Get("project_id")
project, err := bitwardenClient.Projects().Update("project_id", "organization_id", "new_project_name")
project, err := bitwardenClient.Projects().Delete([]string{"project_id_1", "project_id_2"})
secret, err := bitwardenClient.Secrets().Create("key", "value", "note", "organization_id", []string{"project_id"})
secrets, err := bitwardenClient.Secrets().List("organization_id")
secret, err := bitwardenClient.Secrets().Get("secret_id")
secrets, err := bitwardenClient.Secrets().GetByIDS([]string{"secret_ids"})
secret, err := bitwardenClient.Secrets().Update("secret_id", "new_key", "new_value", "new_note", "organization_id", []string{"project_id"})
secret, err := bitwardenClient.Secrets().Delete([]string{"secret_id_1", "secret_id_2"})
secretsSync, err := bitwardenClient.Secrets().Sync("organization_id", nil)
lastSyncedDate := time.Now()
secretsSync, err = bitwardenClient.Secrets().Sync("organization_id", lastSyncedDate)
To free up resources:
defer bitwardenClient.Close()
For more detailed information, refer to the code comments and method signatures.