MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / _read_password_from_pgpass

Function _read_password_from_pgpass

asyncpg/connect_utils.py:143–177  ·  view source on GitHub ↗

Parse the pgpass file and return the matching password. :return: Password string, if found, ``None`` otherwise.

(
        *, passfile: typing.Optional[pathlib.Path],
        hosts: typing.List[str],
        ports: typing.List[int],
        database: str,
        user: str)

Source from the content-addressed store, hash-verified

141
142
143def _read_password_from_pgpass(
144 *, passfile: typing.Optional[pathlib.Path],
145 hosts: typing.List[str],
146 ports: typing.List[int],
147 database: str,
148 user: str):
149 """Parse the pgpass file and return the matching password.
150
151 :return:
152 Password string, if found, ``None`` otherwise.
153 """
154
155 passtab = _read_password_file(passfile)
156 if not passtab:
157 return None
158
159 for host, port in zip(hosts, ports):
160 if host.startswith('/'):
161 # Unix sockets get normalized into 'localhost'
162 host = 'localhost'
163
164 for phost, pport, pdatabase, puser, ppassword in passtab:
165 if phost != '*' and phost != host:
166 continue
167 if pport != '*' and pport != str(port):
168 continue
169 if pdatabase != '*' and pdatabase != database:
170 continue
171 if puser != '*' and puser != user:
172 continue
173
174 # Found a match.
175 return ppassword
176
177 return None
178
179
180def _validate_port_spec(hosts, port):

Callers 1

Calls 1

_read_password_fileFunction · 0.85

Tested by

no test coverage detected