Skip to content

Commit

Permalink
Use certifi also for check-update and HTTP up/downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
lordi committed Apr 22, 2017
1 parent 15cebe5 commit ccdd41d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
18 changes: 13 additions & 5 deletions syncrypt/pipes/http.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
import asyncio
import logging
import sys
import os.path
import shutil
import aiohttp
import ssl
import sys

import aiofiles
import asyncio
import aiohttp
import certifi

from .base import Pipe, Sink, Source, Limit, BufferedFree
from .base import BufferedFree, Limit, Pipe, Sink, Source

logger = logging.getLogger(__name__)

class AiohttpClientSessionMixin():
def init_client(self, client, headers={}):
sslcontext = ssl.create_default_context(cafile=certifi.where())
conn = aiohttp.TCPConnector(ssl_context=sslcontext)
if client:
self.client_owned, self.client = False, client
else:
self.client_owned, self.client = True, aiohttp.ClientSession(headers=headers, skip_auto_headers=["Content-Type", "User-Agent"])
self.client_owned, self.client = True, aiohttp.ClientSession(
connector=conn,
headers=headers,
skip_auto_headers=["Content-Type", "User-Agent"]
)

@asyncio.coroutine
def close_client(self):
Expand Down
10 changes: 8 additions & 2 deletions syncrypt/utils/updates.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import asyncio
import ssl
from distutils.version import LooseVersion

import aiohttp
import certifi

import syncrypt
from distutils.version import LooseVersion

# The endpoint should return something along the lines of:
# { "darwin": "x.y.z", "linux": "x.y.z", "win": "x.y.z" }
CURRENT_ENDPOINT = 'https://alpha.syncrypt.space/releases/current.json'

@asyncio.coroutine
def retrieve_available_version(platform_id):
with aiohttp.ClientSession() as c:
sslcontext = ssl.create_default_context(cafile=certifi.where())
conn = aiohttp.TCPConnector(ssl_context=sslcontext)
with aiohttp.ClientSession(connector=conn) as c:
r = yield from c.get(CURRENT_ENDPOINT)
content = yield from r.json()
return content[platform_id]
Expand Down

0 comments on commit ccdd41d

Please sign in to comment.