-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SM-1413: Temporary PR to reproduce hyper error
- Loading branch information
1 parent
4be1e09
commit 7f1d71f
Showing
8 changed files
with
104 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= | ||