1Password/connect-sdk-go

Have a list of constants for Item field types

edif2008 opened this issue · 0 comments

Summary

Currently when making an Item, you need to specify a type for each field you create. (e.g. STRING, CONCEALED, OTP, EMAIL). However, it can be a bit tricky to know by heart what the right purpose is for each field.
Therefore, we want to add the constants for supported field purposes, according to the API spec.

Tasks to be done

  • Add a new type that will be used as a field purpose, along with the constants that represent the supported field purposes. Add this in onepassword/items.go
    type ItemFieldType string
    
    const (
        FieldTypeAddress          ItemFieldType = "ADDRESS"
        FieldTypeConcealed        ItemFieldType = "CONCEALED"
        FieldTypeCreditCardNumber ItemFieldType = "CREDIT_CARD_NUMBER"
        FieldTypeCreditCardType   ItemFieldType = "CREDIT_CARD_TYPE"
        FieldTypeDate             ItemFieldType = "DATE"
        FieldTypeEmail            ItemFieldType = "EMAIL"
        FieldTypeGender           ItemFieldType = "GENDER"
        FieldTypeMenu             ItemFieldType = "MENU"
        FieldTypeMonthYear        ItemFieldType = "MONTH_YEAR"
        FieldTypeOTP              ItemFieldType = "OTP"
        FieldTypePhone            ItemFieldType = "PHONE"
        FieldTypeReference        ItemFieldType = "REFERENCE"
        FieldTypeString           ItemFieldType = "STRING"
        FieldTypeURL              ItemFieldType = "URL"
        FieldTypeFile             ItemFieldType = "FILE"
        FieldTypeSSHKey           ItemFieldType = "SSH_KEY"
        FieldTypeUnknown          ItemFieldType = "UNKNOWN"
    )
  • Change the Purpose property of the ItemFiled struct to have the new type. (line 108)
    // ItemField Representation of a single field on an Item
    type ItemField struct {
        ID       string           `json:"id"`
        Section  *ItemSection     `json:"section,omitempty"`
        Type     ItemFieldType    `json:"type"`
        Purpose  string           `json:"purpose,omitempty"`
        Label    string           `json:"label,omitempty"`
        Value    string           `json:"value,omitempty"`
        Generate bool             `json:"generate,omitempty"`
        Recipe   *GeneratorRecipe `json:"recipe,omitempty"`
        Entropy  float64          `json:"entropy,omitempty"`
        TOTP     string           `json:"totp,omitempty"`
    }