mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 23:49:15 +01:00
webdav/sharepoint: renew cookies after 12hrs
This commit is contained in:
parent
c7aa6b587b
commit
22ac80e83a
32
backend/webdav/odrvcookie/renew.go
Normal file
32
backend/webdav/odrvcookie/renew.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package odrvcookie
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/ncw/rclone/lib/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CookieRenew holds information for the renew
|
||||||
|
type CookieRenew struct {
|
||||||
|
srv *rest.Client
|
||||||
|
timer *time.Ticker
|
||||||
|
renewFn func()
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRenew returns and starts a CookieRenew
|
||||||
|
func NewRenew(interval time.Duration, renewFn func()) *CookieRenew {
|
||||||
|
renew := CookieRenew{
|
||||||
|
timer: time.NewTicker(interval),
|
||||||
|
renewFn: renewFn,
|
||||||
|
}
|
||||||
|
go renew.Renew()
|
||||||
|
return &renew
|
||||||
|
}
|
||||||
|
|
||||||
|
// Renew calls the renewFn for every tick
|
||||||
|
func (c *CookieRenew) Renew() {
|
||||||
|
for {
|
||||||
|
<-c.timer.C // wait for tick
|
||||||
|
c.renewFn()
|
||||||
|
}
|
||||||
|
}
|
@ -372,6 +372,17 @@ func (f *Fs) setQuirks(vendor string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
odrvcookie.NewRenew(12*time.Hour, func() {
|
||||||
|
spCookies, err := spCk.Cookies()
|
||||||
|
if err != nil {
|
||||||
|
fs.Errorf("could not renew cookies: %s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
f.srv.SetCookie(&spCookies.FedAuth, &spCookies.RtFa)
|
||||||
|
fs.Debugf(spCookies, "successfully renewed sharepoint cookies")
|
||||||
|
})
|
||||||
|
|
||||||
f.srv.SetCookie(&spCookies.FedAuth, &spCookies.RtFa)
|
f.srv.SetCookie(&spCookies.FedAuth, &spCookies.RtFa)
|
||||||
|
|
||||||
// sharepoint, unlike the other vendors, only lists files if the depth header is set to 0
|
// sharepoint, unlike the other vendors, only lists files if the depth header is set to 0
|
||||||
|
Loading…
Reference in New Issue
Block a user