Skip to content

Commit

Permalink
added sending of initialization logs to Nextcloud instance
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
  • Loading branch information
bigcat88 committed Oct 9, 2024
1 parent 664018a commit e52c501
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.0.1 - 2024-10-10]

### Added

- More logging for faster problem diagnosis. #12

### Fixed

- Warning "sudo: unable to resolve host" during container startup. #11
Expand Down
17 changes: 12 additions & 5 deletions ex_app/lib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ async def login_user(user_email: str, password: str) -> str:
json={"email": user_email, "password": password},
)
if r.status_code >= 400:
LOGGER.error("login_user(%s) error: %s", user_email, r.text)
raise RuntimeError(f"login_user: {r.text}")
return r.text

Expand All @@ -102,6 +103,7 @@ def login_user_sync(user_email: str, password: str) -> str:
json={"email": user_email, "password": password},
)
if r.status_code >= 400:
LOGGER.error("login_user(%s) error: %s", user_email, r.text)
raise RuntimeError(f"login_user: {r.text}")
return r.text

Expand Down Expand Up @@ -261,16 +263,17 @@ async def proxy_frontend_requests(request: Request, path: str):


def initialize_windmill() -> None:
while True: # Let's wait until Windmill opens the port.
with contextlib.suppress(httpx.ReadError, httpx.ConnectError, httpx.RemoteProtocolError):
r = httpx.get("http://127.0.0.1:8000/api/users/whoami")
if r.status_code in (401, 403):
break
if not USERS_STORAGE_PATH.exists():
while True: # Let's wait until Windmill opens the port.
with contextlib.suppress(httpx.ReadError, httpx.ConnectError, httpx.RemoteProtocolError):
r = httpx.get("http://127.0.0.1:8000/api/users/whoami")
if r.status_code in (401, 403):
break
r = httpx.post(
url="http://127.0.0.1:8000/api/auth/login", json={"email": "admin@windmill.dev", "password": "changeme"}
)
if r.status_code >= 400:
LOGGER.error("initialize_windmill: can not login with default credentials: %s", r.text)
raise RuntimeError(f"initialize_windmill: can not login with default credentials, {r.text}")
default_token = r.text
new_default_password = generate_random_string()
Expand All @@ -280,6 +283,7 @@ def initialize_windmill() -> None:
cookies={"token": default_token},
)
if r.status_code >= 400:
LOGGER.error("initialize_windmill: can not change default credentials password: %s", r.text)
raise RuntimeError(f"initialize_windmill: can not change default credentials password, {r.text}")
add_user_to_storage(DEFAULT_USER_EMAIL, new_default_password, default_token)
r = httpx.post(
Expand All @@ -288,6 +292,7 @@ def initialize_windmill() -> None:
cookies={"token": default_token},
)
if r.status_code >= 400:
LOGGER.error("initialize_windmill: can not create persistent token: %s", r.text)
raise RuntimeError(f"initialize_windmill: can not create persistent token, {r.text}")
default_token = r.text
add_user_to_storage(DEFAULT_USER_EMAIL, new_default_password, default_token)
Expand All @@ -297,13 +302,15 @@ def initialize_windmill() -> None:
cookies={"token": default_token},
)
if r.status_code >= 400:
LOGGER.error("initialize_windmill: can not create default workspace: %s", r.text)
raise RuntimeError(f"initialize_windmill: can not create default workspace, {r.text}")
r = httpx.post(
url="http://127.0.0.1:8000/api/w/nextcloud/workspaces/edit_auto_invite",
json={"operator": False, "invite_all": True, "auto_add": True},
cookies={"token": default_token},
)
if r.status_code >= 400:
LOGGER.error("initialize_windmill: can not create default workspace: %s", r.text)
raise RuntimeError(f"initialize_windmill: can not create default workspace, {r.text}")


Expand Down

0 comments on commit e52c501

Please sign in to comment.