-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #459 from DSD-DBS/fix-t4c-user-deletion
Use routes for session termination
- Loading branch information
Showing
9 changed files
with
76 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import logging | ||
|
||
from requests.exceptions import RequestException | ||
from sqlalchemy.orm import Session | ||
|
||
from capellacollab.sessions.models import DatabaseSession | ||
from capellacollab.sessions.operators.k8s import KubernetesOperator | ||
from capellacollab.sessions.schema import WorkspaceType | ||
from capellacollab.settings.modelsources.t4c.repositories.crud import ( | ||
get_user_t4c_repositories, | ||
) | ||
from capellacollab.settings.modelsources.t4c.repositories.interface import ( | ||
remove_user_from_repository, | ||
) | ||
|
||
from . import crud | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def terminate_session( | ||
db_session: Session, session: DatabaseSession, operator: KubernetesOperator | ||
): | ||
if ( | ||
session.tool.name == "Capella" | ||
and session.type == WorkspaceType.PERSISTENT | ||
): | ||
revoke_session_tokens(db_session, session) | ||
|
||
crud.delete_session(db_session, session) | ||
operator.kill_session(session.id) | ||
|
||
|
||
def revoke_session_tokens(db_session: Session, session: DatabaseSession): | ||
for repository in get_user_t4c_repositories( | ||
db_session, session.tool, session.version, session.owner | ||
): | ||
try: | ||
remove_user_from_repository( | ||
repository.instance, | ||
repository.name, | ||
username=session.owner.name, | ||
) | ||
except RequestException: | ||
log.exception( | ||
"Could not delete user from repository '%s' of instance '%s'. Please delete the user manually.", | ||
exc_info=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters