Skip to content

Commit 5e9e06a

Browse files
Support GATEWAY_API_URL env var
1 parent a36e8ed commit 5e9e06a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.rst

+12
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ the Threema gateway. Run the following command to see usage information:
6969
7070
$ threema-gateway --help
7171
72+
Setting a different API url
73+
---------------------------
74+
75+
The default MsgApi URL points to https://msgapi.threema.ch/.
76+
77+
If you are a Threema OnPrem customer or have another reason
78+
to use a different MsgApi endpoint, you may set an environment variable as follows:
79+
80+
.. code-block:: bash
81+
82+
$ GATEWAY_API_URL=https://onprem.myinstance.tld/msgapi threema-gateway ...
83+
7284
Examples
7385
********
7486

threema/gateway/bin/gateway_client.py

+9
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,21 @@
3636

3737
# Apply mock URL when starting CLI in debug mode
3838
_test_port = os.environ.get('THREEMA_TEST_API')
39+
_api_url = os.environ.get('GATEWAY_API_URL')
3940
if _test_port is not None:
41+
if _api_url is not None:
42+
raise RuntimeError('GATEWAY_API_URL cannot be set alongside THREEMA_TEST_API')
4043
_mock_url = 'http://{}:{}'.format('127.0.0.1', _test_port)
4144
Connection.urls = {key: value.replace('https://msgapi.threema.ch', _mock_url)
4245
for key, value in Connection.urls.items()}
4346
click.echo(('WARNING: Currently running in test mode!'
4447
'The Threema Gateway Server will not be contacted!'), err=True)
48+
else:
49+
if _api_url is not None:
50+
if not _api_url.startswith('https://'):
51+
raise RuntimeError('GATEWAY_API_URL must begin with "https://"')
52+
Connection.urls = {key: value.replace('https://msgapi.threema.ch', _api_url.rstrip('/'))
53+
for key, value in Connection.urls.items()}
4554

4655

4756
class _MockConnection(AioRunMixin):

0 commit comments

Comments
 (0)