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 9133698 commit ca0dad5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
42 changes: 29 additions & 13 deletions scaleway/scaleway/instance/v1/custom_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,36 +78,52 @@ 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,
):
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],
)
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
3 changes: 3 additions & 0 deletions scaleway/scaleway/instance/v1/custom_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class GetServerUserDataRequest:
Key defines the user data key to get
"""


@dataclass
class GetAllServerUserDataRequest:
zone: Optional[Zone]
Expand All @@ -27,10 +28,12 @@ class GetAllServerUserDataRequest:

server_id: str


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


@dataclass
class SetAllServerUserDataRequest:
zone: Optional[Zone]
Expand Down

0 comments on commit ca0dad5

Please sign in to comment.