-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AIRFLOW-5751] add get_uri method to Connection (#6426)
(cherry-picked from 53422a8)
- Loading branch information
Showing
2 changed files
with
303 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
|
||
import json | ||
from builtins import bytes | ||
from urllib.parse import urlparse, unquote, parse_qsl | ||
from urllib.parse import parse_qsl, quote, unquote, urlencode, urlparse | ||
|
||
from sqlalchemy import Column, Integer, String, Boolean | ||
from sqlalchemy.ext.declarative import declared_attr | ||
|
@@ -145,6 +145,41 @@ def parse_from_uri(self, uri): | |
if uri_parts.query: | ||
self.extra = json.dumps(dict(parse_qsl(uri_parts.query, keep_blank_values=True))) | ||
|
||
def get_uri(self): | ||
uri = '{}://'.format(str(self.conn_type).lower().replace('_', '-')) | ||
|
||
authority_block = '' | ||
if self.login is not None: | ||
authority_block += quote(self.login, safe='') | ||
|
||
if self.password is not None: | ||
authority_block += ':' + quote(self.password, safe='') | ||
|
||
if authority_block > '': | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ashb
Member
|
||
authority_block += '@' | ||
|
||
uri += authority_block | ||
|
||
host_block = '' | ||
if self.host: | ||
host_block += quote(self.host, safe='') | ||
|
||
if self.port: | ||
if host_block > '': | ||
host_block += ':{}'.format(self.port) | ||
else: | ||
host_block += '@:{}'.format(self.port) | ||
|
||
if self.schema: | ||
host_block += '/{}'.format(quote(self.schema, safe='')) | ||
|
||
uri += host_block | ||
|
||
if self.extra_dejson: | ||
uri += '?{}'.format(urlencode(self.extra_dejson)) | ||
|
||
return uri | ||
|
||
def get_password(self): | ||
if self._password and self.is_encrypted: | ||
fernet = get_fernet() | ||
|
Oops, something went wrong.
Is there a reason you used
>
here, and not!=
, or justif authority_block:
?