Exemplo n.º 1
0
    def login(credentials):
        driver: Driver = LoadedDrivers.getAuthDriver()
        role = None
        if not driver.isDriverAuthenticatable():
            return None
        if driver.isApitaxAuthBasedOnApiAuth():
            # apiDriver = LoadedDrivers.getPrimaryDriver()
            apiDriver: Driver = driver

            if 'driver' in credentials.extra:
                apiDriver = LoadedDrivers.getDriver(
                    credentials.extra['driver'])
            result: ApitaxResponse = apiDriver.authenticateApi(credentials)

            if not result.isStatusSuccess():
                return None

            role = driver.authenticateApitax(
                result.getResponseBody()['credentials'])
            if apiDriver.isApiTokenable():
                credentials.token = apiDriver.getApiToken(result)
        else:
            role = driver.authenticateApitax(credentials)

        if not role:
            return None
        return {"role": role, "credentials": credentials}
Exemplo n.º 2
0
def get_driver_script(name, name2=None):  # noqa: E501
    """Retrieve the contents of a script

    Retrieve the contents of a script # noqa: E501

    :param name2: Get status of a driver with this name
    :type name2: str
    :param name: The script name.
    :type name: str

    :rtype: Response
    """
    response = errorIfUnauthorized(role='user')
    if response:
        return response
    else:
        response = ApitaxResponse()

    print(name)
    print(name2)

    driver: Driver = LoadedDrivers.getDriver(name2)

    response.body.add({'content': driver.getDriverScript(name)})

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 3
0
def get_driver_status(name):  # noqa: E501
    """Retrieve the status of a loaded driver

    Retrieve the status of a loaded driver # noqa: E501

    :param name: Get status of a driver with this name
    :type name: str

    :rtype: Response
    """

    response = errorIfUnauthorized(role='admin')
    if response:
        return response
    else:
        response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(name)
    response.body.add({'name': driver.getDriverName()})
    response.body.add({'description': driver.getDriverDescription()})
    response.body.add({'tips': driver.getDriverTips()})
    response.body.add({'help': driver.getDriverHelpEndpoint()})
    response.body.add({'minimum-role': driver.getDriverMinimumRole()})

    options = {}
    options['configurable'] = driver.isDriverConfigurable()
    options['authenticatable'] = driver.isDriverAuthenticatable()
    options['role-restricted'] = driver.isDriverRoleRestricted()
    options['whitelisted'] = driver.isDriverWhitelisted()
    options['blacklisted'] = driver.isDriverBlacklisted()
    response.body.add({'options': options})

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 4
0
def rename_driver_script(name, rename=None):  # noqa: E501
    """Rename a script

    Rename a script # noqa: E501

    :param name: Get status of a driver with this name
    :type name: str
    :param rename: The data needed to save this script
    :type rename: dict | bytes

    :rtype: Response
    """
    if connexion.request.is_json:
        rename = Rename.from_dict(connexion.request.get_json())  # noqa: E501

    response = errorIfUnauthorized(role='developer')
    if response:
        return response
    else:
        response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(name)
    if not driver.renameDriverScript(rename.original.name, rename.new.name):
        return ErrorResponse(status=500,
                             message='Cannot rename to an existing file.')

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 5
0
def rename_driver_script(driver, script_rename=None):  # noqa: E501
    """Rename a script

    Rename a script # noqa: E501

    :param driver: The driver to use for the request. ie. github
    :type driver: str
    :param script_rename: The data needed to rename this script
    :type script_rename: dict | bytes

    :rtype: Response
    """
    if connexion.request.is_json:
        script_rename = ScriptRename.from_dict(
            connexion.request.get_json())  # noqa: E501

    response = errorIfUnauthorized(role='developer')
    if response:
        return response
    else:
        response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(driver)
    if not driver.renameDriverScript(script_rename.original.name,
                                     script_rename.new.name):
        return ErrorResponse(status=500,
                             message='Cannot rename to an existing file.')

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 6
0
def delete_user(user, driver, user_delete=None):  # noqa: E501
    """Delete a user

    Delete a user # noqa: E501

    :param user: Delete user with this name
    :type user: str
    :param driver: The driver to use for the request. ie. github
    :type driver: str
    :param user_delete: The data needed to delete this user
    :type user_delete: dict | bytes

    :rtype: Response
    """
    if connexion.request.is_json:
        user_delete = UserDelete.from_dict(
            connexion.request.get_json())  # noqa: E501

    response = errorIfUnauthorized(role='admin')
    if response:
        return response
    else:
        response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(driver)

    if driver.deleteApitaxUser(User(username=user)):
        return Response(status=200, body=response.getResponseBody())

    return ErrorResponse(status=500, message='Failed to create user')
Exemplo n.º 7
0
def delete_driver_script(name, delete=None):  # noqa: E501
    """Delete a script

    Delete a script # noqa: E501

    :param name: Get status of a driver with this name
    :type name: str
    :param delete: The data needed to delete this script
    :type delete: dict | bytes

    :rtype: Response
    """
    if connexion.request.is_json:
        delete = Delete1.from_dict(connexion.request.get_json())  # noqa: E501

    response = errorIfUnauthorized(role='developer')
    if response:
        return response
    else:
        response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(name)
    driver.deleteDriverScript(delete.script.name)

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 8
0
def delete_driver_script(driver, script_delete=None):  # noqa: E501
    """Delete a script

    Delete a script # noqa: E501

    :param driver: The driver to use for the request. ie. github
    :type driver: str
    :param script_delete: The data needed to delete this script
    :type script_delete: dict | bytes

    :rtype: Response
    """
    if connexion.request.is_json:
        script_delete = ScriptDelete.from_dict(
            connexion.request.get_json())  # noqa: E501

    response = errorIfUnauthorized(role='developer')
    if response:
        return response
    else:
        response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(driver)
    driver.deleteDriverScript(script_delete.script.name)

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 9
0
def create_user(user, name, create=None):  # noqa: E501
    """Create a new script

    Create a new script # noqa: E501

    :param user: Get user with this name
    :type user: str
    :param name: Get status of a driver with this name
    :type name: str
    :param create: The data needed to create this user
    :type create: dict | bytes

    :rtype: Response
    """
    if connexion.request.is_json:
        create = Create.from_dict(connexion.request.get_json())  # noqa: E501

    response = errorIfUnauthorized(role='admin')
    if response:
        return response
    else:
        response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(name)
    user: User = mapUserToUser(create.script)

    if driver.createApitaxUser(user):
        return Response(status=200, body=response.getResponseBody())

    return ErrorResponse(status=500, message='Failed to create user')
Exemplo n.º 10
0
def execute_string(
        code: str,
        debug: bool = False) -> Tuple[BlockStatus, AhVisitor, float]:
    Drivers.add("scriptax", ScriptaxDriver(path="~/"))
    LoadedDrivers.load("scriptax")

    drivers_path = Path(
        Path(__file__).resolve().parents[1]).joinpath('drivers.json')
    packages = list(drivers_path)
    for key, value in packages.items():
        drivers = value['drivers']

        # Imports default driver
        try:
            module = importlib.import_module(key + '.drivers.driver')
            Drivers.add(key, module.driver)
            LoadedDrivers.load(key)
        except:
            print("Unable to load default driver inside of package: " + key)

        # Imports other drivers
        for driver in drivers:
            try:
                module = importlib.import_module(key + '.drivers.' + driver)
                Drivers.add(key + "_" + driver, module.driver)
                LoadedDrivers.load(key + "_" + driver)
            except:
                print("Unable to load driver `" + driver +
                      "` inside of package: " + key)

    start_time = time.process_time()
    block_status, ahvisitor = customizable_parser(read_string(code),
                                                  options=Options(debug=debug))
    total_time = time.process_time() - start_time
    return block_status, ahvisitor, total_time
Exemplo n.º 11
0
    def execute(self, filepath) -> tuple:
        if self.options.debug:
            self.log.log('>>> Opening Script: ' + filepath)
            self.log.log('')
            self.log.log('')

        if not self.options.driver:
            self.options.driver = LoadedDrivers.getDefaultDriver()

        scriptax = self.options.driver.getDriverScript(filepath)

        result = customizable_parser(scriptax,
                                     parameters=self.parameters,
                                     options=self.options,
                                     file=getPath(filepath))

        return result
Exemplo n.º 12
0
def get_user(user, name):  # noqa: E501
    """Retrieve a user

    Retrieve a user # noqa: E501

    :param user: Get user with this name
    :type user: str
    :param name: Get status of a driver with this name
    :type name: str

    :rtype: Response
    """
    response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(name)
    user: User = driver.getApitaxUser(User(username=user))
    response.body.add({'user': {'username': user.username, 'role': user.role}})

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 13
0
def get_user(user, driver):  # noqa: E501
    """Retrieve a user

    Retrieve a user # noqa: E501

    :param user: Get user with this name
    :type user: str
    :param driver: The driver to use for the request. ie. github
    :type driver: str

    :rtype: Response
    """

    response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(driver)
    user: User = driver.getApitaxUser(User(username=user))
    response.body.add({'user': {'username': user.username, 'role': user.role}})

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 14
0
def get_driver_api_catalog(name):  # noqa: E501
    """Retrieve the api catalog

    Retrieve the api catalog # noqa: E501

    :param name: Get status of a driver with this name
    :type name: str

    :rtype: Response
    """
    response = errorIfUnauthorized(role='developer')
    if response:
        return response
    else:
        response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(name)
    response.body.add(driver.getApiEndpointCatalog())

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 15
0
def get_driver_api_catalog(driver):  # noqa: E501
    """Retrieve the api catalog

    Retrieve the api catalog # noqa: E501

    :param driver: The driver to use for the request. ie. github
    :type driver: str

    :rtype: Response
    """
    response = errorIfUnauthorized(role='developer')
    if response:
        return response
    else:
        response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(driver)
    response.body.add(driver.getApiEndpointCatalog())

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 16
0
def get_driver_blacklist(driver):  # noqa: E501
    """Retrieve the blacklist in the driver

    Retrieve the blacklist in the driver # noqa: E501

    :param driver: The driver to use for the request. ie. github
    :type driver: str

    :rtype: Response
    """

    response = errorIfUnauthorized(role='admin')
    if response:
        return response
    else:
        response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(driver)
    response.body.add({'blacklist': driver.getDriverBlacklist()})

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 17
0
def get_driver_blacklist(name):  # noqa: E501
    """Retrieve the blacklist in the driver

    Retrieve the blacklist in the driver # noqa: E501

    :param name: Get status of a driver with this name
    :type name: str

    :rtype: Response
    """

    response = errorIfUnauthorized(role='admin')
    if response:
        return response
    else:
        response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(name)
    response.body.add({'blacklist': driver.getDriverBlacklist()})

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 18
0
def get_driver_api_status(name):  # noqa: E501
    """Retrieve the status of an api

    Retrieve the status of an api # noqa: E501

    :param name: Get status of a driver with this name
    :type name: str

    :rtype: Response
    """
    response = errorIfUnauthorized(role='developer')
    if response:
        return response
    else:
        response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(name)
    response.body.add({"format": driver.getApiFormat()})
    response.body.add({"description": driver.getApiDescription()})
    response.body.add({"status": driver.getApiStatus()})
    response.body.add({"auth-type": driver.getApiAuthType()})

    endpoints = {}
    endpoints['base'] = driver.getApiBaseEndpoint()
    endpoints['catalog'] = driver.getApiCatalogEndpoint()
    endpoints['auth'] = driver.getApiAuthEndpoint()
    response.body.add({'endpoints': endpoints})

    options = {}
    options['authenticatable'] = driver.isApiAuthenticated()
    options[
        'authentication-separate'] = driver.isApiAuthenticationSeparateRequest(
        )
    options['cataloggable'] = driver.isApiCataloggable()
    options['tokenable'] = driver.isApiTokenable()
    response.body.add({'options': options})

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 19
0
def get_driver_script(driver, script=None):  # noqa: E501
    """Retrieve the contents of a script

    Retrieve the contents of a script # noqa: E501

    :param driver: The driver to use for the request. ie. github
    :type driver: str
    :param script: The script name.
    :type script: str

    :rtype: Response
    """

    response = errorIfUnauthorized(role='user')
    if response:
        return response
    else:
        response = ApitaxResponse()

    driver: Driver = LoadedDrivers.getDriver(driver)

    response.body.add({'content': driver.getDriverScript(script)})

    return Response(status=200, body=response.getResponseBody())
Exemplo n.º 20
0
# Application import
from scriptax.parser.utils.BoilerPlate import customizable_parser
from scriptax.drivers.builtin.Scriptax import Scriptax

from apitaxcore.logs.Log import Log
from apitaxcore.logs.StandardLog import StandardLog
from apitaxcore.models.State import State
from apitaxcore.flow.LoadedDrivers import LoadedDrivers
from apitaxcore.drivers.Drivers import Drivers

State.log = Log(StandardLog(), logColorize=False)

State.log.log("> test")

Drivers.add("scriptax", Scriptax())
LoadedDrivers.load("scriptax")

#scriptax = "from scriptax import test.testing as Tester;"
#scriptax += "from scriptax import test.meow as MEOWWW;"
# scriptax += "from scriptax import bob.bob(testingthis='kk') as Wahp;"
# scriptax += "api someMethod () {log('TESTING SOME METHOD'); log(parent.variableTest);}"
# scriptax += "api paramMethod(test) {log(test);}"
# scriptax += "api returnMethod() {return 'wazzup';log('THIS SHOULD NOT BE REACHABLE');}"
# scriptax += "log(\"test\"); log(2+4/4); variableTest=5; variableTest='okay'; shawn=True; tristan=None; jen=0X678; if(shawn) {bob=42;log(jen); if(True) {log('help me pls');log(variableTest + 5 / 3);}} someInstance = new Tester();"
# scriptax += "log('break');"
# scriptax += "someInstance.setPath(path='methods are good to go');someMethod();someInstance.getPath();someInstance.resetPath();someInstance.getPath();Tester.getPath();Tester.resetPath();MEOWWW.getPath();"
# scriptax += "variableTest=5; if(shawn && variableTest > 5) return someInstance.addOne(num=5.1);"
# scriptax += "paramMethod(test='no way');log(returnMethod());log(someInstance.addOne(num=5));"
# scriptax += "bobInstance = new Wahp(testingthis='yeee');bobInstance.doBob();log(bobInstance.addOne(somenum=43));"
# scriptax += "someVar = {'bob': 5}; someVar.bob = 6; someVar.shawn = 'test'; log(someVar.shawn);"
# scriptax += "someDict = {'blerp': 0x987abc}; someVar.shawn = someDict; log(someVar.shawn.blerp);"
Exemplo n.º 21
0
from scriptaxstd.drivers.builtin.Api import Api
from scriptaxstd.drivers.builtin.ApiXml import ApiXml
from apitax.drivers.builtin.BasicAuth import BasicAuth
from apitax.drivers.builtin.Apitax import Apitax

# Adding imported drivers into app
Drivers.add("commandtax", Commandtax())
Drivers.add("scriptax", Scriptax())
Drivers.add("std", StandardLibrary())
Drivers.add("api", Api())
Drivers.add("api-xml", ApiXml())
Drivers.add("basic-auth", BasicAuth())
Drivers.add("apitax", Apitax())

# Loading added drivers
LoadedDrivers.load("commandtax")
LoadedDrivers.load("scriptax")
LoadedDrivers.load("std")
LoadedDrivers.load("api")
LoadedDrivers.load("api-xml")
LoadedDrivers.load("basic-auth")
LoadedDrivers.load("apitax")

# Importing/Adding custom project drivers
project.loadDrivers()

# Finishes loading app by loading custom drivers as specified in the config
setup.load()

# This loads the app for use in both the uWSGI and Nginx mode as well as dev server mode
from apitax.api.Server import *
Exemplo n.º 22
0
    def handleDriverCommand(self, command: Command) -> ApitaxResponse:
        response: ApitaxResponse = ApitaxResponse()

        driverName = None

        if len(command.command) < 1:
            return response.res_bad_request(
                body={
                    'error': 'Improper command: `blank` command was attempted.'
                })

        if '--apitax-debug' in command.command:
            command.options.debug = True
            del command.command[command.command.index('--apitax-debug')]

        if '--apitax-sensitive' in command.command:
            command.options.sensitive = True
            del command.command[command.command.index('--apitax-sensitive')]

        if '--apitax-driver' in command.command:
            driverName = command.command[
                command.command.index('--apitax-driver') + 1]
            del command.command[command.command.index('--apitax-sensitive') +
                                1]
            del command.command[command.command.index('--apitax-driver')]

        if driverName:
            command.options.driver = LoadedDrivers.getDriver(driverName)
        elif LoadedDrivers.getDriver(command.command[0]):
            command.options.driver = LoadedDrivers.getDriver(
                command.command[0])
            del command.command[0]
        else:
            command.options.driver = LoadedDrivers.getPrimaryDriver()

        if not command.options.driver:
            return response.res_server_error(
                body={
                    'error':
                    'Could not find a valid driver to use for command: ' +
                    str(command.command)
                })

        command.command = Command(command=command.command,
                                  request=command.request,
                                  parameters=command.parameters,
                                  options=command.options)

        if command.options.driver.isDriverCommandable():
            if command.options.driver.isApiAuthenticated():
                self.authenticate(command)
            response = command.options.driver.handleDriverCommand(
                command.command)
        else:
            return response.res_server_error(
                body={
                    'error':
                    'Driver `' + command.options.driver.getDriverName() +
                    '` does not support this operation: ' +
                    str(command.command)
                })

        return response