Skip to content

Commit 8017be7

Browse files
sfc-gh-stakedaankit-bhatnagar167
authored andcommitted
SNOW-81828: Modified account name parsing so that global URLs will work properly without having to specify the 'host' field
1 parent 8dbd620 commit 8017be7

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

connection.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
from .time_util import (
6767
DEFAULT_MASTER_VALIDITY_IN_SECONDS,
6868
HeartBeatTimer, get_time_millis)
69-
from .util_text import split_statements, construct_hostname
69+
from .util_text import split_statements, construct_hostname, parse_account
7070

7171

7272
def DefaultConverterClass():
@@ -779,8 +779,7 @@ def __config(self, **kwargs):
779779
u'errno': ER_NO_ACCOUNT_NAME
780780
})
781781
if u'.' in self._account:
782-
# remove region subdomain
783-
self._account = self._account[0:self._account.find(u'.')]
782+
self._account = parse_account(self._account)
784783

785784
if self.ocsp_fail_open:
786785
logger.info(

test/test_unit_construct_hostname.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ def test_construct_hostname_basic():
2828

2929
assert construct_hostname(None, 'account1.eu-central-1') == \
3030
'account1.eu-central-1.snowflakecomputing.com'
31+
32+
assert construct_hostname(None, 'account1-jkabfvdjisoa778wqfgeruishafeuw89q.global') == \
33+
'account1-jkabfvdjisoa778wqfgeruishafeuw89q.global.snowflakecomputing.com'

test/test_unit_parse_account.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2012-2019 Snowflake Computing Inc. All right reserved.
5+
#
6+
7+
from snowflake.connector.util_text import parse_account
8+
9+
10+
def test_parse_account_basic():
11+
assert parse_account('account1') == 'account1'
12+
13+
assert parse_account('account1.eu-central-1') == 'account1'
14+
15+
assert parse_account('account1-jkabfvdjisoa778wqfgeruishafeuw89q.global') == 'account1'

util_text.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,20 @@ def construct_hostname(region, account):
200200
else:
201201
host = u'{0}.snowflakecomputing.com'.format(account)
202202
return host
203+
204+
205+
def parse_account(account):
206+
url_parts = account.split(u'.')
207+
# if this condition is true, then we have some extra
208+
# stuff in the account field.
209+
if len(url_parts) > 1:
210+
if url_parts[1] == u'global':
211+
# remove external ID from account
212+
parsed_account = url_parts[0][0:url_parts[0].rfind(u'-')]
213+
else:
214+
# remove region subdomain
215+
parsed_account = url_parts[0]
216+
else:
217+
parsed_account = account
218+
219+
return parsed_account

0 commit comments

Comments
 (0)