Allow insecure requests because registry.twtxt.org has an expired certificate
This commit is contained in:
parent
871b809cb0
commit
6271af4488
|
@ -6,15 +6,16 @@ from twtxt_registry_client import RegistryClient
|
|||
|
||||
@click.group(name='twtxt-registry')
|
||||
@click.argument('registry_url', required=True)
|
||||
@click.option('-k', '--insecure', is_flag=True)
|
||||
@click.pass_context
|
||||
def cli(ctx, registry_url):
|
||||
def cli(ctx, registry_url, insecure):
|
||||
scheme, netloc, path, query, fragment = urlsplit(registry_url)
|
||||
if not scheme:
|
||||
scheme = 'https'
|
||||
if not netloc and path:
|
||||
netloc, _, path = path.partition('/')
|
||||
registry_url = urlunsplit((scheme, netloc, path, query, fragment))
|
||||
ctx.obj = RegistryClient(registry_url)
|
||||
ctx.obj = RegistryClient(registry_url, insecure=insecure)
|
||||
|
||||
|
||||
@cli.command()
|
||||
|
|
|
@ -4,8 +4,10 @@ import requests
|
|||
|
||||
class RegistryClient(object):
|
||||
|
||||
def __init__(self, registry_url):
|
||||
def __init__(self, registry_url, insecure=False):
|
||||
self.registry_url = registry_url
|
||||
self.session = requests.Session()
|
||||
self.session.verify = not insecure
|
||||
|
||||
def request(self, method, endpoint, *, format='plain', **params):
|
||||
resp = method(
|
||||
|
@ -17,10 +19,10 @@ class RegistryClient(object):
|
|||
return resp
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
return self.request(requests.get, *args, **kwargs)
|
||||
return self.request(self.session.get, *args, **kwargs)
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
return self.request(requests.post, *args, **kwargs)
|
||||
return self.request(self.session.post, *args, **kwargs)
|
||||
|
||||
def register(self, nickname, url, *, format='plain'):
|
||||
return self.post(
|
||||
|
|
Reference in New Issue