Skip to content
Closed
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
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ unwrap_used = "deny"
# This slows down clean builds by about 50%, but the resulting binaries can be orders of magnitude faster
# As clean builds won't occur very often, this won't slow down the development process
[profile.dev.package."*"]
opt-level = 2
opt-level = 0

# Turn on a small amount of optimisation in development mode. This might interfere when trying to use a debugger
# if the compiler decides to optimize some code away, if that's the case, it can be set to 0 or commented out
[profile.dev]
opt-level = 1
opt-level = 0

# Turn on LTO on release mode
[profile.release]
lto = "thin"
codegen-units = 1
# [profile.release]
# lto = "thin"
# codegen-units = 1
# Stripping the binary reduces the size by ~30%, but the stacktraces won't be usable anymore.
# This is fine as long as we don't have any unhandled panics, but let's keep it disabled for now
# strip = true
1 change: 1 addition & 0 deletions crates/bitwarden-sm/src/client_projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl<'a> ClientProjects<'a> {
}

pub async fn list(&self, input: &ProjectsListRequest) -> Result<ProjectsResponse, Error> {
println!("list the projects");
list_projects(self.client, input).await
}

Expand Down
2 changes: 2 additions & 0 deletions crates/bitwarden-sm/src/client_secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ impl<'a> ClientSecrets<'a> {
&self,
input: &SecretIdentifiersRequest,
) -> Result<SecretIdentifiersResponse, Error> {
println!("list the secrets");
list_secrets(self.client, input).await
}

pub async fn list_by_project(
&self,
input: &SecretIdentifiersByProjectRequest,
) -> Result<SecretIdentifiersResponse, Error> {
println!("list the secrets by project");
list_secrets_by_project(self.client, input).await
}

Expand Down
15 changes: 13 additions & 2 deletions crates/bitwarden-sm/src/projects/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,22 @@ pub(crate) async fn list_projects(
&config.api,
input.organization_id,
)
.await?;
.await;

let r = match res {
Ok(r) => {
println!("{:?}", r);
r
}
Err(e) => {
println!("{:?}", e);
return Err(e.into());
}
};

let enc = client.internal.get_encryption_settings()?;

ProjectsResponse::process_response(res, &enc)
ProjectsResponse::process_response(r, &enc)
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
Expand Down
30 changes: 26 additions & 4 deletions crates/bitwarden-sm/src/secrets/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,22 @@ pub(crate) async fn list_secrets(
&config.api,
input.organization_id,
)
.await?;
.await;

let r = match res {
Ok(r) => {
println!("{:?}", r);
r
}
Err(e) => {
println!("{:?}", e);
return Err(e.into());
}
};

let enc = client.internal.get_encryption_settings()?;

SecretIdentifiersResponse::process_response(res, &enc)
SecretIdentifiersResponse::process_response(r, &enc)
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
Expand All @@ -49,11 +60,22 @@ pub(crate) async fn list_secrets_by_project(
&config.api,
input.project_id,
)
.await?;
.await;

let r = match res {
Ok(r) => {
println!("{:?}", r);
r
}
Err(e) => {
println!("{:?}", e);
return Err(e.into());
}
};

let enc = client.internal.get_encryption_settings()?;

SecretIdentifiersResponse::process_response(res, &enc)
SecretIdentifiersResponse::process_response(r, &enc)
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
Expand Down
157 changes: 56 additions & 101 deletions languages/go/example/example.go
Original file line number Diff line number Diff line change
@@ -1,116 +1,71 @@
package main

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

sdk "github.com/bitwarden/sdk-go"
"github.com/gofrs/uuid"
)

func main() {
// Configuring the URLS is optional, set them to nil to use the default values
apiURL := os.Getenv("API_URL")
identityURL := os.Getenv("IDENTITY_URL")

bitwardenClient, _ := sdk.NewBitwardenClient(&apiURL, &identityURL)

accessToken := os.Getenv("ACCESS_TOKEN")
organizationIDStr := os.Getenv("ORGANIZATION_ID")
projectName := os.Getenv("PROJECT_NAME")

// Configuring the stateFile is optional, pass nil
// in AccessTokenLogin() to not use state
stateFile := os.Getenv("STATE_FILE")

if projectName == "" {
projectName = "NewTestProject" // default value
}

err := bitwardenClient.AccessTokenLogin(accessToken, &stateFile)
if err != nil {
panic(err)
}

organizationID, err := uuid.FromString(organizationIDStr)
if err != nil {
panic(err)
}

project, err := bitwardenClient.Projects().Create(organizationID.String(), projectName)
if err != nil {
panic(err)
}
fmt.Println(project)
projectID := project.ID
fmt.Println(projectID)

if _, err = bitwardenClient.Projects().List(organizationID.String()); err != nil {
panic(err)
}

if _, err = bitwardenClient.Projects().Get(projectID); err != nil {
panic(err)
}

if _, err = bitwardenClient.Projects().Update(projectID, organizationID.String(), projectName+"2"); err != nil {
panic(err)
}

key := "key"
value := "value"
note := "note"

secret, err := bitwardenClient.Secrets().Create(key, value, note, organizationID.String(), []string{projectID})
if err != nil {
panic(err)
}
secretID := secret.ID

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

if _, err = bitwardenClient.Secrets().Get(secretID); err != nil {
panic(err)
}

if _, err = bitwardenClient.Secrets().Update(secretID, key, value, note, organizationID.String(), []string{projectID}); err != nil {
panic(err)
}

if _, err = bitwardenClient.Secrets().Delete([]string{secretID}); err != nil {
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)
}

// Get secrets with a list of IDs
secretIDs := make([]string, len(secretIdentifiers.Data))
for i, identifier := range secretIdentifiers.Data {
secretIDs[i] = identifier.ID
}
var (
ApiUrl = "http://localhost:4000"
IdentityUrl = "http://localhost:33656"
OrganizationId = ""
AccessToken = ""
statePath = ""
)

secrets, err := bitwardenClient.Secrets().GetByIDS(secretIDs)
func main() {
// create the client
bitwardenClient, err := sdk.NewBitwardenClient(&ApiUrl, &IdentityUrl)
if err != nil {
log.Fatalf("Error getting secrets: %v", err)
log.Fatal(err)
}

jsonSecrets, err := json.MarshalIndent(secrets, "", " ")
// access token login
err = bitwardenClient.AccessTokenLogin(AccessToken, &statePath)
if err != nil {
log.Fatalf("Error marshalling secrets to JSON: %v", err)
}

fmt.Println(string(jsonSecrets))

defer bitwardenClient.Close()
log.Fatal(err)
}

// build the waitgroup
var wg sync.WaitGroup
wg.Add(2)

// build the goroutines
go func() {
defer wg.Done()
for i := 0; i < 100; i++ {
projects, err := bitwardenClient.Projects().List(OrganizationId)
if err != nil {
log.Println("Error listing projects:", err)
return
}

fmt.Printf("# of Projects (iteration %d): %d\n", i+1, len(projects.Data))
for _, project := range projects.Data {
fmt.Printf("ID: %s\n", project.ID)
fmt.Printf("Name: %s\n", project.Name)
}
}
}()
go func() {
defer wg.Done()
for i := 0; i < 100; i++ {
secrets, err := bitwardenClient.Secrets().List(OrganizationId)
if err != nil {
log.Println("Error listing secrets:", err)
return
}

fmt.Printf("# of Secrets (iteration %d): %d\n", i+1, len(secrets.Data))
for _, secret := range secrets.Data {
fmt.Printf("ID: %s\n", secret.ID)
fmt.Printf("Name: %s\n", secret.Key)
}
}
}()

wg.Wait()
}
5 changes: 1 addition & 4 deletions languages/go/example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ replace github.com/bitwarden/sdk-go => ../

go 1.21

require (
github.com/bitwarden/sdk-go v0.0.0-00010101000000-000000000000
github.com/gofrs/uuid v4.4.0+incompatible
)
require github.com/bitwarden/sdk-go v0.0.0-00010101000000-000000000000
2 changes: 0 additions & 2 deletions languages/go/example/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=