Skip to content

Commit

Permalink
SM-1413: Temporary PR to reproduce hyper error
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonhurst committed Aug 13, 2024
1 parent 4be1e09 commit 7f1d71f
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 118 deletions.
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");

Check warning on line 27 in crates/bitwarden-sm/src/client_projects.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/client_projects.rs#L27

Added line #L27 was not covered by tests
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");

Check warning on line 36 in crates/bitwarden-sm/src/client_secrets.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/client_secrets.rs#L36

Added line #L36 was not covered by tests
list_secrets(self.client, input).await
}

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

Check warning on line 44 in crates/bitwarden-sm/src/client_secrets.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/client_secrets.rs#L44

Added line #L44 was not covered by tests
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;

Check warning on line 28 in crates/bitwarden-sm/src/projects/list.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/projects/list.rs#L28

Added line #L28 was not covered by tests

let r = match res {
Ok(r) => {
println!("{:?}", r);
r

Check warning on line 33 in crates/bitwarden-sm/src/projects/list.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/projects/list.rs#L30-L33

Added lines #L30 - L33 were not covered by tests
}
Err(e) => {
println!("{:?}", e);
return Err(e.into());

Check warning on line 37 in crates/bitwarden-sm/src/projects/list.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/projects/list.rs#L35-L37

Added lines #L35 - L37 were not covered by tests
}
};

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

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

Check warning on line 43 in crates/bitwarden-sm/src/projects/list.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/projects/list.rs#L43

Added line #L43 was not covered by tests
}

#[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;

Check warning on line 29 in crates/bitwarden-sm/src/secrets/list.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/secrets/list.rs#L29

Added line #L29 was not covered by tests

let r = match res {
Ok(r) => {
println!("{:?}", r);
r

Check warning on line 34 in crates/bitwarden-sm/src/secrets/list.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/secrets/list.rs#L31-L34

Added lines #L31 - L34 were not covered by tests
}
Err(e) => {
println!("{:?}", e);
return Err(e.into());

Check warning on line 38 in crates/bitwarden-sm/src/secrets/list.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/secrets/list.rs#L36-L38

Added lines #L36 - L38 were not covered by tests
}
};

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

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

Check warning on line 44 in crates/bitwarden-sm/src/secrets/list.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/secrets/list.rs#L44

Added line #L44 was not covered by tests
}

#[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;

Check warning on line 63 in crates/bitwarden-sm/src/secrets/list.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/secrets/list.rs#L63

Added line #L63 was not covered by tests

let r = match res {
Ok(r) => {
println!("{:?}", r);
r

Check warning on line 68 in crates/bitwarden-sm/src/secrets/list.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/secrets/list.rs#L65-L68

Added lines #L65 - L68 were not covered by tests
}
Err(e) => {
println!("{:?}", e);
return Err(e.into());

Check warning on line 72 in crates/bitwarden-sm/src/secrets/list.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/secrets/list.rs#L70-L72

Added lines #L70 - L72 were not covered by tests
}
};

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

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

Check warning on line 78 in crates/bitwarden-sm/src/secrets/list.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-sm/src/secrets/list.rs#L78

Added line #L78 was not covered by tests
}

#[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=

0 comments on commit 7f1d71f

Please sign in to comment.