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)
| 135 | |
| 136 | |
| 137 | def _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 | |
| 174 | def _validate_port_spec(hosts, port): |
no test coverage detected
searching dependent graphs…