Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,23 @@ PRs more than welcome.
package main

import (
"context"
"fmt"

"github.com/browserutils/kooky"
_ "github.com/browserutils/kooky/browser/all" // register cookie store finders!
"github.com/browserutils/kooky/filter"
)

func main() {
// uses registered finders to find cookie store files in default locations
// applies the passed filters "Valid", "DomainHasSuffix()" and "Name()" in order to the cookies
cookiesSeq := kooky.TraverseCookies(context.TODO(), kooky.Valid, kooky.DomainHasSuffix(`google.com`), kooky.Name(`NID`)).OnlyCookies()
cookiesSeq := kooky.TraverseCookies(context.TODO(), filter.Valid, filter.DomainHasSuffix(`google.com`), filter.Name(`NID`)).OnlyCookies()

for cookie := range cookiesSeq {
fmt.Println(cookie.Domain, cookie.Name, cookie.Value)
}
}
}
```

### Chrome on macOS
Expand Down
3 changes: 2 additions & 1 deletion browser/chrome/chrome_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/browserutils/kooky"
"github.com/browserutils/kooky/filter"
"github.com/browserutils/kooky/internal/chrome"
"github.com/browserutils/kooky/internal/testutils"
)
Expand Down Expand Up @@ -33,7 +34,7 @@ func TestReadCookies(t *testing.T) {
name := "user"

ctx := context.Background()
cookies = kooky.FilterCookies(ctx, cookies, kooky.Domain(domain), kooky.Name(name)).Collect(ctx)
cookies = kooky.FilterCookies(ctx, cookies, filter.Domain(domain), filter.Name(name)).Collect(ctx)
if len(cookies) == 0 {
t.Fatalf("Found no cookies with domain=%q, name=%q", domain, name)
}
Expand Down
3 changes: 2 additions & 1 deletion browser/safari/safari_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/browserutils/kooky"
"github.com/browserutils/kooky/filter"
"github.com/browserutils/kooky/internal/testutils"
)

Expand All @@ -24,7 +25,7 @@ func TestReadCookies(t *testing.T) {

domain := "news.ycombinator.com"
name := "user"
cookies = kooky.FilterCookies(ctx, cookies, kooky.Domain(domain), kooky.Name(name)).Collect(ctx)
cookies = kooky.FilterCookies(ctx, cookies, filter.Domain(domain), filter.Name(name)).Collect(ctx)
if len(cookies) == 0 {
t.Fatalf("Found no cookies with domain=%q, name=%q", domain, name)
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/kooky/kooky.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/browserutils/kooky"
_ "github.com/browserutils/kooky/browser/all"
"github.com/browserutils/kooky/filter"

"github.com/spf13/pflag"
)
Expand All @@ -31,13 +32,13 @@ func main() {
// cookie filters
filters := []kooky.Filter{storeFilter(browser, profile, defaultProfile)}
if showExpired == nil || !*showExpired {
filters = append(filters, kooky.Valid)
filters = append(filters, filter.Valid)
}
if domain != nil && len(*domain) > 0 {
filters = append(filters, kooky.DomainContains(*domain))
filters = append(filters, filter.DomainContains(*domain))
}
if name != nil && len(*name) > 0 {
filters = append(filters, kooky.Name(*name))
filters = append(filters, filter.Name(*name))
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -126,7 +127,7 @@ func prFilePath(c *kooky.Cookie) string {
}

func storeFilter(browser, profile *string, defaultProfile *bool) kooky.Filter {
return kooky.FilterFunc(func(cookie *kooky.Cookie) bool {
return filter.FilterFunc(func(cookie *kooky.Cookie) bool {
if cookie == nil || cookie.Browser == nil {
return false
}
Expand Down
7 changes: 4 additions & 3 deletions cookiejar_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/browserutils/kooky"
_ "github.com/browserutils/kooky/browser/firefox"
"github.com/browserutils/kooky/filter"
)

func Example_cookieJar() {
Expand All @@ -26,13 +27,13 @@ func Example_cookieJar() {
}
// jar := s
// only store cookies relevant for the target website in the cookie jar
jar, _ := s.SubJar(ctx, kooky.FilterFunc(func(c *kooky.Cookie) bool {
return kooky.Domain(`github.com`).Filter(c) || kooky.Domain(`.github.com`).Filter(c)
jar, _ := s.SubJar(ctx, filter.FilterFunc(func(c *kooky.Cookie) bool {
return filter.Domain(`github.com`).Filter(c) || filter.Domain(`.github.com`).Filter(c)
}))

u, _ := url.Parse(`https://github.com/settings/profile`)

cookies := kooky.FilterCookies(ctx, jar.Cookies(u), kooky.Name(`logged_in`)).Collect(ctx)
cookies := kooky.FilterCookies(ctx, jar.Cookies(u), filter.Name(`logged_in`)).Collect(ctx)
if len(cookies) == 0 {
log.Fatal(`not logged in`)
}
Expand Down
3 changes: 2 additions & 1 deletion cookiestores_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/browserutils/kooky"
_ "github.com/browserutils/kooky/browser/all" // register cookiestore finders
"github.com/browserutils/kooky/filter"
)

func ExampleFindAllCookieStores() {
Expand All @@ -18,7 +19,7 @@ func ExampleFindAllCookieStores() {
defer store.Close()

var filters = []kooky.Filter{
kooky.Valid, // remove expired cookies
filter.Valid, // remove expired cookies
}

for cookie := range store.TraverseCookies(filters...).OnlyCookies() {
Expand Down
Loading