|
68 | 68 | HeartBeatTimer, get_time_millis) |
69 | 69 | from .util_text import split_statements, construct_hostname, parse_account |
70 | 70 |
|
| 71 | +from snowflake.connector.network import APPLICATION_SNOWSQL |
| 72 | + |
71 | 73 |
|
72 | 74 | def DefaultConverterClass(): |
73 | 75 | if PY_ISSUE_23517 or IS_WINDOWS: |
@@ -599,6 +601,33 @@ def __set_error_attributes(self): |
599 | 601 | callable(getattr(errors, method))]: |
600 | 602 | setattr(self, m, getattr(errors, m)) |
601 | 603 |
|
| 604 | + @staticmethod |
| 605 | + def setup_ocsp_privatelink(app, hostname): |
| 606 | + if app == APPLICATION_SNOWSQL: |
| 607 | + ocsp_cache_server = u'http://ocsp{}/ocsp_response_cache.json'.format( |
| 608 | + hostname[hostname.index('.'):]) |
| 609 | + else: |
| 610 | + ocsp_cache_server = \ |
| 611 | + u'http://ocsp.{}/ocsp_response_cache.json'.format( |
| 612 | + hostname) |
| 613 | + if 'SF_OCSP_RESPONSE_CACHE_SERVER_URL' not in os.environ: |
| 614 | + os.environ[ |
| 615 | + 'SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server |
| 616 | + else: |
| 617 | + if not os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL']. \ |
| 618 | + startswith("http://"): |
| 619 | + ocsp_cache_server = "http://{0}/{1}".format( |
| 620 | + os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'], |
| 621 | + "ocsp_response_cache.json") |
| 622 | + else: |
| 623 | + ocsp_cache_server = "{0}/{1}".format( |
| 624 | + os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'], |
| 625 | + "ocsp_response_cache.json") |
| 626 | + |
| 627 | + os.environ[ |
| 628 | + 'SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server |
| 629 | + logger.debug(u"OCSP Cache Server is updated: %s", ocsp_cache_server) |
| 630 | + |
602 | 631 | def __open_connection(self): |
603 | 632 | u""" |
604 | 633 | Opens a new network connection |
@@ -627,26 +656,7 @@ def __open_connection(self): |
627 | 656 | os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL']) |
628 | 657 |
|
629 | 658 | if self.host.endswith(u".privatelink.snowflakecomputing.com"): |
630 | | - ocsp_cache_server = \ |
631 | | - u'http://ocsp.{}/ocsp_response_cache.json'.format( |
632 | | - self.host) |
633 | | - if 'SF_OCSP_RESPONSE_CACHE_SERVER_URL' not in os.environ: |
634 | | - os.environ[ |
635 | | - 'SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server |
636 | | - else: |
637 | | - if not os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL']. \ |
638 | | - startswith("http://"): |
639 | | - ocsp_cache_server = "http://{0}/{1}".format( |
640 | | - os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'], |
641 | | - "ocsp_response_cache.json") |
642 | | - else: |
643 | | - ocsp_cache_server = "{0}/{1}".format( |
644 | | - os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'], |
645 | | - "ocsp_response_cache.json") |
646 | | - |
647 | | - os.environ[ |
648 | | - 'SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server |
649 | | - logger.debug(u"OCSP Cache Server is updated: %s", ocsp_cache_server) |
| 659 | + SnowflakeConnection.setup_ocsp_privatelink(self.application, self.host) |
650 | 660 | else: |
651 | 661 | if 'SF_OCSP_RESPONSE_CACHE_SERVER_URL' in os.environ: |
652 | 662 | del os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'] |
|
0 commit comments