Skip to content

🎨 Allow project node patch of service key #6085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class NodeCreate(InputSchemaWithoutCamelCase):


class NodePatch(InputSchemaWithoutCamelCase):
service_key: ServiceKey = FieldNotRequired(alias="key")
service_version: ServiceVersion = FieldNotRequired(alias="version")
label: str = FieldNotRequired()
inputs: InputsDict = FieldNotRequired()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ async def create_node(request: web.Request) -> web.Response:
return envelope_json_response(data, status_cls=web.HTTPCreated)


# NOTE: Careful, this endpoint is actually "get_node_state," and it doesn't return a Node resource.
@routes.get(f"/{VTAG}/projects/{{project_id}}/nodes/{{node_id}}", name="get_node")
@login_required
@permission_required("project.node.read")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ async def remove_project_node(
async with self.engine.acquire() as conn:
await project_nodes_repo.delete(conn, node_id=node_id)

# NOTE: Not all Node data are here yet; they are in the workbench of a Project, waiting to be moved here.
async def get_project_node(
self, project_id: ProjectID, node_id: NodeID
) -> ProjectNode:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
)
from servicelib.logging_utils import get_log_record_extra, log_context
from servicelib.rabbitmq import RemoteMethodNotRegisteredError, RPCServerError
from servicelib.rabbitmq.rpc_interfaces.catalog import services as catalog_rpc
from servicelib.rabbitmq.rpc_interfaces.clusters_keeper.ec2_instances import (
get_instance_type_details,
)
Expand Down Expand Up @@ -916,7 +917,27 @@ async def patch_project_node(
if not _user_project_access_rights.write:
raise ProjectInvalidRightsError(user_id=user_id, project_uuid=project_id)

# 2. Patch the project node
# 2. If patching service key or version make sure it's valid
if _node_patch_exclude_unset.get("key") or _node_patch_exclude_unset.get("version"):
_project, _ = await db.get_project(
user_id=user_id, project_uuid=f"{project_id}"
)
_project_node_data = _project["workbench"][f"{node_id}"]

_service_key = _node_patch_exclude_unset.get("key", _project_node_data["key"])
_service_version = _node_patch_exclude_unset.get(
"version", _project_node_data["version"]
)
rabbitmq_rpc_client = get_rabbitmq_rpc_client(app)
await catalog_rpc.get_service(
rabbitmq_rpc_client,
product_name=product_name,
user_id=user_id,
service_key=_service_key,
service_version=_service_version,
)

# 3. Patch the project node
updated_project, _ = await db.update_project_node_data(
user_id=user_id,
project_uuid=project_id,
Expand All @@ -925,7 +946,7 @@ async def patch_project_node(
new_node_data=_node_patch_exclude_unset,
)

# 3. Notify project node update
# 4. Notify project node update
await notify_project_node_update(app, updated_project, node_id, errors=None)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ def mock_project_uses_available_services(mocker: MockerFixture):
)


@pytest.fixture
def mock_catalog_rpc_get_service(mocker: MockerFixture):
mocker.patch(
"simcore_service_webserver.projects.projects_api.catalog_rpc.get_service",
spec=True,
return_value=True,
)


@pytest.mark.parametrize(
"user_role,expected",
[
Expand Down Expand Up @@ -77,8 +86,9 @@ async def test_patch_project_node(
logged_user: UserInfoDict,
user_project: ProjectDict,
expected: HTTPStatus,
mock_catalog_api_get_services_for_user_in_product,
mock_project_uses_available_services,
mock_catalog_api_get_services_for_user_in_product: None,
mock_project_uses_available_services: None,
mock_catalog_rpc_get_service: None,
):
node_id = next(iter(user_project["workbench"]))
assert client.app
Expand Down
Loading