def setUp(self):
        app = Sanic(__name__)
        app.config["SECRET_KEY"] = "my secret"

        basic_verify_auth = HTTPBasicAuth()

        @basic_verify_auth.verify_password
        def basic_verify_auth_verify_password(username, password):
            if username == "john":
                return password == "hello"
            elif username == "susan":
                return password == "bye"
            elif username == "":
                return True
            return False

        @basic_verify_auth.error_handler
        def error_handler(request):
            return text("error", status=403)  # use a custom error status

        @app.route("/")
        def index(request):
            return text("index")

        @app.route("/basic-verify")
        @basic_verify_auth.login_required
        def basic_verify_auth_route(request):
            anon = basic_verify_auth.username(request) == ""
            return text(
                f"basic_verify_auth:{basic_verify_auth.username(request)} "
                f"anon:{anon}")

        self.app = app
        self.basic_verify_auth = basic_verify_auth
        self.client = app.test_client
Пример #2
0
    def setUp(self):
        app = Sanic(__name__)
        app.config["SECRET_KEY"] = "my secret"

        basic_auth = HTTPBasicAuth()
        token_auth = HTTPTokenAuth("MyToken")
        multi_auth = MultiAuth(basic_auth, token_auth)

        @basic_auth.verify_password
        def verify_password(username, password):
            return username == "john" and password == "hello"

        @token_auth.verify_token
        def verify_token(token):
            return token == "this-is-the-token!"

        @token_auth.error_handler
        def error_handler(request):
            return text("error",
                        status=401,
                        headers={"WWW-Authenticate": 'MyToken realm="Foo"'})

        @app.route("/")
        def index(request):
            return text("index")

        @app.route("/protected")
        @multi_auth.login_required
        def auth_route(request):
            return text("access granted")

        self.app = app
        self.client = app.test_client
    def setUp(self):
        app = Sanic(__name__)
        app.config["SECRET_KEY"] = "my secret"
        app.config["CORS_AUTOMATIC_OPTIONS"] = True

        CORS(app)
        basic_auth = HTTPBasicAuth()

        @basic_auth.get_password
        def get_basic_password(username):
            if username == "john":
                return "hello"
            elif username == "susan":
                return "bye"
            else:
                return None

        @app.route("/")
        def index(request):
            return text("index")

        @app.route("/basic")
        @basic_auth.login_required
        def basic_auth_route(request):
            return text(f"basic_auth:{basic_auth.username(request)}")

        self.app = app
        self.basic_auth = basic_auth
        self.client = app.test_client
    def setUp(self):
        app = Sanic(__name__)
        app.config["SECRET_KEY"] = "my secret"

        basic_custom_auth = HTTPBasicAuth()

        @basic_custom_auth.get_password
        def get_basic_custom_auth_get_password(username):
            if username == "john":
                return md5("hello").hexdigest()
            elif username == "susan":
                return md5("bye").hexdigest()
            else:
                return None

        @basic_custom_auth.hash_password
        def basic_custom_auth_hash_password(password):
            return md5(password).hexdigest()

        @app.route("/")
        def index(request):
            return text("index")

        @app.route("/basic-custom")
        @basic_custom_auth.login_required
        def basic_custom_auth_route(request):
            return text(
                f"basic_custom_auth:{basic_custom_auth.username(request)}")

        self.app = app
        self.basic_custom_auth = basic_custom_auth
        self.client = app.test_client
Пример #5
0
    def setUp(self):
        app = Sanic(__name__)
        app.config["SECRET_KEY"] = "my secret"

        basic_auth_my_realm = HTTPBasicAuth(realm="My Realm")

        @basic_auth_my_realm.get_password
        def get_basic_password_2(username):
            if username == "john":
                return "johnhello"
            elif username == "susan":
                return "susanbye"
            else:
                return None

        @basic_auth_my_realm.hash_password
        def basic_auth_my_realm_hash_password(username, password):
            return username + password

        @basic_auth_my_realm.error_handler
        def basic_auth_my_realm_error(request):
            return text("custom error")

        @app.route("/")
        def index(request):
            return text("index")

        @app.route("/basic-with-realm")
        @basic_auth_my_realm.login_required
        def basic_auth_my_realm_route(request):
            return text(
                f"basic_auth_my_realm:{basic_auth_my_realm.username(request)}")

        self.app = app
        self.basic_auth_my_realm = basic_auth_my_realm
        self.client = app.test_client
Пример #6
0
import json
import argparse
from sanic.log import logger, logging
import meraki
import meraki.exceptions
import yaml

from group_mapper_csrv import GroupMapper

__author__ = "Ryan LaTorre"
__email__ = "*****@*****.**"
__copyright__ = "Copyright (c) 2020 Cisco and/or its affiliates"
__license__ = "Cisco Sample Code License"

app = Sanic("meraki-csrv")
auth = HTTPBasicAuth()

# The root logger
#logging.getLogger().setLevel(logging.INFO)
logging.getLogger().setLevel(logging.DEBUG)
# The Meraki logger is very talkative, set it to ERROR only
logging.getLogger('meraki').setLevel(logging.ERROR)
#logger.setLevel(logging.INFO)
logger.setLevel(logging.DEBUG)

class MerakiConfig:
    def __init__(self, config):
        self.api_key = config['meraki_api_key']

def provision_client(network_id: str, mac: str, username: str, mapped_group: str):
    clients = [{'mac': mac, 'name': username}]