Пример #1
0
def script_catalog():  # noqa: E501
    """Retrieve the script catalog

    Retrieve the script catalog # noqa: E501


    :rtype: Response
    """
    if (not hasAccess()):
        return redirectUnauthorized()

    driver = LoadedDrivers.getDefaultDriver()
    return Response(status=200, body=driver.getScriptsCatalog())
Пример #2
0
def system_status():  # noqa: E501
    """Retrieve the system status

    Retrieve the system status # noqa: E501


    :rtype: Response
    """
    if(not hasAccess()):
        return redirectUnauthorized()

    body = State.config.serialize(["driver", "log", "log-file", "log-colorize"])
    body.update({'debug': State.options.debug, 'sensitive': State.options.sensitive})
    return Response(status=200, body=body)
Пример #3
0
def get_script(name=None):  # noqa: E501
    """Retrieve the contents of a script

    Retrieve the contents of a script # noqa: E501

    :param name: The script name.
    :type name: str

    :rtype: Response
    """

    if (not hasAccess()):
        return redirectUnauthorized()

    driver = LoadedDrivers.getDefaultDriver()
    return Response(status=200, body=driver.readScript(name))
Пример #4
0
def 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
    """
    if(not hasAccess()):
        return redirectUnauthorized()

    driver = LoadedDrivers.getDefaultBaseDriver()
    body = {"name": str(driver.__class__.__name__)}
    body.update(driver.serialize())
    return Response(status=200, body=body)
Пример #5
0
def delete_script(delete=None):  # noqa: E501
    """Delete a script

    Delete a script # noqa: E501

    :param delete: The data needed to delete this script
    :type delete: dict | bytes

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

    if (not hasAccess()):
        return redirectUnauthorized()

    driver = LoadedDrivers.getDefaultDriver()
    driver.deleteScript(delete.script.name)
    return Response(status=200, body={})
Пример #6
0
def create_script(create=None):  # noqa: E501
    """Create a new script

    Create a new script # noqa: E501

    :param Scripts: The data needed to create this script
    :type Scripts: dict | bytes

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

    if (not hasAccess()):
        return redirectUnauthorized()

    driver = LoadedDrivers.getDefaultDriver()
    driver.saveScript(create.script.name, create.script.content)
    return Response(status=200, body={'file-name': create.script.name})
Пример #7
0
def rename_script(rename=None):  # noqa: E501
    """Rename a script

    Rename a script # noqa: E501

    :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

    if (not hasAccess()):
        return redirectUnauthorized()

    driver = LoadedDrivers.getDefaultDriver()
    if (not driver.renameScript(rename.original.name, rename.new.name)):
        return ErrorResponse(status=500,
                             message='Cannot rename to an existing file.')
    return Response(status=200, body={'file-name': rename.new.name})
Пример #8
0
def endpoint_catalog(catalog=None):  # noqa: E501
    """Retrieve the endpoint catalog

    Retrieve the endpoint catalog # noqa: E501

    :param catalog: The data needed to get a catalog
    :type catalog: dict | bytes

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

    if (not hasAccess()):
        return redirectUnauthorized()

    driver = LoadedDrivers.getDefaultDriver()
    auth = None
    if (catalog):
        auth = catalog
    return Response(status=200, body=driver.getCatalog(auth))
Пример #9
0
def command(execute=None):  # noqa: E501
    """Execute a Command

    Execute a command # noqa: E501

    :param execute: The data needed to execute this command
    :type execute: dict | bytes

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

    if (not hasAccess()):
        return redirectUnauthorized()

    try:
        connector = None

        parameters = {}

        if (execute.command.parameters):
            parameters = execute.command.parameters

        credentials = Credentials()

        options = Options()

        if (execute.command.options):
            if ('debug' in execute.command.options):
                options.debug = execute.command.options['debug']

            if ('sensitive' in execute.command.options):
                options.sensitive = execute.command.options['sensitive']

        if (execute.auth):
            credentials = mapUserAuthToCredentials(execute.auth, credentials)
            if (not execute.auth.api_token):
                options.sensitive = True

        connector = Connector(options=options,
                              credentials=credentials,
                              command=execute.command.command,
                              parameters=parameters)

        commandHandler = connector.execute()

        response = Response(
            status=commandHandler.response.getResponseStatusCode(),
            body=commandHandler.response.getResponseBody())

        if (options.debug):
            response.log = connector.logBuffer

        return response
    except:
        State.log.error(traceback.format_exc())
        if ('debug' in execute.command.options
                and execute.command.options['debug']):
            return ErrorResponse(
                status=500,
                message=
                "Uncaught exception occured during processing. To get a larger stack trace, visit the logs.",
                state=traceback.format_exc(3))
        else:
            return ErrorResponse(status=500, message="")