MCPcopy Index your code
hub / github.com/MagicStack/asyncpg / _read_password_from_pgpass

Function _read_password_from_pgpass

asyncpg/connect_utils.py:137–171  ·  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

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

Callers 1

Calls 1

_read_password_fileFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…