mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-18 08:06:59 +00:00
Cookies for Import-Export
This commit is contained in:
@ -3,7 +3,13 @@
|
|||||||
Changelog [format](http://keepachangelog.com/en/1.0.0/)
|
Changelog [format](http://keepachangelog.com/en/1.0.0/)
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
* GODT-682 Persistent anonymous API cookies for Import-Export.
|
||||||
|
|
||||||
|
### Changed
|
||||||
* GODT-511 User agent format changed.
|
* GODT-511 User agent format changed.
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
* GODT-519 Unused AUTH scope parsing methods
|
* GODT-519 Unused AUTH scope parsing methods
|
||||||
|
|
||||||
|
|||||||
@ -21,9 +21,11 @@ import (
|
|||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
|
|
||||||
"github.com/ProtonMail/proton-bridge/internal/cmd"
|
"github.com/ProtonMail/proton-bridge/internal/cmd"
|
||||||
|
"github.com/ProtonMail/proton-bridge/internal/cookies"
|
||||||
"github.com/ProtonMail/proton-bridge/internal/events"
|
"github.com/ProtonMail/proton-bridge/internal/events"
|
||||||
"github.com/ProtonMail/proton-bridge/internal/frontend"
|
"github.com/ProtonMail/proton-bridge/internal/frontend"
|
||||||
"github.com/ProtonMail/proton-bridge/internal/importexport"
|
"github.com/ProtonMail/proton-bridge/internal/importexport"
|
||||||
|
"github.com/ProtonMail/proton-bridge/internal/preferences"
|
||||||
"github.com/ProtonMail/proton-bridge/internal/updates"
|
"github.com/ProtonMail/proton-bridge/internal/updates"
|
||||||
"github.com/ProtonMail/proton-bridge/internal/users/credentials"
|
"github.com/ProtonMail/proton-bridge/internal/users/credentials"
|
||||||
"github.com/ProtonMail/proton-bridge/pkg/config"
|
"github.com/ProtonMail/proton-bridge/pkg/config"
|
||||||
@ -36,6 +38,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// cacheVersion is used for cache files such as lock, or preferences.
|
||||||
|
// Different number will drop old files and create new ones.
|
||||||
|
cacheVersion = "c11"
|
||||||
|
|
||||||
appName = "importExport"
|
appName = "importExport"
|
||||||
appNameDash = "import-export-app"
|
appNameDash = "import-export-app"
|
||||||
)
|
)
|
||||||
@ -58,7 +64,7 @@ func main() {
|
|||||||
// IMPORTANT: ***Read the comments before CHANGING the order ***
|
// IMPORTANT: ***Read the comments before CHANGING the order ***
|
||||||
func run(context *cli.Context) (contextError error) { // nolint[funlen]
|
func run(context *cli.Context) (contextError error) { // nolint[funlen]
|
||||||
// We need to have config instance to setup a logs, panic handler, etc ...
|
// We need to have config instance to setup a logs, panic handler, etc ...
|
||||||
cfg := config.New(appName, constants.Version, constants.Revision, "")
|
cfg := config.New(appName, constants.Version, constants.Revision, cacheVersion)
|
||||||
|
|
||||||
// We want to know about any problem. Our PanicHandler calls sentry which is
|
// We want to know about any problem. Our PanicHandler calls sentry which is
|
||||||
// not dependent on anything else. If that fails, it tries to create crash
|
// not dependent on anything else. If that fails, it tries to create crash
|
||||||
@ -132,6 +138,16 @@ func run(context *cli.Context) (contextError error) { // nolint[funlen]
|
|||||||
// implementation depending on whether build flag pmapi_prod is used or not.
|
// implementation depending on whether build flag pmapi_prod is used or not.
|
||||||
cm.SetRoundTripper(cfg.GetRoundTripper(cm, eventListener))
|
cm.SetRoundTripper(cfg.GetRoundTripper(cm, eventListener))
|
||||||
|
|
||||||
|
pref := preferences.New(cfg)
|
||||||
|
|
||||||
|
// Cookies must be persisted across restarts.
|
||||||
|
jar, err := cookies.NewCookieJar(pref)
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithError(err).Warn("Could not create cookie jar")
|
||||||
|
} else {
|
||||||
|
cm.SetCookieJar(jar)
|
||||||
|
}
|
||||||
|
|
||||||
importexportInstance := importexport.New(cfg, panicHandler, eventListener, cm, credentialsStore)
|
importexportInstance := importexport.New(cfg, panicHandler, eventListener, cm, credentialsStore)
|
||||||
|
|
||||||
// Decide about frontend mode before initializing rest of import-export.
|
// Decide about frontend mode before initializing rest of import-export.
|
||||||
|
|||||||
@ -266,6 +266,9 @@ func (c *client) doBuffered(req *http.Request, bodyBuffer []byte, retryUnauthori
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cookies are returned only after request was sent.
|
||||||
|
c.log.Tracef("REQCOOKIES '%v'", req.Cookies())
|
||||||
|
|
||||||
resDate := res.Header.Get("Date")
|
resDate := res.Header.Get("Date")
|
||||||
if resDate != "" {
|
if resDate != "" {
|
||||||
if serverTime, err := http.ParseTime(resDate); err == nil {
|
if serverTime, err := http.ParseTime(resDate); err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user