-
Notifications
You must be signed in to change notification settings - Fork 8
/
items.go
110 lines (95 loc) · 2.75 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Code generated by op-codegen - DO NOT EDIT
package onepassword
import (
"context"
"encoding/json"
"github.com/1password/onepassword-sdk-go/internal"
)
// The Items API holds all operations the SDK client can perform on 1Password items.
type ItemsAPI interface {
// Create a new item
Create(ctx context.Context, params ItemCreateParams) (Item, error)
// Get an item by vault and item ID
Get(ctx context.Context, vaultId string, itemId string) (Item, error)
// Update an existing item.
Put(ctx context.Context, item Item) (Item, error)
// Delete an item.
Delete(ctx context.Context, vaultId string, itemId string) error
// List all items
ListAll(ctx context.Context, vaultId string) (*Iterator[ItemOverview], error)
}
type ItemsSource struct {
internal.InnerClient
}
func NewItemsSource(inner internal.InnerClient) *ItemsSource {
return &ItemsSource{inner}
}
// Create a new item
func (s ItemsSource) Create(ctx context.Context, params ItemCreateParams) (Item, error) {
resultString, err := clientInvoke(ctx, s.InnerClient, "ItemsCreate", map[string]interface{}{
"params": params,
})
if err != nil {
return Item{}, err
}
var result Item
err = json.Unmarshal([]byte(*resultString), &result)
if err != nil {
return Item{}, err
}
return result, nil
}
// Get an item by vault and item ID
func (s ItemsSource) Get(ctx context.Context, vaultId string, itemId string) (Item, error) {
resultString, err := clientInvoke(ctx, s.InnerClient, "ItemsGet", 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
}
// Update an existing item.
func (s ItemsSource) Put(ctx context.Context, item Item) (Item, error) {
resultString, err := clientInvoke(ctx, s.InnerClient, "ItemsPut", 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
}
// Delete an item.
func (s ItemsSource) Delete(ctx context.Context, vaultId string, itemId string) error {
_, err := clientInvoke(ctx, s.InnerClient, "ItemsDelete", map[string]interface{}{
"vault_id": vaultId,
"item_id": itemId,
})
return err
}
// List all items
func (s ItemsSource) ListAll(ctx context.Context, vaultId string) (*Iterator[ItemOverview], error) {
resultString, err := clientInvoke(ctx, s.InnerClient, "ItemsListAll", map[string]interface{}{
"vault_id": vaultId,
})
if err != nil {
return nil, err
}
var result []ItemOverview
err = json.Unmarshal([]byte(*resultString), &result)
if err != nil {
return nil, err
}
return NewIterator(result), nil
}