diff --git a/cmd/Desktop-Bridge/main.go b/cmd/Desktop-Bridge/main.go index 1c8924fa..c0b6f9df 100644 --- a/cmd/Desktop-Bridge/main.go +++ b/cmd/Desktop-Bridge/main.go @@ -47,6 +47,7 @@ import ( "github.com/ProtonMail/proton-bridge/internal/api" "github.com/ProtonMail/proton-bridge/internal/bridge" + "github.com/ProtonMail/proton-bridge/internal/cookies" "github.com/ProtonMail/proton-bridge/internal/events" "github.com/ProtonMail/proton-bridge/internal/frontend" "github.com/ProtonMail/proton-bridge/internal/imap" @@ -56,7 +57,6 @@ import ( "github.com/ProtonMail/proton-bridge/pkg/args" "github.com/ProtonMail/proton-bridge/pkg/config" "github.com/ProtonMail/proton-bridge/pkg/constants" - "github.com/ProtonMail/proton-bridge/pkg/cookies" "github.com/ProtonMail/proton-bridge/pkg/listener" "github.com/ProtonMail/proton-bridge/pkg/pmapi" "github.com/ProtonMail/proton-bridge/pkg/updates" @@ -275,7 +275,7 @@ func run(context *cli.Context) (contextError error) { // nolint[funlen] cm.SetRoundTripper(cfg.GetRoundTripper(cm, eventListener)) // Cookies must be persisted across restarts. - jar, err := cookies.New(cookies.NewPersister(pref)) + jar, err := cookies.NewCookieJar(cookies.NewPersister(pref)) if err != nil { logrus.WithError(err).Warn("Could not create cookie jar") } else { diff --git a/pkg/cookies/jar.go b/internal/cookies/jar.go similarity index 84% rename from pkg/cookies/jar.go rename to internal/cookies/jar.go index da439c2c..029bda73 100644 --- a/pkg/cookies/jar.go +++ b/internal/cookies/jar.go @@ -15,6 +15,7 @@ // You should have received a copy of the GNU General Public License // along with ProtonMail Bridge. If not, see . +// Package cookies implements a persistent cookie jar which satisfies the http.CookieJar interface. package cookies import ( @@ -26,13 +27,15 @@ import ( "github.com/sirupsen/logrus" ) +// Jar implements http.CookieJar by wrapping the standard library's cookiejar.Jar. +// The jar uses a Persister to load cookies at startup and save cookies when set. type Jar struct { jar *cookiejar.Jar persister *Persister locker sync.Locker } -func New(persister *Persister) (*Jar, error) { +func NewCookieJar(persister *Persister) (*Jar, error) { jar, err := cookiejar.New(nil) if err != nil { return nil, err diff --git a/pkg/cookies/jar_test.go b/internal/cookies/jar_test.go similarity index 97% rename from pkg/cookies/jar_test.go rename to internal/cookies/jar_test.go index 87719e88..0006a496 100644 --- a/pkg/cookies/jar_test.go +++ b/internal/cookies/jar_test.go @@ -36,7 +36,7 @@ func TestJar(t *testing.T) { ts := getTestServer(t, testCookies...) defer ts.Close() - jar, err := New(NewPersister(make(testPersister))) + jar, err := NewCookieJar(NewPersister(make(testPersister))) require.NoError(t, err) client := &http.Client{Jar: jar} diff --git a/pkg/cookies/persister.go b/internal/cookies/persister.go similarity index 100% rename from pkg/cookies/persister.go rename to internal/cookies/persister.go