Skip to content

Commit

Permalink
Add support for custom Gateway API URL endpoints in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
threema-eduard authored and threema-lenny committed Aug 20, 2024
1 parent 36e7879 commit 631a609
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ the Threema gateway. Run the following command to see usage information:
$ threema-gateway --help
Gateway API Endpoint
--------------------

The default Gateway API Endpoint URL used is https://msgapi.threema.ch/.

If you are a Threema OnPrem customer or have another reason to use a different
Gateway API Endpoint, you may override the URL as follows:

.. code-block:: bash
$ export GATEWAY_API_URL=https://onprem.myinstance.tld/msgapi
Any following calls to ``threema-gateway`` will then use the supplied Gateway
API Endpoint URL.

Examples
********

Expand Down
12 changes: 12 additions & 0 deletions threema/gateway/bin/gateway_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,24 @@

# Apply mock URL when starting CLI in debug mode
_test_port = os.environ.get('THREEMA_TEST_API')
_api_url = os.environ.get('GATEWAY_API_URL')
if _test_port is not None:
if _api_url is not None:
raise RuntimeError('GATEWAY_API_URL cannot be set alongside THREEMA_TEST_API')
_mock_url = 'http://{}:{}'.format('127.0.0.1', _test_port)
Connection.urls = {key: value.replace('https://msgapi.threema.ch', _mock_url)
for key, value in Connection.urls.items()}
click.echo(('WARNING: Currently running in test mode!'
'The Threema Gateway Server will not be contacted!'), err=True)
else:
if _api_url is not None:
if not _api_url.startswith('https://'):
raise RuntimeError('GATEWAY_API_URL must begin with "https://"')
Connection.urls = {key: value.replace(
'https://msgapi.threema.ch',
_api_url.rstrip('/')
)
for key, value in Connection.urls.items()}


class _MockConnection(AioRunMixin):
Expand Down

0 comments on commit 631a609

Please sign in to comment.