gosn

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2019 License: MIT Imports: 32 Imported by: 0

README

gosn

Build Status CircleCI GoDoc Go Report Card

about

Standard Notes is a service and application for the secure management and storage of notes.

gosn is a library to help develop your own application to manage notes on the official, or your self-hosted, Standard Notes server.

installation

Using go get: go get github.com/jonhadfield/gosn

documentation

basic usage

authenticating

To interact with Standard Notes you first need to sign in:

    sIn := gosn.SignInInput{
        Email:     "someone@example.com",
        Password:  "mysecret,
    }
    sOut, _ := gosn.SignIn(sIn)

This will return a session containing the necessary secrets and information to make requests to get or put data.

getting items

    input := GetItemsInput{
        Session: sOut.Session,
    }
    gio, _ := GetItems(input)

creating a note

    # create note content
    content := NoteContent{
        Title:          "Note Title",
        Text:           "Note Text",
    }
    # create note
    note := NewNote()
    note.Content = content
    
    # sync note
    pii := PutItemsInput{
    		Session: sOut.Session,
    		Items:   []gosn.Notes{note},
    }
    pio, _ := PutItems(pii)

Documentation

Index

Constants

View Source
const (
	SNServerURL              = "https://sync.standardnotes.org"
	KeyringApplicationName   = "session"
	KeyringService           = "StandardNotesCLI"
	MsgSessionRemovalSuccess = "session removed successfully"
	MsgSessionRemovalFailure = "failed to remove session"
)
View Source
const (

	// PageSize is the maximum number of items to return with each call
	PageSize = 300
)

Variables

This section is empty.

Functions

func AddSession

func AddSession(snServer, inKey string, k keyring.Keyring) (res string, err error)

func Decrypt

func Decrypt(key []byte, cryptoText string) (pt string, err error)

decrypt from base64 to decrypted string

func Encrypt

func Encrypt(key []byte, text string) string

encrypt string to base64 crypto using AES

func GenUUID

func GenUUID() string

GenUUID generates a unique identifier required when creating a new item

func GetCredentials

func GetCredentials(inServer string) (email, password, apiServer, errMsg string)

func GetSessionFromKeyring

func GetSessionFromKeyring(k keyring.Keyring) (s string, err error)

func MakeSessionString

func MakeSessionString(email string, session Session) string

func RemoveSession

func RemoveSession(k keyring.Keyring) string

RemoveSession removes the SN session from the keyring

func SessionExists

func SessionExists(k keyring.Keyring) error

func SessionStatus

func SessionStatus(sKey string, k keyring.Keyring) (msg string, err error)

Types

type AppDataContent

type AppDataContent struct {
	OrgStandardNotesSN OrgStandardNotesSNDetail `json:"org.standardnotes.sn"`
}

type AppTagConfig

type AppTagConfig struct {
	Email    string
	Token    string
	FindText string
	FindTag  string
	NewTags  []string
	Debug    bool
}

AppTagConfig defines expected configuration structure for making Tag related operations

type ClientStructure

type ClientStructure interface {
	References() ItemReferences
	// update or insert item references
	UpsertReferences(input ItemReferences)
	// set references
	SetReferences(input ItemReferences)
	// return title
	GetTitle() string
	// set title
	SetTitle(input string)
	// get last update time
	GetUpdateTime() (time.Time, error)
	// set last update time
	SetUpdateTime(time.Time)
	// get appdata
	GetAppData() AppDataContent
	// set appdata
	SetAppData(data AppDataContent)
	// client structure methods for Note
	NoteClientStructure
	// client structure methods for Component
	ComponentClientStructure
}

ClientStructure defines behaviour of an Item's content entry

type ComponentClientStructure added in v0.0.2

type ComponentClientStructure interface {
	// return name
	GetName() string
	// return active status
	GetActive() bool
	// get item associations
	GetItemAssociations() []string
	// get item disassociations
	GetItemDisassociations() []string
	// associate items
	AssociateItems(items []string)
	// disassociate items
	DisassociateItems(items []string)
}

ClientStructure defines behaviour of a Component Item's content entry

type ComponentContent added in v0.0.2

type ComponentContent struct {
	LegacyURL          string         `json:"legacy_url"`
	HostedURL          string         `json:"hosted_url"`
	LocalURL           string         `json:"local_url"`
	ValidUntil         string         `json:"valid_until"`
	OfflineOnly        string         `json:"offlineOnly"`
	Name               string         `json:"name"`
	Area               string         `json:"area"`
	PackageInfo        interface{}    `json:"package_info"`
	Permissions        interface{}    `json:"permissions"`
	Active             interface{}    `json:"active"`
	AutoUpdateDisabled string         `json:"autoupdateDisabled"`
	ComponentData      interface{}    `json:"componentData"`
	DissociatedItemIds []string       `json:"disassociatedItemIds"`
	AssociatedItemIds  []string       `json:"associatedItemIds"`
	ItemReferences     ItemReferences `json:"references"`
	AppData            AppDataContent `json:"appData"`
}

func NewComponentContent added in v0.0.2

func NewComponentContent() *ComponentContent

NewTagContent returns an empty Tag content instance

func (*ComponentContent) AssociateItems added in v0.0.2

func (cc *ComponentContent) AssociateItems(newItems []string)

func (*ComponentContent) DisassociateItems added in v0.0.2

func (cc *ComponentContent) DisassociateItems(itemsToRemove []string)

func (*ComponentContent) GetActive added in v0.0.2

func (cc *ComponentContent) GetActive() bool

func (*ComponentContent) GetAppData added in v0.0.2

func (cc *ComponentContent) GetAppData() AppDataContent

func (*ComponentContent) GetItemAssociations added in v0.0.2

func (cc *ComponentContent) GetItemAssociations() []string

func (*ComponentContent) GetItemDisassociations added in v0.0.2

func (cc *ComponentContent) GetItemDisassociations() []string

func (*ComponentContent) GetName added in v0.0.2

func (cc *ComponentContent) GetName() string

func (*ComponentContent) GetText added in v0.0.2

func (cc *ComponentContent) GetText() string

func (*ComponentContent) GetTitle added in v0.0.2

func (cc *ComponentContent) GetTitle() string

func (*ComponentContent) GetUpdateTime added in v0.0.2

func (cc *ComponentContent) GetUpdateTime() (time.Time, error)

func (*ComponentContent) References added in v0.0.2

func (cc *ComponentContent) References() ItemReferences

func (*ComponentContent) SetAppData added in v0.0.2

func (cc *ComponentContent) SetAppData(data AppDataContent)

func (*ComponentContent) SetReferences added in v0.0.2

func (cc *ComponentContent) SetReferences(input ItemReferences)

func (*ComponentContent) SetText added in v0.0.2

func (cc *ComponentContent) SetText(input string)

func (*ComponentContent) SetTitle added in v0.0.2

func (cc *ComponentContent) SetTitle(title string)

func (*ComponentContent) SetUpdateTime added in v0.0.2

func (cc *ComponentContent) SetUpdateTime(uTime time.Time)

func (*ComponentContent) UpsertReferences added in v0.0.2

func (cc *ComponentContent) UpsertReferences(input ItemReferences)

type DecryptedItem

type DecryptedItem struct {
	UUID        string `json:"uuid"`
	Content     string `json:"content"`
	ContentType string `json:"content_type"`
	Deleted     bool   `json:"deleted"`
	CreatedAt   string `json:"created_at"`
	UpdatedAt   string `json:"updated_at"`
}

type DecryptedItems

type DecryptedItems []DecryptedItem

func (*DecryptedItems) Parse

func (di *DecryptedItems) Parse() (p Items, err error)

func (*DecryptedItems) RemoveDeleted

func (di *DecryptedItems) RemoveDeleted()

type EncryptedItem

type EncryptedItem struct {
	UUID        string `json:"uuid"`
	Content     string `json:"content"`
	ContentType string `json:"content_type"`
	EncItemKey  string `json:"enc_item_key"`
	Deleted     bool   `json:"deleted"`
	CreatedAt   string `json:"created_at"`
	UpdatedAt   string `json:"updated_at"`
}

type EncryptedItems

type EncryptedItems []EncryptedItem

func (*EncryptedItems) DeDupe

func (ei *EncryptedItems) DeDupe()

func (EncryptedItems) Decrypt

func (ei EncryptedItems) Decrypt(Mk, Ak string, debug bool) (o DecryptedItems, err error)

func (EncryptedItems) DecryptAndParse

func (ei EncryptedItems) DecryptAndParse(Mk, Ak string, debug bool) (o Items, err error)

func (*EncryptedItems) RemoveDeleted

func (ei *EncryptedItems) RemoveDeleted()

type Filter

type Filter struct {
	Type       string
	Key        string
	Comparison string
	Value      string
}

type GetItemsInput

type GetItemsInput struct {
	Session     Session
	SyncToken   string
	CursorToken string
	OutType     string
	BatchSize   int // number of items to retrieve
	PageSize    int // override default number of items to request with each sync call
	Debug       bool
}

GetItemsInput defines the input for retrieving items

type GetItemsOutput

type GetItemsOutput struct {
	Items      EncryptedItems // items new or modified since last sync
	SavedItems EncryptedItems // dirty items needing resolution
	Unsaved    EncryptedItems // items not saved during sync
	SyncToken  string
	Cursor     string
}

GetItemsOutput defines the output from retrieving items It contains slices of items based on their state see: https://standardfile.org/ for state details

func GetItems

func GetItems(input GetItemsInput) (output GetItemsOutput, err error)

GetItems retrieves items from the API using optional filters

type Item

type Item struct {
	UUID        string
	Content     ClientStructure
	ContentType string
	Deleted     bool
	CreatedAt   string
	UpdatedAt   string
	ContentSize int
}

Item describes a decrypted item

func NewComponent added in v0.0.2

func NewComponent() *Item

NewComponent returns an Item of type Component without content

func NewNote

func NewNote() *Item

NewNote returns an Item of type Note without content

func NewTag

func NewTag() *Item

NewTag returns an Item of type Tag without content

func (Item) Copy

func (item Item) Copy() *Item

func (Item) Equals

func (item Item) Equals(e Item) bool

type ItemFilters

type ItemFilters struct {
	MatchAny bool
	Filters  []Filter
}

type ItemReference

type ItemReference struct {
	// unique identifier of the item being referenced
	UUID string `json:"uuid"`
	// type of item being referenced
	ContentType string `json:"content_type"`
}

ItemReference defines a reference from one item to another

type ItemReferences

type ItemReferences []ItemReference

type Items

type Items []Item

func (*Items) DeDupe

func (i *Items) DeDupe()

func (*Items) Encrypt

func (i *Items) Encrypt(Mk, Ak string, debug bool) (e EncryptedItems, err error)

func (*Items) Filter

func (i *Items) Filter(f ItemFilters)

func (*Items) RemoveDeleted

func (i *Items) RemoveDeleted()

func (*Items) Validate

func (i *Items) Validate() error

type NoteClientStructure added in v0.0.2

type NoteClientStructure interface {
	// set text
	SetText(input string)
	// return text
	GetText() string
}

ClientStructure defines behaviour of a Component Item's content entry

type NoteContent

type NoteContent struct {
	Title          string         `json:"title"`
	Text           string         `json:"text"`
	ItemReferences ItemReferences `json:"references"`
	AppData        AppDataContent `json:"appData"`
}

func NewNoteContent

func NewNoteContent() *NoteContent

NewNoteContent returns an empty Note content instance

func (*NoteContent) AddItemAssociations added in v0.0.2

func (noteContent *NoteContent) AddItemAssociations() string

func (*NoteContent) AssociateItems added in v0.0.2

func (noteContent *NoteContent) AssociateItems(newItems []string)

func (NoteContent) Copy

func (noteContent NoteContent) Copy() *NoteContent

func (*NoteContent) DisassociateItems added in v0.0.2

func (noteContent *NoteContent) DisassociateItems(newItems []string)

func (*NoteContent) GetActive added in v0.0.2

func (noteContent *NoteContent) GetActive() bool

func (*NoteContent) GetAppData

func (noteContent *NoteContent) GetAppData() AppDataContent

func (*NoteContent) GetItemAssociations added in v0.0.2

func (noteContent *NoteContent) GetItemAssociations() []string

func (*NoteContent) GetItemDisassociations added in v0.0.2

func (noteContent *NoteContent) GetItemDisassociations() []string

func (*NoteContent) GetName added in v0.0.2

func (noteContent *NoteContent) GetName() string

func (*NoteContent) GetText

func (noteContent *NoteContent) GetText() string

func (*NoteContent) GetTitle

func (noteContent *NoteContent) GetTitle() string

func (*NoteContent) GetUpdateTime

func (noteContent *NoteContent) GetUpdateTime() (time.Time, error)

func (*NoteContent) References

func (noteContent *NoteContent) References() ItemReferences

func (*NoteContent) SetAppData

func (noteContent *NoteContent) SetAppData(data AppDataContent)

func (*NoteContent) SetReferences

func (noteContent *NoteContent) SetReferences(newRefs ItemReferences)

func (*NoteContent) SetText

func (noteContent *NoteContent) SetText(text string)

func (*NoteContent) SetTitle

func (noteContent *NoteContent) SetTitle(title string)

func (*NoteContent) SetUpdateTime

func (noteContent *NoteContent) SetUpdateTime(uTime time.Time)

func (*NoteContent) UpsertReferences

func (noteContent *NoteContent) UpsertReferences(newRefs ItemReferences)

type OrgStandardNotesSNDetail

type OrgStandardNotesSNDetail struct {
	ClientUpdatedAt string `json:"client_updated_at"`
}

type PutItemsInput

type PutItemsInput struct {
	Items     EncryptedItems
	SyncToken string
	Session   Session
	Debug     bool
}

PutItemsInput defines the input used to put items

type PutItemsOutput

type PutItemsOutput struct {
	ResponseBody syncResponse
}

PutItemsOutput defines the output from putting items

func PutItems

func PutItems(i PutItemsInput) (output PutItemsOutput, err error)

PutItems validates and then syncs items via API

type RegisterInput

type RegisterInput struct {
	Email     string
	Password  string
	APIServer string
	Debug     bool
}

func (RegisterInput) Register

func (input RegisterInput) Register() (token string, err error)

Register creates a new user token Params: email, password, pw_cost, pw_nonce, version

type Session

type Session struct {
	Token  string
	Mk     string
	Ak     string
	Server string
}

Session holds authentication and encryption parameters required to communicate with the API and process transferred data

func CliSignIn

func CliSignIn(email, password, apiServer string) (session Session, err error)

CLiSignIn takes the server URL and credentials and sends them to the API to get a response including an authentication token plus the keys required to encrypt and decrypt SN items

func GetSession

func GetSession(loadSession bool, sessionKey, server string) (session Session, email string, err error)

func GetSessionFromUser

func GetSessionFromUser(server string) (Session, string, error)

func ParseSessionString

func ParseSessionString(in string) (email string, session Session, err error)

func (*Session) Valid added in v0.0.2

func (s *Session) Valid() bool

type SignInInput

type SignInInput struct {
	Email     string
	TokenName string
	TokenVal  string
	Password  string
	APIServer string
	Debug     bool
}

type SignInOutput

type SignInOutput struct {
	Session   Session
	TokenName string
}

func SignIn

func SignIn(input SignInInput) (output SignInOutput, err error)

SignIn authenticates with the server using credentials and optional MFA in order to obtain the data required to interact with Standard Notes

type TagContent

type TagContent struct {
	Title          string         `json:"title"`
	ItemReferences ItemReferences `json:"references"`
	AppData        AppDataContent `json:"appData"`
}

func NewTagContent

func NewTagContent() *TagContent

NewTagContent returns an empty Tag content instance

func (*TagContent) AssociateItems added in v0.0.2

func (tagContent *TagContent) AssociateItems(newItems []string)

func (TagContent) Copy

func (tagContent TagContent) Copy() *TagContent

func (*TagContent) DisassociateItems added in v0.0.2

func (tagContent *TagContent) DisassociateItems(newItems []string)

func (TagContent) Equals

func (tagContent TagContent) Equals(e TagContent) bool

func (*TagContent) GetActive added in v0.0.2

func (tagContent *TagContent) GetActive() bool

func (*TagContent) GetAppData

func (tagContent *TagContent) GetAppData() AppDataContent

func (*TagContent) GetItemAssociations added in v0.0.2

func (tagContent *TagContent) GetItemAssociations() []string

func (*TagContent) GetItemDisassociations added in v0.0.2

func (tagContent *TagContent) GetItemDisassociations() []string

func (*TagContent) GetName added in v0.0.2

func (tagContent *TagContent) GetName() string

func (*TagContent) GetText

func (tagContent *TagContent) GetText() string

func (*TagContent) GetTitle

func (tagContent *TagContent) GetTitle() string

func (*TagContent) GetUpdateTime

func (tagContent *TagContent) GetUpdateTime() (time.Time, error)

func (*TagContent) References

func (tagContent *TagContent) References() ItemReferences

func (*TagContent) SetAppData

func (tagContent *TagContent) SetAppData(data AppDataContent)

func (*TagContent) SetReferences

func (tagContent *TagContent) SetReferences(newRefs ItemReferences)

func (*TagContent) SetText

func (tagContent *TagContent) SetText(text string)

func (*TagContent) SetTitle

func (tagContent *TagContent) SetTitle(title string)

func (*TagContent) SetUpdateTime

func (tagContent *TagContent) SetUpdateTime(uTime time.Time)

func (*TagContent) TextContains

func (tagContent *TagContent) TextContains(findString string, matchCase bool) bool

func (*TagContent) UpsertReferences

func (tagContent *TagContent) UpsertReferences(newRefs ItemReferences)

type UpdateItemRefsInput

type UpdateItemRefsInput struct {
	Items Items // Tags
	ToRef Items // Items To Reference
}

type UpdateItemRefsOutput

type UpdateItemRefsOutput struct {
	Items Items // Tags
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL