[docs]defiter_log_lines(self,url:str,timestamps:bool=True)->Iterator[str]:response=self.session.get(url,stream=True)lines=response.iter_lines()forlineinlines:structured_log=json.loads(line)timestamp,log=structured_log["date"],structured_log["log"]log_date=(datetime.fromisoformat(timestamp[:-1]+"+00:00").replace(tzinfo=timezone.utc).astimezone()# Convert to users timezone)iftimestamps:log=f"{log_date}{log}"yieldlog
[docs]defcheck_credentials(self):"""Determine if valid credentials are already set for the user."""_=self.session.get("/credentials")
[docs]defset_credentials(self):ifself.auth.client_idandself.auth.client_secret:self.session.post("/credentials",json={"client_id":self.auth.client_id,"client_secret":self.auth.client_secret,},)else:# We only have a JWT and no client id/secret, so validate# that there are already valid credentials set for the user.# This situation will generally only arise when used from# some backend process.self.check_credentials()