browserutils / kooky

Go code to read cookies from browser cookie stores.
MIT License
210 stars 41 forks source link

add filtering #21

Closed srlehn closed 4 years ago

srlehn commented 4 years ago

preparation for a signature change of the ReadCookie() funcs:

// currently:
func ReadSafariCookies(filename string, domainFilter string, nameFilter string, expireAfter time.Time) ([]*kooky.Cookie, error)
func ReadChromeCookies(filename string, domainFilter string, nameFilter string, expireAfter time.Time) ([]*kooky.Cookie, error)
func ReadFirefoxCookies(filename string) ([]*kooky.Cookie, error)

// planned:
ReadCookies(filename string, ...Filter) ([]*Cookie, error)

// example usage:
cookies, err := ReadCookies(filename) // default without filters
cookies, err := ReadCookies(filename, Domain(domainFilter), Name(nameFilter), ExpiresAfter(expireAfter)) // with filters
var ownFilter Filter = func(*Cookie) bool { /* do something */ }
cookies, err := ReadCookies(filename, ValueContais(valuePart), ownFilter, Debug, HTTPOnly) // with filters

change of the Read...() functions remains.


https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

zellyn commented 4 years ago

I understand adding arbitrary filters, but how does this remove the need for telling it which browser you want to read from?

srlehn commented 4 years ago

ah.... it doesn't. I had the separation from #14 in mind. then they are in firefox/chrome/... packages.

And i have something planned with a global search after locating the cookie dbs. I have some location code lying around which I have to prepare a bit. I was thinking a bit about the interface and structure but don't have much yet.

Here are some things I would like to add later:

type CookiesFile struct {
    Browser, Profile, Path string
}

type Reader interface {
    Read(*CookiesFile, ...Filter) ([]*Cookie, error)
}

type Searcher interface {
    Search(browser, profile string) ([]*CookiesFile, error)
}
zellyn commented 4 years ago

Ah, ok. Makes sense.