From 80a9fcb0106f45841c90de1103d9e95fc9adae0c Mon Sep 17 00:00:00 2001 From: Colton Hurst Date: Mon, 29 Jan 2024 17:06:33 -0500 Subject: [PATCH 1/5] SM-1082: Add SM state to bitwarden_client.go --- languages/go/bitwarden_client.go | 4 ++-- languages/go/example/example.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/languages/go/bitwarden_client.go b/languages/go/bitwarden_client.go index 5e1108ce1..70ca7a602 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, state_path *string) error { + req := AccessTokenLoginRequest{AccessToken: accessToken, StateFile: state_path} 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..9f654822f 100644 --- a/languages/go/example/example.go +++ b/languages/go/example/example.go @@ -16,6 +16,7 @@ func main() { bitwardenClient, _ := sdk.NewBitwardenClient(&apiURL, &identityURL) accessToken := os.Getenv("ACCESS_TOKEN") + statePath := os.Getenv("STATE_PATH") organizationIDStr := os.Getenv("ORGANIZATION_ID") projectName := os.Getenv("PROJECT_NAME") @@ -23,7 +24,7 @@ func main() { projectName = "NewTestProject" // default value } - err := bitwardenClient.AccessTokenLogin(accessToken) + err := bitwardenClient.AccessTokenLogin(accessToken, &statePath) if err != nil { panic(err) } From c09e13f517f87119f559fae296dc7e7a29ced549 Mon Sep 17 00:00:00 2001 From: Colton Hurst Date: Mon, 29 Jan 2024 17:09:22 -0500 Subject: [PATCH 2/5] SM-1082: Use camelCase --- languages/go/bitwarden_client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/languages/go/bitwarden_client.go b/languages/go/bitwarden_client.go index 70ca7a602..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, state_path *string) error { - req := AccessTokenLoginRequest{AccessToken: accessToken, StateFile: state_path} +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) From bd86086f627b8d231c4f38c447c38170db6c1a82 Mon Sep 17 00:00:00 2001 From: Colton Hurst Date: Mon, 5 Feb 2024 19:34:38 -0500 Subject: [PATCH 3/5] SM-1082: Mark statePath as optional in Go wrapper --- languages/go/example/example.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/languages/go/example/example.go b/languages/go/example/example.go index 9f654822f..3ebfcd09a 100644 --- a/languages/go/example/example.go +++ b/languages/go/example/example.go @@ -16,10 +16,13 @@ func main() { bitwardenClient, _ := sdk.NewBitwardenClient(&apiURL, &identityURL) accessToken := os.Getenv("ACCESS_TOKEN") - statePath := os.Getenv("STATE_PATH") organizationIDStr := os.Getenv("ORGANIZATION_ID") projectName := os.Getenv("PROJECT_NAME") + // Configuring the statePath is optional, pass nil + // in AccessTokenLogni() to not use state + statePath := os.Getenv("STATE_PATH") + if projectName == "" { projectName = "NewTestProject" // default value } From ac94ce967741cd62ad9d0ed74d5b9f688bb27a7a Mon Sep 17 00:00:00 2001 From: Colton Hurst Date: Tue, 6 Feb 2024 16:01:56 -0500 Subject: [PATCH 4/5] SM-1082: Fix spelling error --- languages/go/example/example.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages/go/example/example.go b/languages/go/example/example.go index 3ebfcd09a..deb353565 100644 --- a/languages/go/example/example.go +++ b/languages/go/example/example.go @@ -20,7 +20,7 @@ func main() { projectName := os.Getenv("PROJECT_NAME") // Configuring the statePath is optional, pass nil - // in AccessTokenLogni() to not use state + // in AccessTokenLogin() to not use state statePath := os.Getenv("STATE_PATH") if projectName == "" { From 6d50e85d0e627cbdbae8aa743e286b3398095f06 Mon Sep 17 00:00:00 2001 From: Colton Hurst Date: Wed, 7 Feb 2024 11:28:25 -0500 Subject: [PATCH 5/5] SM-1082: Update Go readme --- languages/go/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 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) ``` ---