Read now works, and terraform directory contains example code
This commit is contained in:
1 parent
ef498e4a72
commit
a6f1019175
43 files changed
+4341
-38
No files matched your search
+5
-3
@@ -4,11 +4,13 @@ from urllib.parse import urlparse
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
BASE_URL = os.environ.get("SWITCH_URL", "http://192.168.2.10")
|
||||
from config import SWITCH_BASE_URL, SWITCH_PASSWORD
|
||||
|
||||
BASE_URL = SWITCH_BASE_URL
|
||||
SESSION_COOKIE_FILE = os.path.join(os.path.dirname(__file__), ".session_cookie")
|
||||
|
||||
|
||||
def login(password: str = "", session: requests.Session | None = None) -> requests.Session:
|
||||
def login(password: str = SWITCH_PASSWORD, session: requests.Session | None = None) -> requests.Session:
|
||||
"""POST to /hp_login.html, return a Session with the SID cookie set."""
|
||||
session = session or requests.Session()
|
||||
# A bare POST occasionally comes back without setting SID (the switch
|
||||
@@ -58,7 +60,7 @@ def _cache_session(session: requests.Session) -> None:
|
||||
f.write(sid)
|
||||
|
||||
|
||||
def get_session(password: str = "", force_login: bool = False) -> requests.Session:
|
||||
def get_session(password: str = SWITCH_PASSWORD, force_login: bool = False) -> requests.Session:
|
||||
"""Reuse a still-valid cached session if one exists, otherwise log in.
|
||||
|
||||
The switch only allows one active web session at a time and briefly
|
||||
|
||||
Reference in new issue
Block a user