Skip to content

Commit 430aea9

Browse files
committed
Added parameter to config to store certs
1 parent b6f0034 commit 430aea9

3 files changed

Lines changed: 34 additions & 9 deletions

File tree

maproulette/api/configuration.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
"""This module contains the basic configuration object that is used to communicate with the MapRoulette API."""
22

3-
DEFAULT_URL = 'maproulette.org'
3+
DEFAULT_HOSTNAME = 'maproulette.org'
44
DEFAULT_PROTOCOL = 'https'
55
DEFAULT_API_VERSION = '/api/v2'
66

77

88
class Configuration:
99
"""Class for storing the configuration of the MapRoulette server"""
10-
def __init__(self, url=DEFAULT_URL, protocol=DEFAULT_PROTOCOL, api_version=DEFAULT_API_VERSION, api_key=None):
11-
self.url = f"{protocol}://{url}{api_version}"
12-
self.base_url = f"{protocol}://{url}"
10+
def __init__(self, hostname=DEFAULT_HOSTNAME, protocol=DEFAULT_PROTOCOL, api_version=DEFAULT_API_VERSION,
11+
api_key=None, certs=None, verify=True):
12+
"""Create a new configuration object to connect to the MapRoulette server.
13+
14+
:param hostname: Optional parameter to specify the hostname of the MapRoulette instance being addressed. Do not
15+
include the protocol (https, http). Default value is 'maproulette.org'.
16+
:type hostname: str
17+
:param protocol: Optional parameter to specify the protocol to use for the connection to the MapRoulette
18+
instance being addressed such as https or http. Default value is 'https'.
19+
:type protocol: str
20+
:param api_version: Optional parameter to specify the API version to use. The default is '/api/v2'.
21+
:type api_version: str
22+
:param api_key: Optional parameter to pass the user-specific API key. This key is necessary for some actions.
23+
:type api_key: str
24+
:param certs: Optional parameter to pass the client-side certificate and key if necessary to make connection
25+
with the MapRoulette instance being addressed.
26+
:type certs: tuple
27+
:param verify: Optional parameter to specify whether to verify SSL certificates for HTTPS requests. Default is
28+
True.
29+
:type verify: bool
30+
"""
31+
self.api_url = f"{protocol}://{hostname}{api_version}"
32+
self.base_url = f"{protocol}://{hostname}"
33+
self.protocol = protocol
1334
self.headers = dict()
1435
self.headers['apikey'] = api_key
15-
self.protocol = protocol
36+
self.certs = certs
37+
self.verify = verify

maproulette/api/maproulette_server.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
class MapRouletteServer:
1111
"""Class that holds the basic requests that can be made to the MapRoulette API."""
1212
def __init__(self, configuration):
13-
self.url = configuration.url
13+
self.url = configuration.api_url
1414
self.base_url = configuration.base_url
1515
self.headers = configuration.headers
16+
self.certs = configuration.certs
17+
self.verify = configuration.verify
1618
if self.__check_health():
1719
self.session = requests.Session()
1820
self.session.headers = self.headers
19-
self.session.verify = False
21+
self.session.verify = self.verify
22+
self.session.cert = self.certs
2023

2124
def __check_health(self, retries=3, delay=5):
2225
"""Checks health of connection to host by pinging the URL set in the configuration
@@ -30,7 +33,8 @@ def __check_health(self, retries=3, delay=5):
3033
response = requests.get(
3134
self.base_url + '/ping',
3235
headers=self.headers,
33-
verify=False
36+
verify=self.verify,
37+
cert=self.certs
3438
)
3539
if not response.ok:
3640
print(f"Unsuccessful connection. Retrying in {str(delay)} seconds")

maproulette/api/project.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""This module contains the methods that the user will use directly to interact with MapRoulette projects"""
22

3-
import json
43
from maproulette.api.maproulette_server import MapRouletteServer
54
from maproulette.models.project import ProjectModel
65

0 commit comments

Comments
 (0)