forked from 1Password/onepassword-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
items.go
87 lines (74 loc) · 2.13 KB
/
items.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// AUTOGENERATED - DO NOT EDIT MANUALLY
package onepassword
import (
"context"
"encoding/json"
"github.com/1password/onepassword-sdk-go/internal"
)
// ItemsAPI contains all operations the SDK client can perform on 1Password items.
type ItemsAPI interface {
// Create a new item
Create(ctx context.Context, item Item) (Item, error)
// Get an item by vault and item ID
Get(ctx context.Context, vaultId string, itemId string) (Item, error)
// Update an existing item. You can currently only edit text and concealed fields.
Update(ctx context.Context, item Item) (Item, error)
// Delete an item.
Delete(ctx context.Context, vaultId string, itemId string) error
}
type ItemsSource struct {
internal.InnerClient
}
func NewItemsSource(inner internal.InnerClient) *ItemsSource {
return &ItemsSource{inner}
}
func (s ItemsSource) Create(ctx context.Context, item Item) (Item, error) {
resultString, err := clientInvoke(ctx, s.InnerClient, "Create", map[string]interface{}{
"item": item,
})
if err != nil {
return Item{}, err
}
var result Item
err = json.Unmarshal([]byte(*resultString), &result)
if err != nil {
return Item{}, err
}
return result, nil
}
func (s ItemsSource) Get(ctx context.Context, vaultId string, itemId string) (Item, error) {
resultString, err := clientInvoke(ctx, s.InnerClient, "Get", map[string]interface{}{
"vault_id": vaultId,
"item_id": itemId,
})
if err != nil {
return Item{}, err
}
var result Item
err = json.Unmarshal([]byte(*resultString), &result)
if err != nil {
return Item{}, err
}
return result, nil
}
func (s ItemsSource) Update(ctx context.Context, item Item) (Item, error) {
resultString, err := clientInvoke(ctx, s.InnerClient, "Update", map[string]interface{}{
"item": item,
})
if err != nil {
return Item{}, err
}
var result Item
err = json.Unmarshal([]byte(*resultString), &result)
if err != nil {
return Item{}, err
}
return result, nil
}
func (s ItemsSource) Delete(ctx context.Context, vaultId string, itemId string) error {
_, err := clientInvoke(ctx, s.InnerClient, "Delete", map[string]interface{}{
"vault_id": vaultId,
"item_id": itemId,
})
return err
}