code: def add_hba_entry(self, *, type='host', database, user, address=None,
                        auth_method, auth_options=None):
          
          status = self.get_status()
          if status == 'not-initialized':
              raise ClusterError(
                  'cannot modify HBA records: cluster is not initialized')
  
          if type not in {'local', 'host', 'hostssl', 'hostnossl'}:
              raise ValueError('invalid HBA record type: {!r}'.format(type))
  
          pg_hba = os.path.join(self._data_dir, 'pg_hba.conf')
  
          record = '{} {} {}'.format(type, database, user)
  
          if type != 'local':
              if address is None:
                  raise ValueError(
                      '{!r} entry requires a valid address'.format(type))
              else:
                  record += ' {}'.format(address)
  
          record += ' {}'.format(auth_method)
  
          if auth_options is not None:
              record += ' ' + ' '.join(
                  '{}={}'.format(k, v) for k, v in auth_options)
  
          try:
              with open(pg_hba, 'a') as f:
                  print(record, file=f)
          except IOError as e:
              raise ClusterError(
                  'cannot modify HBA records: {}'.format(e)) from e
docs: Add a record to pg_hba.conf.