Skip to content
Snippets Groups Projects
Select Git revision
  • 40b9809d25f08336d4482a793cc5d3e5f6d5299a
  • develop default protected
  • redploy-placement-port
  • master protected
  • feature/NAT-1574-add-moodi-for-ixs
  • authorship-fix-from-develop
  • 1048-service-config-backfilling
  • feature/nat-1211-edgeport-lacp-xmit
  • fix/nat-1120-sdp-validation
  • NAT-1154-import-edge-port-update
  • fix/l3-imports
  • feature/10GGBS-NAT-980
  • fix/NAT-1009/fix-redeploy-base-config-if-there-is-a-vprn
  • 4.12
  • 4.11
  • 4.10
  • 4.8
  • 4.5
  • 4.4
  • 4.3
  • 4.2
  • 4.1
  • 4.0
  • 3.12
  • 3.11
  • 3.10
  • 3.9
  • 3.8
  • 3.7
  • 3.6
  • 3.5
  • 3.4
  • 3.3
33 results

helpers.py

Blame
  • default.py 1.49 KiB
    """
    Default Endpoints
    =========================
    
    .. contents:: :local:
    
    /version
    ---------------------
    
    .. autofunction:: compendium_v2.routes.default.version
    
    """
    import pkg_resources
    from flask import Blueprint, jsonify, render_template
    
    from compendium_v2.routes import common
    
    routes = Blueprint('compendium-v2-default', __name__)
    API_VERSION = '0.1'
    
    VERSION_SCHEMA = {
        '$schema': 'http://json-schema.org/draft-07/schema#',
    
        'type': 'object',
        'properties': {
            'api': {
                'type': 'string',
                'pattern': r'\d+\.\d+'
            },
            'module': {
                'type': 'string',
                'pattern': r'\d+\.\d+'
            }
        },
        'required': ['api', 'module'],
        'additionalProperties': False
    }
    
    
    @routes.after_request
    def after_request(resp):
        return common.after_request(resp)
    
    
    @routes.route('/', defaults={'path': ''}, methods=['GET'])
    @routes.route('/<path:path>', methods=['GET'])
    def index(path):
        # https://flask.palletsprojects.com/en/2.0.x/patterns/singlepageapplications/
        return render_template('index.html')
    
    
    @routes.route('/version', methods=['GET', 'POST'])
    @common.require_accepts_json
    def version():
        """
        handler for /version requests
    
        response will be formatted as:
    
        .. asjson::
            compendium_v2.routes.default.VERSION_SCHEMA
    
        :return:
        """
        version_params = {
            'api': API_VERSION,
            'module':
                pkg_resources.get_distribution('compendium-v2').version
        }
        return jsonify(version_params)