Commit 9f415fb7 authored by Aleš Mrázek's avatar Aleš Mrázek
Browse files

.well-known/host-meta corrections

parent 0f7e4cec
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>
<Link rel='restconf' href='/restconf'/>
</XRD>
......@@ -34,7 +34,6 @@ HandlerConditionT = Callable[[str, str], bool] # Function(method, path) -> bool
epretty = ErrorHelpers.epretty
debug_httph = LogHelpers.create_module_dbg_logger(__name__)
CTYPE_PLAIN = "text/plain"
CTYPE_YANG_JSON = "application/yang.api+json"
CTYPE_XRD_XML = "application/xrd+xml"
......@@ -415,21 +414,6 @@ class HttpHandlersImpl:
return http_resp
def get_root_resource_(self, headers: OrderedDict, data: Optional[str], client_cert: SSLCertT) -> HttpResponse:
username = ClientHelpers.get_username(client_cert, headers)
url_path = headers[":path"].split("?")[0]
url_path_safe = "".join(filter(lambda c: c.isalpha() or c in "/-_.", url_path)).replace("..", "").strip("/")
file_path = os.path.join(config.CFG.http["DOC_ROOT"], url_path_safe)
response = b"<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n" \
b" <Link rel='restconf' href='" + config.CFG.http["API_ROOT"].encode() + b"'/>\n" \
b"</XRD>\n"
info("[{}] Root Resource Discovery {} of type \"{}\"".format(username, file_path, CTYPE_XRD_XML))
http_resp = HttpResponse(HttpStatus.Ok, response, CTYPE_XRD_XML)
return http_resp
def get_file(self, headers: OrderedDict, data: Optional[str], client_cert: SSLCertT) -> HttpResponse:
# Ordinary file on filesystem
username = ClientHelpers.get_username(client_cert, headers)
......@@ -449,8 +433,8 @@ class HttpHandlersImpl:
fd = open(file_path, 'rb')
response = fd.read()
fd.close()
except FileNotFoundError:
warn("[{}] Cannot open requested file \"{}\"".format(username, file_path))
except FileNotFoundError as fnf:
warn("[{}] Cannot open requested file \"{}\", {}".format(username, file_path, fnf))
http_resp = HttpResponse.empty(HttpStatus.NotFound)
else:
info("[{}] Serving ordinary file {} of type \"{}\"".format(username, file_path, ctype))
......@@ -704,64 +688,64 @@ class HttpHandlersImpl:
return http_resp
def _delete(self, pth: str, username: str) -> HttpResponse:
url_split = pth.split("?")
url_path = url_split[0]
url_split = pth.split("?")
url_path = url_split[0]
rpc1 = RpcInfo()
rpc1.username = username
rpc1.path = url_path.rstrip("/")
rpc1 = RpcInfo()
rpc1.username = username
rpc1.path = url_path.rstrip("/")
# Skip NACM check for privileged users
if username in config.CFG.nacm["ALLOWED_USERS"]:
rpc1.skip_nacm_check = True
# Skip NACM check for privileged users
if username in config.CFG.nacm["ALLOWED_USERS"]:
rpc1.skip_nacm_check = True
try:
self.ds.lock_data(username)
try:
self.ds.lock_data(username)
try:
staging_root = self.ds.get_data_root_staging(rpc1.username)
new_root = self.ds.delete_node_rpc(staging_root, rpc1)
self.ds.add_to_journal_rpc(ChangeType.DELETE, rpc1, None, *new_root)
http_resp = HttpResponse.empty(HttpStatus.NoContent, status_in_body=False)
except NacmForbiddenError as e:
http_resp = HttpResponse.error(
HttpStatus.Forbidden,
RestconfErrType.Protocol,
ERRTAG_ACCDENIED,
exception=e
)
except (NonexistentSchemaNode, NonexistentInstance) as e:
http_resp = HttpResponse.error(
HttpStatus.NotFound,
RestconfErrType.Protocol,
ERRTAG_INVVALUE,
exception=e
)
except NoHandlerError as e:
http_resp = HttpResponse.error(
HttpStatus.BadRequest,
RestconfErrType.Protocol,
ERRTAG_OPNOTSUPPORTED,
exception=e
)
except (InstanceValueError, StagingDataException, YangsonException) as e:
http_resp = HttpResponse.error(
HttpStatus.BadRequest,
RestconfErrType.Protocol,
ERRTAG_INVVALUE,
exception=e
)
except DataLockError as e:
try:
staging_root = self.ds.get_data_root_staging(rpc1.username)
new_root = self.ds.delete_node_rpc(staging_root, rpc1)
self.ds.add_to_journal_rpc(ChangeType.DELETE, rpc1, None, *new_root)
http_resp = HttpResponse.empty(HttpStatus.NoContent, status_in_body=False)
except NacmForbiddenError as e:
http_resp = HttpResponse.error(
HttpStatus.Conflict,
HttpStatus.Forbidden,
RestconfErrType.Protocol,
ERRTAG_LOCKDENIED,
ERRTAG_ACCDENIED,
exception=e
)
finally:
self.ds.unlock_data()
except (NonexistentSchemaNode, NonexistentInstance) as e:
http_resp = HttpResponse.error(
HttpStatus.NotFound,
RestconfErrType.Protocol,
ERRTAG_INVVALUE,
exception=e
)
except NoHandlerError as e:
http_resp = HttpResponse.error(
HttpStatus.BadRequest,
RestconfErrType.Protocol,
ERRTAG_OPNOTSUPPORTED,
exception=e
)
except (InstanceValueError, StagingDataException, YangsonException) as e:
http_resp = HttpResponse.error(
HttpStatus.BadRequest,
RestconfErrType.Protocol,
ERRTAG_INVVALUE,
exception=e
)
except DataLockError as e:
http_resp = HttpResponse.error(
HttpStatus.Conflict,
RestconfErrType.Protocol,
ERRTAG_LOCKDENIED,
exception=e
)
finally:
self.ds.unlock_data()
return http_resp
return http_resp
def delete_api(self, headers: OrderedDict, data: Optional[str], client_cert: SSLCertT) -> HttpResponse:
username = ClientHelpers.get_username(client_cert, headers)
......
......@@ -138,18 +138,18 @@ class Jetconf:
self.rest_srv = RestServer()
self.rest_srv.register_api_handlers(datastore)
# Create XRD file '.well-known/host-meta'
# Create XRD '.well-known/host-meta' file
host_meta = "<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n" \
" <Link rel='restconf' href='" + self.config.http["API_ROOT"] + "'/>\n" \
"\t<Link rel='restconf' href='" + self.config.http["API_ROOT"] + "'/>\n" \
"</XRD>\n"
hm_path = self.config.http["DOC_ROOT"] + "/.well-known/host-meta"
try:
if not os.path.exists(os.path.dirname(hm_path)):
os.makedirs(os.path.dirname(hm_path))
hm = open(hm_path, "w")
hm.write(host_meta)
hm.close()
hmf = open(hm_path, "w")
hmf.write(host_meta)
hmf.close()
except (OSError, IOError) as e:
raise JetconfInitError("Creating XRD 'host-meta' file failed, reason: {}".format(ErrorHelpers.epretty(e)))
......
......@@ -26,7 +26,6 @@ from .http_handlers import (
ERRTAG_REQLARGE
)
debug_srv = LogHelpers.create_module_dbg_logger(__name__)
......
Supports Markdown
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