Skip to content

Commit 6ff6b68

Browse files
threema-eduardthreema-lenny
authored andcommitted
Add support for custom Gateway API URL endpoints in CLI
1 parent 22172ac commit 6ff6b68

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CHANGELOG.rst

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Changelog
1111
- Add an optional parameter to the CLI for `send-simple` and `send-e2e` to allow
1212
passing the text as an argument instead from stdin.
1313
- Make the random padding spec compliant
14+
- Add an optional environment variable `GATEWAY_API_URL` to override the Gateway
15+
API Endpoint URL
1416

1517
`7.0.1`_ (2023-02-21)
1618
---------------------

README.rst

+15
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ the Threema gateway. Run the following command to see usage information:
6767
6868
$ threema-gateway --help
6969
70+
Gateway API Endpoint
71+
--------------------
72+
73+
The default Gateway API Endpoint URL used is https://msgapi.threema.ch/.
74+
75+
If you are a Threema OnPrem customer or have another reason to use a different
76+
Gateway API Endpoint, you may override the URL as follows:
77+
78+
.. code-block:: bash
79+
80+
$ export GATEWAY_API_URL=https://onprem.myinstance.tld/msgapi
81+
82+
Any following calls to ``threema-gateway`` will then use the supplied Gateway
83+
API Endpoint URL.
84+
7085
Examples
7186
********
7287

threema/gateway/bin/gateway_client.py

+12
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,24 @@
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(
53+
'https://msgapi.threema.ch',
54+
_api_url.rstrip('/')
55+
)
56+
for key, value in Connection.urls.items()}
4557

4658

4759
class _MockConnection(AioRunMixin):

0 commit comments

Comments
 (0)