-
Notifications
You must be signed in to change notification settings - Fork 8
/
types.go
377 lines (337 loc) · 11.8 KB
/
types.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
// Code generated by typeshare 1.12.0. DO NOT EDIT.
package onepassword
import "encoding/json"
// For future use, if we want to return more information about the generated password.
// Currently, it only returns the password itself.
type GeneratePasswordResponse struct {
// The generated password.
Password string `json:"password"`
}
type ItemCategory string
const (
ItemCategoryLogin ItemCategory = "Login"
ItemCategorySecureNote ItemCategory = "SecureNote"
ItemCategoryCreditCard ItemCategory = "CreditCard"
ItemCategoryCryptoWallet ItemCategory = "CryptoWallet"
ItemCategoryIdentity ItemCategory = "Identity"
ItemCategoryPassword ItemCategory = "Password"
ItemCategoryDocument ItemCategory = "Document"
ItemCategoryAPICredentials ItemCategory = "ApiCredentials"
ItemCategoryBankAccount ItemCategory = "BankAccount"
ItemCategoryDatabase ItemCategory = "Database"
ItemCategoryDriverLicense ItemCategory = "DriverLicense"
ItemCategoryEmail ItemCategory = "Email"
ItemCategoryMedicalRecord ItemCategory = "MedicalRecord"
ItemCategoryMembership ItemCategory = "Membership"
ItemCategoryOutdoorLicense ItemCategory = "OutdoorLicense"
ItemCategoryPassport ItemCategory = "Passport"
ItemCategoryRewards ItemCategory = "Rewards"
ItemCategoryRouter ItemCategory = "Router"
ItemCategoryServer ItemCategory = "Server"
ItemCategorySSHKey ItemCategory = "SshKey"
ItemCategorySocialSecurityNumber ItemCategory = "SocialSecurityNumber"
ItemCategorySoftwareLicense ItemCategory = "SoftwareLicense"
ItemCategoryPerson ItemCategory = "Person"
ItemCategoryUnsupported ItemCategory = "Unsupported"
)
type ItemFieldType string
const (
ItemFieldTypeText ItemFieldType = "Text"
ItemFieldTypeConcealed ItemFieldType = "Concealed"
ItemFieldTypeCreditCardType ItemFieldType = "CreditCardType"
ItemFieldTypeCreditCardNumber ItemFieldType = "CreditCardNumber"
ItemFieldTypePhone ItemFieldType = "Phone"
ItemFieldTypeURL ItemFieldType = "Url"
ItemFieldTypeTOTP ItemFieldType = "Totp"
ItemFieldTypeUnsupported ItemFieldType = "Unsupported"
)
// Field type-specific attributes.
type ItemFieldDetailsTypes string
const (
// The computed OTP code and other details
ItemFieldDetailsTypeVariantOTP ItemFieldDetailsTypes = "Otp"
)
type ItemFieldDetails struct {
Type ItemFieldDetailsTypes `json:"type"`
content interface{}
}
func (i *ItemFieldDetails) UnmarshalJSON(data []byte) error {
var enum struct {
Tag ItemFieldDetailsTypes `json:"type"`
Content json.RawMessage `json:"content"`
}
if err := json.Unmarshal(data, &enum); err != nil {
return err
}
i.Type = enum.Tag
switch i.Type {
case ItemFieldDetailsTypeVariantOTP:
var res OTPFieldDetails
i.content = &res
}
if err := json.Unmarshal(enum.Content, &i.content); err != nil {
return err
}
return nil
}
func (i ItemFieldDetails) MarshalJSON() ([]byte, error) {
var enum struct {
Tag ItemFieldDetailsTypes `json:"type"`
Content interface{} `json:"content,omitempty"`
}
enum.Tag = i.Type
enum.Content = i.content
return json.Marshal(enum)
}
func (i ItemFieldDetails) OTP() *OTPFieldDetails {
res, _ := i.content.(*OTPFieldDetails)
return res
}
func NewItemFieldDetailsTypeVariantOTP(content *OTPFieldDetails) ItemFieldDetails {
return ItemFieldDetails{
Type: ItemFieldDetailsTypeVariantOTP,
content: content,
}
}
// Represents a field within an item.
type ItemField struct {
// The field's ID
ID string `json:"id"`
// The field's title
Title string `json:"title"`
// The ID of the section containing the field. Built-in fields such as usernames and passwords don't require a section.
SectionID *string `json:"sectionId,omitempty"`
// The field's type
FieldType ItemFieldType `json:"fieldType"`
// The string representation of the field's value
Value string `json:"value"`
// Field type-specific attributes.
Details *ItemFieldDetails `json:"details,omitempty"`
}
// A section groups together multiple fields in an item.
type ItemSection struct {
// The section's unique ID
ID string `json:"id"`
// The section's title
Title string `json:"title"`
}
// Controls the auto-fill behavior of a website.
//
// For more information, visit https://support.1password.com/autofill-behavior/
type AutofillBehavior string
const (
// Auto-fill any page that’s part of the website, including subdomains
AutofillBehaviorAnywhereOnWebsite AutofillBehavior = "AnywhereOnWebsite"
// Auto-fill only if the domain (hostname and port) is an exact match.
AutofillBehaviorExactDomain AutofillBehavior = "ExactDomain"
// Never auto-fill on this website
AutofillBehaviorNever AutofillBehavior = "Never"
)
type Website struct {
// The website URL
URL string `json:"url"`
// The label of the website, e.g. 'website', 'sign-in address'
Label string `json:"label"`
// The auto-fill behavior of the website
//
// For more information, visit https://support.1password.com/autofill-behavior/
AutofillBehavior AutofillBehavior `json:"autofillBehavior"`
}
// Represents a 1Password item.
type Item struct {
// The item's ID
ID string `json:"id"`
// The item's title
Title string `json:"title"`
// The item's category
Category ItemCategory `json:"category"`
// The ID of the vault where the item is saved
VaultID string `json:"vaultId"`
// The item's fields
Fields []ItemField `json:"fields"`
// The item's sections
Sections []ItemSection `json:"sections"`
// The item's tags
Tags []string `json:"tags"`
// The websites used for autofilling for items of the Login and Password categories.
Websites []Website `json:"websites"`
// The item's version
Version uint32 `json:"version"`
}
type ItemCreateParams struct {
// The item's category
Category ItemCategory `json:"category"`
// The ID of the vault where the item is saved
VaultID string `json:"vaultId"`
// The item's title
Title string `json:"title"`
// The item's fields
Fields []ItemField `json:"fields,omitempty"`
// The item's sections
Sections []ItemSection `json:"sections,omitempty"`
// The item's tags
Tags []string `json:"tags,omitempty"`
// The websites used for autofilling for items of the Login and Password categories.
Websites []Website `json:"websites,omitempty"`
}
// Represents a decrypted 1Password item.
type ItemOverview struct {
// The item's ID
ID string `json:"id"`
// The item's title
Title string `json:"title"`
// The item's category
Category ItemCategory `json:"category"`
// The ID of the vault where the item is saved
VaultID string `json:"vaultId"`
// The websites used for autofilling for items of the Login and Password categories.
Websites []Website `json:"websites"`
}
// Additional attributes for OTP fields.
type OTPFieldDetails struct {
// The OTP code, if successfully computed
Code *string `json:"code,omitempty"`
// The error message, if the OTP code could not be computed
ErrorMessage *string `json:"errorMessage,omitempty"`
}
// Represents a decrypted 1Password vault.
type VaultOverview struct {
// The vault's ID
ID string `json:"id"`
// The vault's title
Title string `json:"title"`
}
// Generated type representing the anonymous struct variant `Memorable` of the `PasswordRecipe` Rust enum
type PasswordRecipeMemorableInner struct {
// The type of separator between chunks.
SeparatorType SeparatorType `json:"separatorType"`
// Uppercase one randomly selected chunk.
Capitalize bool `json:"capitalize"`
// The type of word list used.
WordListType WordListType `json:"wordListType"`
// The number of "words" (words or syllables).
WordCount uint32 `json:"wordCount"`
}
// Generated type representing the anonymous struct variant `Pin` of the `PasswordRecipe` Rust enum
type PasswordRecipePinInner struct {
// Number of digits in the PIN.
Length uint32 `json:"length"`
}
// Generated type representing the anonymous struct variant `Random` of the `PasswordRecipe` Rust enum
type PasswordRecipeRandomInner struct {
// Include at least one digit in the password.
IncludeDigits bool `json:"includeDigits"`
// Include at least one symbol in the password.
IncludeSymbols bool `json:"includeSymbols"`
// The length of the password.
Length uint32 `json:"length"`
}
type PasswordRecipeTypes string
const (
PasswordRecipeTypeVariantMemorable PasswordRecipeTypes = "Memorable"
PasswordRecipeTypeVariantPin PasswordRecipeTypes = "Pin"
PasswordRecipeTypeVariantRandom PasswordRecipeTypes = "Random"
)
type PasswordRecipe struct {
Type PasswordRecipeTypes `json:"type"`
parameters interface{}
}
func (p *PasswordRecipe) UnmarshalJSON(data []byte) error {
var enum struct {
Tag PasswordRecipeTypes `json:"type"`
Content json.RawMessage `json:"parameters"`
}
if err := json.Unmarshal(data, &enum); err != nil {
return err
}
p.Type = enum.Tag
switch p.Type {
case PasswordRecipeTypeVariantMemorable:
var res PasswordRecipeMemorableInner
p.parameters = &res
case PasswordRecipeTypeVariantPin:
var res PasswordRecipePinInner
p.parameters = &res
case PasswordRecipeTypeVariantRandom:
var res PasswordRecipeRandomInner
p.parameters = &res
}
if err := json.Unmarshal(enum.Content, &p.parameters); err != nil {
return err
}
return nil
}
func (p PasswordRecipe) MarshalJSON() ([]byte, error) {
var enum struct {
Tag PasswordRecipeTypes `json:"type"`
Content interface{} `json:"parameters,omitempty"`
}
enum.Tag = p.Type
enum.Content = p.parameters
return json.Marshal(enum)
}
func (p PasswordRecipe) Memorable() *PasswordRecipeMemorableInner {
res, _ := p.parameters.(*PasswordRecipeMemorableInner)
return res
}
func (p PasswordRecipe) Pin() *PasswordRecipePinInner {
res, _ := p.parameters.(*PasswordRecipePinInner)
return res
}
func (p PasswordRecipe) Random() *PasswordRecipeRandomInner {
res, _ := p.parameters.(*PasswordRecipeRandomInner)
return res
}
func NewPasswordRecipeTypeVariantMemorable(content *PasswordRecipeMemorableInner) PasswordRecipe {
return PasswordRecipe{
Type: PasswordRecipeTypeVariantMemorable,
parameters: content,
}
}
func NewPasswordRecipeTypeVariantPin(content *PasswordRecipePinInner) PasswordRecipe {
return PasswordRecipe{
Type: PasswordRecipeTypeVariantPin,
parameters: content,
}
}
func NewPasswordRecipeTypeVariantRandom(content *PasswordRecipeRandomInner) PasswordRecipe {
return PasswordRecipe{
Type: PasswordRecipeTypeVariantRandom,
parameters: content,
}
}
type SeparatorType string
const (
// Randomly selected digits.
// E.g, "`correct4horse0battery1staple`"
SeparatorTypeDigits SeparatorType = "digits"
// Randomly selected digits and symbols.
// This is useful to get word-based passwords to meet complexity requirements
// E.g, "`correct4horse-battery1staple`"
SeparatorTypeDigitsAndSymbols SeparatorType = "digitsAndSymbols"
// Spaces, like the original Diceware.
// Great for mobile keyboards, not so great when people can overhear you type the password.
// E.g, "`correct horse battery staple`"
SeparatorTypeSpaces SeparatorType = "spaces"
// Hyphens "`-`".
// E.g, "`correct-horse-battery-staple`"
SeparatorTypeHyphens SeparatorType = "hyphens"
// "`_`".
// E.g, "`correct_horse_battery_staple`"
SeparatorTypeUnderscores SeparatorType = "underscores"
// Period (full stop) "`.`".
// E.g, "`correct.horse.battery.staple`"
SeparatorTypePeriods SeparatorType = "periods"
// Comma "`,`".
// E.g, "`correct,horse,battery,staple`"
SeparatorTypeCommas SeparatorType = "commas"
)
type WordListType string
const (
// Agile wordlist
WordListTypeFullWords WordListType = "fullWords"
// English-like syllables
WordListTypeSyllables WordListType = "syllables"
// Three (random) letter "words"
WordListTypeThreeLetters WordListType = "threeLetters"
)