]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: client: replace POST method with PUT in config cmd
authorAleš Mrázek <ales.mrazek@nic.cz>
Mon, 5 Dec 2022 21:59:53 +0000 (22:59 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Tue, 10 Jan 2023 18:57:14 +0000 (19:57 +0100)
manager/knot_resolver_manager/cli/cmd/config.py

index a454dd57498e6bddc127f75b1a41b4c3cdd46145..a4a08a6bf2c53d2727020d0a3d3d282c10f5f610 100644 (file)
@@ -23,9 +23,9 @@ class Formats(Enum):
     YAML = 1
 
 
-def operation_to_method(operation: Operations) -> Literal["POST", "GET", "DELETE"]:
+def operation_to_method(operation: Operations) -> Literal["PUT", "GET", "DELETE"]:
     if operation == Operations.SET:
-        return "POST"
+        return "PUT"
     elif operation == Operations.DELETE:
         return "DELETE"
 
@@ -181,9 +181,12 @@ class ConfigCommand(Command):
         response = request(method, url, reformat(new_config, Formats.JSON) if new_config else None)
         print(f"status: {response.status}")
 
-        if self.operation == Operations.GET and self.value_or_file and response.status == 200:
-            with open(self.value_or_file, "w") as f:
-                f.write(reformat(response.body, self.format))
-            print(f"saved to: {self.value_or_file}")
+        if self.operation == Operations.GET and response.status == 200:
+            if self.value_or_file:
+                with open(self.value_or_file, "w") as f:
+                    f.write(reformat(response.body, self.format))
+                print(f"saved to: {self.value_or_file}")
+            else:
+                print(reformat(response.body, self.format))
         else:
-            print(reformat(response.body, self.format))
+            print(response.body)