Skip to content

Commit 485ce5b

Browse files
committed
fixup! Add endpoint option
1 parent a6b8bd5 commit 485ce5b

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

ably/realtime/realtime.py

+4
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

+8-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ 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
37+
fully qualified domain name to connect to Ably.
38+
- `rest_host`: Deprecated: this property is deprecated and will
39+
be removed in a future version. The host to connect to.
40+
Defaults to rest.ably.io
41+
- `environment`: Deprecated: this property is deprecated and
42+
will be removed in a future version. The environment to use.
43+
Defaults to 'production'
3844
- `port`: The port to connect to. Defaults to 80
3945
- `tls_port`: The tls_port to connect to. Defaults to 443
4046
- `tls`: Specifies whether the client should use TLS. Defaults

ably/transport/defaults.py

+3-3
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

+4-6
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,14 @@ 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:
47+
if environment is not None or rest_host is not None or realtime_host is not None:
48+
raise ValueError('endpoint is incompatible with any of environment, rest_host or realtime_host')
4849

4950
if idempotent_rest_publishing is None:
5051
from ably import api_version
5152
idempotent_rest_publishing = api_version >= '1.2'
5253

53-
if environment == "production":
54-
endpoint = Defaults.endpoint
55-
5654
if environment is not None and endpoint is None:
5755
endpoint = environment
5856

@@ -287,7 +285,7 @@ def __get_rest_hosts(self):
287285
# Fallback hosts
288286
fallback_hosts = self.fallback_hosts
289287
if fallback_hosts is None:
290-
if self.rest_host:
288+
if self.rest_host is not None:
291289
fallback_hosts = []
292290
else:
293291
fallback_hosts = Defaults.get_fallback_hosts(self.endpoint)

test/ably/rest/restinit_test.py

+2-2
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)