Skip to content

Commit 9be7244

Browse files
MOmarMiraj1PasswordSDKBotlibutcher
authored
Go SDK Release v0.3.0 (#194)
* Update core to version e1f91a18 * update example code * Release v0.3.0 * fix release notes * fix release notes * fix heading for breaking change * add single ticks to function names and return types * Apply suggestions from code review Co-authored-by: Lucy Butcher <[email protected]> * Update internal/release/RELEASE-NOTES Co-authored-by: Lucy Butcher <[email protected]> * remove extra newline and fix formatting * delete iterator file --------- Co-authored-by: 1PasswordSDKBot <[email protected]> Co-authored-by: Lucy Butcher <[email protected]>
1 parent 4b20509 commit 9be7244

File tree

9 files changed

+199
-95
lines changed

9 files changed

+199
-95
lines changed

example/main.go

+26-27
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"crypto/rsa"
77
"crypto/x509"
88
"encoding/pem"
9-
"errors"
109
"fmt"
1110
"os"
1211
)
@@ -43,42 +42,48 @@ func main() {
4342
resolveTOTPSecretReference(client, item.VaultID, item.ID, "TOTP_onetimepassword")
4443
sharelink := generateItemSharing(client, item.VaultID, item.ID)
4544
fmt.Println(sharelink)
45+
archiveItem(client, item.VaultID, item.ID)
4646
deleteItem(client, item.VaultID, item.ID)
4747
}
4848

4949
func listVaultsAndItems(client *onepassword.Client, vaultID string) {
5050
// [developer-docs.sdk.go.list-vaults]-start
51-
vaults, err := client.Vaults().ListAll(context.Background())
51+
vaults, err := client.Vaults().List(context.Background())
5252
if err != nil {
5353
panic(err)
5454
}
55-
for {
56-
vault, err := vaults.Next()
57-
if errors.Is(err, onepassword.ErrorIteratorDone) {
58-
break
59-
} else if err != nil {
60-
panic(err)
61-
}
62-
55+
for _, vault := range vaults {
6356
fmt.Printf("%s %s\n", vault.ID, vault.Title)
6457
}
6558
// [developer-docs.sdk.go.list-vaults]-end
6659

6760
// [developer-docs.sdk.go.list-items]-start
68-
items, err := client.Items().ListAll(context.Background(), vaultID)
61+
overviews, err := client.Items().List(context.Background(), vaultID)
6962
if err != nil {
7063
panic(err)
7164
}
72-
for {
73-
item, err := items.Next()
74-
if errors.Is(err, onepassword.ErrorIteratorDone) {
75-
break
76-
} else if err != nil {
77-
panic(err)
78-
}
79-
fmt.Printf("%s %s\n", item.ID, item.Title)
65+
for _, overview := range overviews {
66+
fmt.Printf("%s %s\n", overview.ID, overview.Title)
8067
}
8168
// [developer-docs.sdk.go.list-items]-end
69+
70+
// [developer-docs.sdk.go.use-item-filters]-start
71+
archivedOverviews, err := client.Items().List(context.Background(), vaultID,
72+
onepassword.NewItemListFilterTypeVariantByState(
73+
&onepassword.ItemListFilterByStateInner{
74+
Active: false,
75+
Archived: true,
76+
},
77+
),
78+
)
79+
if err != nil {
80+
panic(err)
81+
}
82+
for _, overview := range archivedOverviews {
83+
fmt.Printf("%s %s\n", overview.ID, overview.Title)
84+
}
85+
// [developer-docs.sdk.go.use-item-filters]-end
86+
8287
}
8388

8489
func getAndUpdateItem(client *onepassword.Client, existingVaultID, existingItemID string) {
@@ -140,9 +145,9 @@ func resolveBulkSecretReferences(client *onepassword.Client, vaultID, itemID, fi
140145
// Retrieves multiple secrets from 1Password.
141146
// Takes multiple secret references as input and returns the secret to which it points.
142147
secret, _ := client.Secrets().ResolveAll(
143-
context.Background(),
148+
context.Background(),
144149
[]string{
145-
fmt.Sprintf("op://%s/%s/%s", vaultID, itemID, fieldID),
150+
fmt.Sprintf("op://%s/%s/%s", vaultID, itemID, fieldID),
146151
fmt.Sprintf("op://%s/%s/%s", vaultID, itemID, fieldID2),
147152
},
148153
)
@@ -290,11 +295,6 @@ func generatePasswords() {
290295
// [developer-docs.sdk.go.generate-memorable-password]-end
291296
}
292297

293-
// NOTE: just for the sake of archiving it. This is because the SDK
294-
// NOTE: only works with active items, so archiving and then deleting
295-
// NOTE: is not yet possible.
296-
//
297-
//lint:ignore U1000 NOTE: this is in a separate function to avoid creating a new item
298298
func archiveItem(client *onepassword.Client, vaultID string, itemID string) {
299299
// [developer-docs.sdk.go.archive-item]-start
300300
// Archive a item from your vault.
@@ -303,7 +303,6 @@ func archiveItem(client *onepassword.Client, vaultID string, itemID string) {
303303
if err != nil {
304304
panic(err)
305305
}
306-
307306
// [developer-docs.sdk.go.archive-item]-end
308307
}
309308

internal/release/RELEASE-NOTES

+83-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,90 @@
1-
# 1Password Go SDK v0.2.1
1+
# 1Password Go SDK v0.3.0
22

33
## NEW
44

5-
- **`CreatedAt` and `UpdatedAt` item metadata:** Items and item overviews now expose attributes with their creation and last edit times.
6-
- **Resolving secrets in bulk**: With the `client.Secrets().ResolveAll` function, the SDK is now able to resolve multiple secrets at once, improving the performance of the operation.
5+
- **Support for item states**: You can now fetch an item's state using the SDK. `ItemOverview` exposes one of two states: `Active` or `Archived`.
6+
- `Active`: An item located inside a vault. (Default)
7+
- `Archived`: An item that has been moved to the Archive. 1Password doesn't include archived items in search results or suggest them when you fill in apps and browsers. You can keep archived items as long as you'd like.
8+
- **Filtering listed items by state**: You can now filter the results of the item list function by item state.
79

8-
## IMPROVED
10+
## FIXED
911

10-
- **Support for new field types:** Items with `Address` and `Date` fields can now be created, retrieved, and edited using the 1Password SDK.
11-
- **Item sharing for attachments and documents**: Items with files attached now can also be shared using the `client.Items().Shares()` functions.
12-
- **Adding custom fields in sections automatically**: The SDK now automatically adds custom fields without a section to an empty section within the item, creating it if necessary.
13-
- **`Tags` in item overviews**: The return type of `Items().ListAll` now also contains the item tags.
14-
- **Broader item editing capabilities**: You are now able to use the `items.put` function on more items, including those with fields that are not directly editable through the SDK (such as legacy fields, passkeys etc.)
12+
- **Deleting Archived Items:** The SDK now supports deleting items from the archive.
1513

16-
## FIXED
14+
## ⚠️ BREAKING CHANGES ⚠️
15+
This release contains breaking changes for two functions in the Go SDK.
16+
17+
**Vault listing**
18+
19+
* The function name has changed from `ListAll` to `List`. To use this in your code, replace:
20+
```go
21+
vaults, err := client.Vaults().ListAll(context.Background(), vaultID)
22+
// error handling
23+
```
24+
with:
25+
```go
26+
vaults, err := client.Vaults().List(context.Background(), vaultID)
27+
// error handling
28+
```
29+
30+
* The return type of the vault listing function has changed from `*Iterator[VaultOverview]` to `[]VaultOverview`. To use this in your code, replace:
31+
32+
```go
33+
for {
34+
vault, err := vaults.Next()
35+
if errors.Is(err, onepassword.ErrorIteratorDone) {
36+
break
37+
} else if err != nil {
38+
// error handling
39+
}
40+
// using the vault overview
41+
}
42+
```
43+
with:
44+
```go
45+
for _, vault := range vaults {
46+
// using the vault overview
47+
}
48+
```
49+
**Item listing**
50+
51+
* The function name has changed from `ListAll` to `List`. To use this in your code, replace:
52+
```go
53+
overviews, err := client.Items().ListAll(context.Background())
54+
// error handling
55+
```
56+
with:
57+
```go
58+
overviews, err := client.Items().List(
59+
context.Background(),
60+
vaultID,
61+
onepassword.NewItemListFilterTypeVariantByState(
62+
&onepassword.ItemListFilterByStateInner{
63+
Active: true,
64+
Archived: true,
65+
},
66+
),
67+
)
68+
// error handling
69+
```
70+
71+
* The return type of the item listing function has changed from `*Iterator[ItemOverview]` to `[]ItemOverview`. To use this in your code, replace:
72+
```go
73+
for {
74+
overview, err := overviews.Next()
75+
if errors.Is(err, onepassword.ErrorIteratorDone) {
76+
break
77+
} else if err != nil {
78+
// error handling
79+
}
80+
// using the item overview
81+
}
82+
```
83+
with:
84+
```go
85+
for _, overview := range overviews {
86+
// using the item overview
87+
}
88+
```
1789

18-
- **Improvements to resolving secret references:**
19-
- Archived items are no longer used for secret references.
20-
- When multiple sections match a section query in resolving secret references, the SDK look through the fields in all sections, instead of erroring.
90+
This does not affect any code that's already deployed, and will not take effect in your codebase until you choose to update to version 0.3.0 or later of the 1Password Go SDK.

internal/release/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.1
1+
0.3.0

internal/release/version-build

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0020101
1+
0030001

internal/wasm/core.wasm

15.9 KB
Binary file not shown.

items.go

+10-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iterator.go

-42
This file was deleted.

0 commit comments

Comments
 (0)