Skip to content

Commit b04697e

Browse files
committed
fixup! Add endpoint option
1 parent d9706dd commit b04697e

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

ably/realtime/realtime.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ def __init__(self, key: Optional[str] = None, loop: Optional[asyncio.AbstractEve
4848
You can set this to false and explicitly connect to Ably using the
4949
connect() method. The default is true.
5050
**kwargs: client options
51+
endpoint: str
52+
Endpoint specifies either a routing policy name or fully qualified domain name to connect to Ably.
5153
realtime_host: str
54+
Deprecated: this property is deprecated and will be removed in a future version.
5255
Enables a non-default Ably host to be specified for realtime connections.
5356
For development environments only. The default value is realtime.ably.io.
5457
environment: str
58+
Deprecated: this property is deprecated and will be removed in a future version.
5559
Enables a custom environment to be used with the Ably service. Defaults to `production`
5660
realtime_request_timeout: float
5761
Timeout (in milliseconds) for the wait of acknowledgement for operations performed via a realtime

ably/rest/rest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ def __init__(self, key: Optional[str] = None, token: Optional[str] = None,
3333
3434
**Optional Parameters**
3535
- `client_id`: Undocumented
36-
- `rest_host`: The host to connect to. Defaults to rest.ably.io
37-
- `environment`: The environment to use. Defaults to 'production'
36+
- `endpoint`: Endpoint specifies either a routing policy name or fully qualified domain name to connect to Ably.
37+
- `rest_host`: Deprecated: this property is deprecated and will be removed in a future version. The host to connect to. Defaults to rest.ably.io
38+
- `environment`: Deprecated: this property is deprecated and will be removed in a future version. The environment to use. Defaults to 'production'
3839
- `port`: The port to connect to. Defaults to 80
3940
- `tls_port`: The tls_port to connect to. Defaults to 443
4041
- `tls`: Specifies whether the client should use TLS. Defaults

ably/transport/defaults.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ def get_hostname(endpoint):
5151
if endpoint.startswith("nonprod:"):
5252
return endpoint[len("nonprod:"):] + ".realtime.ably-nonprod.net"
5353

54-
if endpoint == "main":
55-
return "main.realtime.ably.net"
56-
5754
return endpoint + ".realtime.ably.net"
5855

5956
@staticmethod
6057
def get_fallback_hosts(endpoint="main"):
58+
if "." in endpoint or "::" in endpoint or "localhost" in endpoint:
59+
return []
60+
6161
if endpoint.startswith("nonprod:"):
6262
root = endpoint.replace("nonprod:", "")
6363
return [

ably/types/options.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,13 @@ def __init__(self, client_id=None, log_level=0, tls=True, rest_host=None, realti
4343
if environment is not None and realtime_host is not None:
4444
raise ValueError('specify realtime_host or environment, not both')
4545

46-
if environment is not None and endpoint is not None:
47-
raise ValueError('specify endpoint or environment, not both')
46+
if endpoint is not None and (environment is not None or rest_host is not None or realtime_host is not None):
47+
raise ValueError('endpoint is incompatible with any of environment, rest_host or realtime_host')
4848

4949
if idempotent_rest_publishing is None:
5050
from ably import api_version
5151
idempotent_rest_publishing = api_version >= '1.2'
5252

53-
if environment == "production":
54-
endpoint = Defaults.endpoint
55-
5653
if environment is not None and endpoint is None:
5754
endpoint = environment
5855

@@ -287,7 +284,7 @@ def __get_rest_hosts(self):
287284
# Fallback hosts
288285
fallback_hosts = self.fallback_hosts
289286
if fallback_hosts is None:
290-
if self.rest_host:
287+
if self.rest_host is not None:
291288
fallback_hosts = []
292289
else:
293290
fallback_hosts = Defaults.get_fallback_hosts(self.endpoint)

test/ably/rest/restinit_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def test_rest_host_and_environment(self):
7373
ably = AblyRest(token='foo', rest_host="some.other.host")
7474
assert "some.other.host" == ably.options.rest_host, "Unexpected host mismatch"
7575

76-
# environment: production
77-
ably = AblyRest(token='foo', environment="production")
76+
# environment: main
77+
ably = AblyRest(token='foo', environment="main")
7878
host = ably.options.get_rest_host()
7979
assert "main.realtime.ably.net" == host, "Unexpected host mismatch %s" % host
8080

0 commit comments

Comments
 (0)