Bug fixes

parent aed22086
......@@ -519,7 +519,12 @@ class BaseDatastore:
if self._usr_journals.get(rpc.username) is None:
self._usr_journals[rpc.username] = UsrChangeJournal(self._data)
self._usr_journals[rpc.username].cl_new(rpc.op_input_args["name"])
try:
cl_name = rpc.op_input_args["name"]
except (TypeError, KeyError):
raise ValueError("This operation expects \"name\" input parameter")
self._usr_journals[rpc.username].cl_new(cl_name)
ret_data = {"status": "OK"}
elif rpc.op_name == "conf-list":
usr_journal = self._usr_journals.get(rpc.username)
......
......@@ -16,10 +16,6 @@
"name": "01",
"ip-address": "127.0.0.1",
"port": 53531
},
{
"name": "02",
"ip-address": "::1"
}
],
"filesystem-paths": {
......@@ -317,6 +313,13 @@
"comment": "Users can write other zones.",
"action": "permit"
},
{
"name": "permit-server-options-access",
"path": "/dns-server:dns-server/server-options",
"access-operations": "*",
"comment": "Users can write some server options.",
"action": "permit"
},
{
"name": "permit-zone-data-access",
"path": "/dns-zones:zone-data",
......
......@@ -8,6 +8,7 @@ from typing import Dict, List
from yangson.schema import NonexistentSchemaNode
from yangson.instance import NonexistentInstance, InstanceTypeError, DuplicateMember
from yangson.datatype import YangTypeError
from jetconf.knot_api import KnotError
from .config import CONFIG_GLOBAL, CONFIG_HTTP, NACM_ADMINS, API_ROOT_data, API_ROOT_STAGING_data, API_ROOT_ops
......@@ -113,6 +114,9 @@ def _get(prot: "H2Protocol", stream_id: int, ds: BaseDatastore, pth: str, yl_dat
except InstanceTypeError as e:
warn(epretty(e))
prot.send_empty(stream_id, "400", "Bad Request")
except KnotError as e:
error(epretty(e))
prot.send_empty(stream_id, "500", "Internal Server Error")
finally:
ds.unlock_data()
......@@ -244,6 +248,9 @@ def _get_staging(prot: "H2Protocol", stream_id: int, ds: BaseDatastore, pth: str
except NoHandlerError as e:
warn(epretty(e))
prot.send_empty(stream_id, "400", "Bad Request")
except KnotError as e:
error(epretty(e))
prot.send_empty(stream_id, "500", "Internal Server Error")
finally:
ds.unlock_data()
......@@ -315,16 +322,7 @@ def _post(prot: "H2Protocol", data: bytes, stream_id: int, ds: BaseDatastore, pt
except DuplicateMember as e:
warn(epretty(e))
prot.send_empty(stream_id, "409", "Conflict")
except InstanceTypeError as e:
warn(epretty(e))
prot.send_empty(stream_id, "400", "Bad Request")
except InstanceAlreadyPresent as e:
warn(epretty(e))
prot.send_empty(stream_id, "400", "Bad Request")
except NoHandlerError as e:
warn(epretty(e))
prot.send_empty(stream_id, "400", "Bad Request")
except ValueError as e:
except (InstanceTypeError, YangTypeError, InstanceAlreadyPresent, NoHandlerError, ValueError) as e:
warn(epretty(e))
prot.send_empty(stream_id, "400", "Bad Request")
finally:
......@@ -539,8 +537,11 @@ def create_api_op(ds: BaseDatastore):
except NoHandlerForOpError:
warn("Nonexistent handler for operation \"{}\"".format(op_name))
prot.send_empty(stream_id, "400", "Bad Request")
except KnotError as e:
except ValueError as e:
warn(epretty(e))
prot.send_empty(stream_id, "400", "Bad Request")
except KnotError as e:
error(epretty(e))
prot.send_empty(stream_id, "500", "Internal Server Error")
return api_op_closure
......@@ -97,7 +97,11 @@ class KnotConfig(KnotCtl):
if not self.socket_lock.acquire(blocking=True, timeout=5):
raise KnotApiError("Cannot acquire Knot socket lock")
self.connect(self.sock_path)
try:
self.connect(self.sock_path)
except Exception:
self.socket_lock.release()
raise KnotApiError("Cannot connect to Knot socket")
self.connected = True
def knot_disconnect(self):
......@@ -143,6 +147,8 @@ class KnotConfig(KnotCtl):
raise KnotApiError("Knot socket is closed")
if data is not None:
if isinstance(data, (int, bool)):
data = str(data).lower()
self.send_block("conf-set", section=section, identifier=identifier, item=item, zone=zone, data=data)
else:
self.send_block("conf-unset", section=section, identifier=identifier, item=item, zone=zone)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment