Skip to content

Commit

Permalink
Pulling changes from release/v2.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tmikuska committed Jun 26, 2024
1 parent d673541 commit 57095b3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion virl2_client/models/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def auth_flow(

def logout(self, clear_all_sessions=False) -> bool:
"""
Log out the user. Invalidates the current token.
Log out the user (invalidate the current token).
:param clear_all_sessions: Whether to clear all sessions.
:returns: Whether the logout succeeded.
Expand Down
3 changes: 1 addition & 2 deletions virl2_client/models/cl_pyats.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ def _load_pyats_testbed(self, testbed_yaml: str) -> Testbed:

def sync_testbed(self, username: str, password: str) -> None:
"""
Sync the testbed from the server.
This fetches the latest topology data from the server.
Sync the testbed (the latest topology data) from the server.
:param username: The username to be inserted into the testbed data.
:param password: The password to be inserted into the testbed data.
Expand Down
14 changes: 7 additions & 7 deletions virl2_client/models/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from typing import TYPE_CHECKING

from ..utils import UNCHANGED, get_url_from_template
from ..utils import get_url_from_template

if TYPE_CHECKING:
import httpx
Expand Down Expand Up @@ -109,9 +109,9 @@ def update_group(
self,
group_id: str,
name: str | None = None,
description: str | None = UNCHANGED,
members: list[str] | None = UNCHANGED,
labs: list[dict[str, str]] | None = UNCHANGED,
description: str | None = None,
members: list[str] | None = None,
labs: list[dict[str, str]] | None = None,
) -> dict:
"""
Update a group.
Expand All @@ -126,11 +126,11 @@ def update_group(
data: dict[str, str | list] = {}
if name is not None:
data["name"] = name
if description is not UNCHANGED:
if description is not None:
data["description"] = description
if members is not UNCHANGED:
if members is not None:
data["members"] = members
if labs is not UNCHANGED:
if labs is not None:
data["labs"] = labs
url = self._url_for("group", group_id=group_id)
return self._session.patch(url, json=data).json()
Expand Down
39 changes: 30 additions & 9 deletions virl2_client/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from typing import TYPE_CHECKING, Any

from ..utils import UNCHANGED, get_url_from_template
from ..utils import UNCHANGED, _Sentinel, get_url_from_template

if TYPE_CHECKING:
import httpx
Expand All @@ -49,7 +49,7 @@ def _url_for(self, endpoint, **kwargs):
"""
return get_url_from_template(endpoint, self._URL_TEMPLATES, kwargs)

def users(self) -> list[str]:
def users(self) -> list[dict]:
"""
Get the list of available users.
Expand Down Expand Up @@ -83,9 +83,12 @@ def create_user(
pwd: str,
fullname: str = "",
description: str = "",
email: str = "",
admin: bool = False,
groups: list[str] | None = None,
resource_pool: str | None = None,
opt_in: bool | None = None,
tour_version: str = "",
) -> dict:
"""
Create a new user.
Expand All @@ -94,58 +97,76 @@ def create_user(
:param pwd: Desired password.
:param fullname: Full name.
:param description: Description.
:param email: Email address.
:param admin: Whether to create an admin user.
:param groups: List of groups to which the user should be added.
:param resource_pool: Resource pool to which the user should be added.
:param opt_in: Whether the user has seen the initial contact dialog.
:param tour_version: The version of the Workbench tour the user has completed.
:returns: User object.
"""
data = {
"username": username,
"password": pwd,
"fullname": fullname,
"description": description,
"email": email,
"admin": admin,
"groups": groups or [],
"resource_pool": resource_pool,
"opt_in": opt_in,
"tour_version": tour_version,
}
url = self._url_for("users")
return self._session.post(url, json=data).json()

def update_user(
self,
user_id: str,
fullname: str | None = UNCHANGED,
description: str | None = UNCHANGED,
groups: list[str] | None = UNCHANGED,
fullname: str | None = None,
description: str | None = None,
email: str | None = None,
groups: list[str] | None = None,
admin: bool | None = None,
password_dict: dict[str, str] | None = None,
resource_pool: str | None = UNCHANGED,
resource_pool: str | None | _Sentinel = UNCHANGED,
opt_in: bool | None | _Sentinel = UNCHANGED,
tour_version: str | None = None,
) -> dict:
"""
Update an existing user.
:param user_id: User UUID4.
:param fullname: Full name.
:param description: Description.
:param email: Email address.
:param admin: Whether to create an admin user.
:param groups: List of groups to which the user should be added.
:param password_dict: Dictionary containing old and new passwords.
:param resource_pool: Resource pool to which the user should be added.
:param opt_in: Whether the user has seen the initial contact dialog.
:param tour_version: The version of the Workbench tour the user has completed.
:returns: User object.
"""
data: dict[str, Any] = {}
if fullname is not UNCHANGED:
if fullname is not None:
data["fullname"] = fullname
if description is not UNCHANGED:
if description is not None:
data["description"] = description
if email is not None:
data["email"] = email
if admin is not None:
data["admin"] = admin
if groups is not UNCHANGED:
if groups is not None:
data["groups"] = groups
if password_dict is not None:
data["password"] = password_dict
if resource_pool is not UNCHANGED:
data["resource_pool"] = resource_pool
if opt_in is not UNCHANGED:
data["opt_in"] = opt_in
if tour_version is not None:
data["tour_version"] = tour_version

url = self._url_for("user", user_id=user_id)
return self._session.patch(url, json=data).json()
Expand Down
2 changes: 1 addition & 1 deletion virl2_client/virl2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def import_lab(
self,
topology: str,
title: str | None = None,
offline=None,
offline: bool | None = None,
virl_1x: bool = False,
) -> Lab:
"""
Expand Down

0 comments on commit 57095b3

Please sign in to comment.