From 5a0575e722a832c5ba481be0afb94e9ac8119937 Mon Sep 17 00:00:00 2001 From: Colton Hurst Date: Thu, 15 Feb 2024 14:00:32 -0500 Subject: [PATCH] SM-1082: Add SM State to Go SDK Wrapper (#559) ## Type of change ``` - [ ] Bug fix - [x] New feature development - [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [ ] Build/deploy pipeline (DevOps) - [ ] Other ``` ## Objective Add the ability to easily use SM state in Go to the `bitwarden_client.go`. ## Code changes - **bitwarden_client.go:** Add the `statePath` parameter - **example.go:** Set state in the example ## Before you submit - Please add **unit tests** where it makes sense to do so --- languages/go/README.md | 6 ++++-- languages/go/bitwarden_client.go | 4 ++-- languages/go/example/example.go | 6 +++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/languages/go/README.md b/languages/go/README.md index e57badf7e..cea02e282 100644 --- a/languages/go/README.md +++ b/languages/go/README.md @@ -36,10 +36,12 @@ bitwardenClient, _ := sdk.NewBitwardenClient(&apiURL, &identityURL) ### Login -To login using an access token: +To login using an access token. Define some `statePath` and pass it to use state, or pass `nil` instead to not use state. ```go -apiKeyLogin, err := bitwardenClient.AccessTokenLogin(accessToken) +statePath := os.Getenv("STATE_PATH") + +err := bitwardenClient.AccessTokenLogin(accessToken, &statePath) ``` --- diff --git a/languages/go/bitwarden_client.go b/languages/go/bitwarden_client.go index 5e1108ce1..bd236de71 100644 --- a/languages/go/bitwarden_client.go +++ b/languages/go/bitwarden_client.go @@ -45,8 +45,8 @@ func NewBitwardenClient(apiURL *string, identityURL *string) (*BitwardenClient, }, nil } -func (c *BitwardenClient) AccessTokenLogin(accessToken string) error { - req := AccessTokenLoginRequest{AccessToken: accessToken} +func (c *BitwardenClient) AccessTokenLogin(accessToken string, statePath *string) error { + req := AccessTokenLoginRequest{AccessToken: accessToken, StateFile: statePath} command := Command{AccessTokenLogin: &req} responseStr, err := c.commandRunner.RunCommand(command) diff --git a/languages/go/example/example.go b/languages/go/example/example.go index 154c14618..deb353565 100644 --- a/languages/go/example/example.go +++ b/languages/go/example/example.go @@ -19,11 +19,15 @@ func main() { organizationIDStr := os.Getenv("ORGANIZATION_ID") projectName := os.Getenv("PROJECT_NAME") + // Configuring the statePath is optional, pass nil + // in AccessTokenLogin() to not use state + statePath := os.Getenv("STATE_PATH") + if projectName == "" { projectName = "NewTestProject" // default value } - err := bitwardenClient.AccessTokenLogin(accessToken) + err := bitwardenClient.AccessTokenLogin(accessToken, &statePath) if err != nil { panic(err) }