Use CSFR Token in Syncthing module

Fixes #390
This commit is contained in:
Stefan Tatschner 2016-05-24 10:16:01 +02:00
parent 6859eb5a10
commit f059184411

View File

@ -40,11 +40,16 @@ class Syncthing(IntervalModule):
) )
def st_get(self, endpoint): def st_get(self, endpoint):
response = requests.get( # TODO: Maybe we can share a session across multiple GETs.
urljoin(self.url, endpoint), with requests.Session() as s:
verify=self.verify_ssl, r = s.get(self.url)
) csrf_name, csfr_value = r.headers['Set-Cookie'].split('=')
return json.loads(response.text) s.headers.update({'X-' + csrf_name: csfr_value})
r = s.get(
urljoin(self.url, endpoint),
verify=self.verify_ssl,
)
return json.loads(r.text)
def st_post(self, endpoint, data=None): def st_post(self, endpoint, data=None):
headers = {'X-API-KEY': self.apikey} headers = {'X-API-KEY': self.apikey}