Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SM-1082: Add SM State to Go SDK Wrapper #559

Merged
merged 8 commits into from
Feb 15, 2024
Merged

SM-1082: Add SM State to Go SDK Wrapper #559

merged 8 commits into from
Feb 15, 2024

Conversation

coltonhurst
Copy link
Member

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

@coltonhurst coltonhurst self-assigned this Jan 29, 2024
Copy link

codecov bot commented Jan 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (main@1595306). Click here to learn what that means.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #559   +/-   ##
=======================================
  Coverage        ?   57.76%           
=======================================
  Files           ?      168           
  Lines           ?     9912           
  Branches        ?        0           
=======================================
  Hits            ?     5726           
  Misses          ?     4186           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@coltonhurst coltonhurst changed the title SM-1082: Add SM Go SDK Wrapper SM-1082: Add SM State to Go SDK Wrapper Jan 30, 2024
@bitwarden-bot
Copy link

bitwarden-bot commented Jan 30, 2024

Logo
Checkmarx One – Scan Summary & Detailsce9b2a12-1a91-413b-83df-c6a875682f47

No New Or Fixed Issues Found

Thomas-Avery
Thomas-Avery previously approved these changes Jan 31, 2024
Copy link
Contributor

@Thomas-Avery Thomas-Avery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure to update the README.md in the Go folder to include the new parameter to AccessTokenLogin too.

languages/go/bitwarden_client.go Show resolved Hide resolved
languages/go/example/example.go Outdated Show resolved Hide resolved
Copy link
Member

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're missing a reference to the old AccessTokenLogin without statepath in the Readme:

https://github.com/bitwarden/sdk/blob/1595306d0f80807983c374aaebc4938a835be78c/languages/go/README.md?plain=1#L42

Also it still has the old return type, while now it just returns an error, so we should change that too

@coltonhurst
Copy link
Member Author

We're missing a reference to the old AccessTokenLogin without statepath in the Readme:

https://github.com/bitwarden/sdk/blob/1595306d0f80807983c374aaebc4938a835be78c/languages/go/README.md?plain=1#L42

Also it still has the old return type, while now it just returns an error, so we should change that too

Good call. I've updated the README and added a very small description regarding using statePath or nil.

Comment on lines +22 to +23
// Configuring the statePath is optional, pass nil
// in AccessTokenLogin() to not use state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment is more descriptive.

Suggested change
// Configuring the statePath is optional, pass nil
// in AccessTokenLogin() to not use state
// Optional state file to persist access tokens between runs.

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fairly cryptic, can we rewrite it to something like

Login using an access token, accepts an optional statePath which allows you to persist login sessions across multiple runs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colton is out, I'm going to merge this PR now to get it in the hands of our vendor and and create a separate PR with these comment updates.

@differsthecat differsthecat merged commit 5a0575e into main Feb 15, 2024
57 checks passed
@differsthecat differsthecat deleted the sm/sm-1082 branch February 15, 2024 19:00
coltonhurst added a commit that referenced this pull request Jul 25, 2024
## 🎟️ Tracking

<!-- Paste the link to the Jira or GitHub issue or otherwise describe /
point to where this change is coming from. -->

https://bitwarden.atlassian.net/browse/SM-1096

## 📔 Objective

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

The naming around state files and paths is inconsistent. This PR aims to
make the usage consistent.

Every mention of state for access token auth should follow this naming
logic:

`state_dir` <- This refers to the state directory, where state files are
stored. The sdk is currently only aware of state files, directory
handling is still being done in bws.
`state_file` <- This refers to a specific state file.

In our code we don't append naming to variables to indicate the type
(Hungarian Notation), so I thought it pertinent to truncate `_path` from
these, preferring more descriptive `state_dir` and `state_file` for the
names.

Thanks @dani-garcia for pointing this out
[here](#559 (comment)).

⚠️ **Note** ⚠️ This also simplifies the `state_file_dir` key in the
`bws` config file to `state_dir`. There will be more changes to this
functionality with SM-1174, so I will wait to update the changelog for
the next bws version until all this is completed.

## ⏰ Reminders before review

- Contributor guidelines followed
- All formatters and local linters executed and passed
- Written new unit and / or integration tests where applicable
- Protected functional changes with optionality (feature flags)
- Used internationalization (i18n) for all UI strings
- CI builds passed
- Communicated to DevOps any deployment requirements
- Updated any necessary documentation (Confluence, contributing docs) or
informed the documentation
  team

## 🦮 Reviewer guidelines

<!-- Suggested interactions but feel free to use (or not) as you desire!
-->

- 👍 (`:+1:`) or similar for great changes
- 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info
- ❓ (`:question:`) for questions
- 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry
that's not quite a confirmed
  issue and could potentially benefit from discussion
- 🎨 (`:art:`) for suggestions / improvements
- ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or
concerns needing attention
- 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or
indications of technical debt
- ⛏ (`:pick:`) for minor or nitpick changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants