Loading src/nbi/service/_tools/HttpStatusCodes.py +12 −9 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ HTTP_ACCEPTED = 202 HTTP_NOCONTENT = 204 HTTP_BADREQUEST = 400 HTTP_NOTFOUND = 404 HTTP_NOT_ACCEPTABLE = 406 HTTP_CONFLICT = 409 HTTP_UNSUPMEDIATYPE = 415 HTTP_SERVERERROR = 500 HTTP_NOT_IMPLEMENTED = 501 HTTP_GATEWAYTIMEOUT = 504 src/nbi/service/well_known_meta/Resources.py +46 −14 Original line number Diff line number Diff line Loading @@ -12,14 +12,39 @@ # See the License for the specific language governing permissions and # limitations under the License. # RESTCONF .well-known endpoint (RFC 8040) from flask import jsonify from flask import abort, jsonify, make_response, request from flask_restful import Resource from xml.sax.saxutils import escape import xml.etree.ElementTree as ET from .._tools.HttpStatusCodes import HTTP_NOT_ACCEPTABLE XRD_NS = 'http://docs.oasis-open.org/ns/xri/xrd-1.0' ET.register_namespace('', XRD_NS) RESTCONF_PREFIX = '/restconf' class WellKnownHostMeta(Resource): def get(self): response = { best = request.accept_mimetypes.best_match([ 'application/xrd+xml', 'application/json', ], default='application/xrd+xml') if best == 'application/xrd+xml': xrd = ET.Element('{{{:s}}}XRD'.format(str(XRD_NS))) ET.SubElement(xrd, '{{{:s}}}Link'.format(str(XRD_NS)), attrib={ 'rel': 'restconf', 'href': RESTCONF_PREFIX }) xml_string = ET.tostring(xrd, encoding='utf-8', xml_declaration=True).decode() response = make_response(str(xml_string)) response.status_code = 200 response.content_type = best return response elif best == 'application/json': response = jsonify({ 'restconf': { 'capabilities': [ 'urn:ietf:params:restconf:capability:defaults:1.0', Loading @@ -30,6 +55,13 @@ class WellKnownHostMeta(Resource): 'application/yang-data+json', 'application/yang-data+xml' ] } } return jsonify(response) }, 'links': [ {'rel': 'restconf', 'href': RESTCONF_PREFIX} ] }) response.status_code = 200 response.content_type = best return response else: abort(HTTP_NOT_ACCEPTABLE) Loading
src/nbi/service/_tools/HttpStatusCodes.py +12 −9 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ HTTP_ACCEPTED = 202 HTTP_NOCONTENT = 204 HTTP_BADREQUEST = 400 HTTP_NOTFOUND = 404 HTTP_NOT_ACCEPTABLE = 406 HTTP_CONFLICT = 409 HTTP_UNSUPMEDIATYPE = 415 HTTP_SERVERERROR = 500 HTTP_NOT_IMPLEMENTED = 501 HTTP_GATEWAYTIMEOUT = 504
src/nbi/service/well_known_meta/Resources.py +46 −14 Original line number Diff line number Diff line Loading @@ -12,14 +12,39 @@ # See the License for the specific language governing permissions and # limitations under the License. # RESTCONF .well-known endpoint (RFC 8040) from flask import jsonify from flask import abort, jsonify, make_response, request from flask_restful import Resource from xml.sax.saxutils import escape import xml.etree.ElementTree as ET from .._tools.HttpStatusCodes import HTTP_NOT_ACCEPTABLE XRD_NS = 'http://docs.oasis-open.org/ns/xri/xrd-1.0' ET.register_namespace('', XRD_NS) RESTCONF_PREFIX = '/restconf' class WellKnownHostMeta(Resource): def get(self): response = { best = request.accept_mimetypes.best_match([ 'application/xrd+xml', 'application/json', ], default='application/xrd+xml') if best == 'application/xrd+xml': xrd = ET.Element('{{{:s}}}XRD'.format(str(XRD_NS))) ET.SubElement(xrd, '{{{:s}}}Link'.format(str(XRD_NS)), attrib={ 'rel': 'restconf', 'href': RESTCONF_PREFIX }) xml_string = ET.tostring(xrd, encoding='utf-8', xml_declaration=True).decode() response = make_response(str(xml_string)) response.status_code = 200 response.content_type = best return response elif best == 'application/json': response = jsonify({ 'restconf': { 'capabilities': [ 'urn:ietf:params:restconf:capability:defaults:1.0', Loading @@ -30,6 +55,13 @@ class WellKnownHostMeta(Resource): 'application/yang-data+json', 'application/yang-data+xml' ] } } return jsonify(response) }, 'links': [ {'rel': 'restconf', 'href': RESTCONF_PREFIX} ] }) response.status_code = 200 response.content_type = best return response else: abort(HTTP_NOT_ACCEPTABLE)