Skip to content

Commit

Permalink
fix ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Laure-di committed Jan 14, 2025
1 parent b75d23e commit 7ad8012
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
43 changes: 30 additions & 13 deletions scaleway/scaleway/instance/v1/custom_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Optional, Dict

from mypy.semanal import names_modified_in_lvalue
from requests import Response

from scaleway_core.bridge import Zone as ScwZone
Expand Down Expand Up @@ -78,36 +77,54 @@ def set_server_user_data(
self._throw_on_error(res)
return res

def get_all_server_user_data(self, server_id: str, zone: Optional[ScwZone] = None) -> GetAllServerUserDataResponse:
def get_all_server_user_data(
self, server_id: str, zone: Optional[ScwZone] = None
) -> GetAllServerUserDataResponse:
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_server_id = validate_path_param("server_id", server_id)

all_user_data_res = InstanceUtilsV1API.list_server_user_data(self, server_id=param_server_id, zone=param_zone)
all_user_data_res = InstanceUtilsV1API.list_server_user_data(
self, server_id=param_server_id, zone=param_zone
)

user_data: Dict[str,bytes] = {}
user_data: Dict[str, bytes] = {}
for key in all_user_data_res.user_data:
value = InstanceUtilsV1API.get_server_user_data(self, server_id=param_server_id, key=key)
value = InstanceUtilsV1API.get_server_user_data(
self, server_id=param_server_id, key=key
)
print("value: ", value)
user_data[key] = value.content

res = GetAllServerUserDataResponse(user_data=user_data)

return res

def set_all_server_user_data(self, server_id: str, user_data: Dict[str, bytes], zone: Optional[ScwZone] = None):
def set_all_server_user_data(
self,
server_id: str,
user_data: Dict[str, bytes],
zone: Optional[ScwZone] = None,
) -> Optional[None]:
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_server_id = validate_path_param("server_id", server_id)

all_user_data_res = InstanceUtilsV1API.list_server_user_data(self, server_id=param_server_id, zone=param_zone)
all_user_data_res = InstanceUtilsV1API.list_server_user_data(
self, server_id=param_server_id, zone=param_zone
)
for key in all_user_data_res.user_data:
if user_data.get(key) is not None:
continue
InstanceUtilsV1API.delete_server_user_data(self, server_id=param_server_id, key=key)
InstanceUtilsV1API.delete_server_user_data(
self, server_id=param_server_id, key=key
)

for key in user_data:
InstanceUtilsV1API.set_server_user_data(self, server_id=param_server_id, zone=param_zone, key=key, content=user_data[key])




InstanceUtilsV1API.set_server_user_data(
self,
server_id=param_server_id,
zone=param_zone,
key=key,
content=user_data[key],
)

return None
7 changes: 5 additions & 2 deletions scaleway/scaleway/instance/v1/custom_marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ def marshal_GetServerUserDataRequest(

return output

def marshal_ListServerUserDataRequest(request: GetAllServerUserDataRequest, defaults: ProfileDefaults) -> Dict[str, Any]:

def marshal_ListServerUserDataRequest(
request: GetAllServerUserDataRequest, defaults: ProfileDefaults
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.server_id is not None:
output["server_id"] = request.server_id
if request.zone is not None:
output["zone"] = request.zone

return output
return output
11 changes: 7 additions & 4 deletions scaleway/scaleway/instance/v1/custom_types.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from dataclasses import dataclass
from typing import Optional, Dict

from scaleway_core.bridge import Zone
from scaleway_core.bridge import Zone as ScwZone


@dataclass
class GetServerUserDataRequest:
zone: Optional[Zone]
zone: Optional[ScwZone]
"""
Zone of the user data to get
"""
Expand All @@ -18,22 +18,25 @@ class GetServerUserDataRequest:
Key defines the user data key to get
"""


@dataclass
class GetAllServerUserDataRequest:
zone: Optional[Zone]
zone: Optional[ScwZone]
"""
Zone of the user data to get
"""

server_id: str


@dataclass
class GetAllServerUserDataResponse:
user_data: Dict[str, bytes]


@dataclass
class SetAllServerUserDataRequest:
zone: Optional[Zone]
zone: Optional[ScwZone]
"""
Zone of the user data to set
"""
Expand Down

0 comments on commit 7ad8012

Please sign in to comment.