From 7f1d71f85646295f0961acba19fe1df5ce757366 Mon Sep 17 00:00:00 2001 From: Colton Hurst Date: Tue, 13 Aug 2024 19:26:14 -0400 Subject: [PATCH] SM-1413: Temporary PR to reproduce hyper error --- Cargo.toml | 10 +- crates/bitwarden-sm/src/client_projects.rs | 1 + crates/bitwarden-sm/src/client_secrets.rs | 2 + crates/bitwarden-sm/src/projects/list.rs | 15 +- crates/bitwarden-sm/src/secrets/list.rs | 30 +++- languages/go/example/example.go | 157 ++++++++------------- languages/go/example/go.mod | 5 +- languages/go/example/go.sum | 2 - 8 files changed, 104 insertions(+), 118 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e721d9090..fab35e9ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/crates/bitwarden-sm/src/client_projects.rs b/crates/bitwarden-sm/src/client_projects.rs index 13b2c6967..1d17ad59c 100644 --- a/crates/bitwarden-sm/src/client_projects.rs +++ b/crates/bitwarden-sm/src/client_projects.rs @@ -24,6 +24,7 @@ impl<'a> ClientProjects<'a> { } pub async fn list(&self, input: &ProjectsListRequest) -> Result { + println!("list the projects"); list_projects(self.client, input).await } diff --git a/crates/bitwarden-sm/src/client_secrets.rs b/crates/bitwarden-sm/src/client_secrets.rs index 2b1085a0a..b8db7c068 100644 --- a/crates/bitwarden-sm/src/client_secrets.rs +++ b/crates/bitwarden-sm/src/client_secrets.rs @@ -33,6 +33,7 @@ impl<'a> ClientSecrets<'a> { &self, input: &SecretIdentifiersRequest, ) -> Result { + println!("list the secrets"); list_secrets(self.client, input).await } @@ -40,6 +41,7 @@ impl<'a> ClientSecrets<'a> { &self, input: &SecretIdentifiersByProjectRequest, ) -> Result { + println!("list the secrets by project"); list_secrets_by_project(self.client, input).await } diff --git a/crates/bitwarden-sm/src/projects/list.rs b/crates/bitwarden-sm/src/projects/list.rs index 334e06007..7ae837b37 100644 --- a/crates/bitwarden-sm/src/projects/list.rs +++ b/crates/bitwarden-sm/src/projects/list.rs @@ -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)] diff --git a/crates/bitwarden-sm/src/secrets/list.rs b/crates/bitwarden-sm/src/secrets/list.rs index 60a5c9727..3b3584c7b 100644 --- a/crates/bitwarden-sm/src/secrets/list.rs +++ b/crates/bitwarden-sm/src/secrets/list.rs @@ -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)] @@ -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)] diff --git a/languages/go/example/example.go b/languages/go/example/example.go index b97645db6..fc59746d2 100644 --- a/languages/go/example/example.go +++ b/languages/go/example/example.go @@ -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() } diff --git a/languages/go/example/go.mod b/languages/go/example/go.mod index cb09b706c..784fb84d9 100644 --- a/languages/go/example/go.mod +++ b/languages/go/example/go.mod @@ -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 diff --git a/languages/go/example/go.sum b/languages/go/example/go.sum index c0ad68738..e69de29bb 100644 --- a/languages/go/example/go.sum +++ b/languages/go/example/go.sum @@ -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=