Skip to content

Commit

Permalink
SM-1082: Add SM State to Go SDK Wrapper (#559)
Browse files Browse the repository at this point in the history
## Type of change

<!-- (mark with an `X`) -->

```
- [ ] Bug fix
- [x] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other
```

## Objective

<!--Describe what the purpose of this PR is. For example: what bug
you're fixing or what new feature you're adding-->

Add the ability to easily use SM state in Go to the
`bitwarden_client.go`.

## Code changes

<!--Explain the changes you've made to each file or major component.
This should help the reviewer understand your changes-->
<!--Also refer to any related changes or PRs in other repositories-->

- **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
  • Loading branch information
coltonhurst authored Feb 15, 2024
1 parent c03bcf5 commit 5a0575e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions languages/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

---
Expand Down
4 changes: 2 additions & 2 deletions languages/go/bitwarden_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion languages/go/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 5a0575e

Please sign in to comment.