def execute(self, filepath): if (self.options.debug): self.log.log('>>> Opening Script: ' + filepath) self.log.log('') self.log.log('') if (self.options.driver): driver = LoadedDrivers.getBaseDriver(self.options.driver) else: driver = LoadedDrivers.getDefaultBaseDriver() input = InputStream(driver.readScript(filepath)) # input = FileStream(filepath) lexer = Ah210Lexer(input) stream = CommonTokenStream(lexer) parser = Ah210Parser(stream) tree = parser.prog() printer = AhListener() visitor = AhVisitor(self.config, self.header, self.auth, parameters=self.parameters, options=self.options) visitor.setState(file=getPath(filepath)) return visitor.visit(tree)
def execute_system_scripts_save(): driver = LoadedDrivers.getDefaultBaseDriver() driver.saveScript(request.json['file-name'], request.json['file']) return json.dumps({ 'status': 200, 'file-name': getPath(request.json['file-name']) })
def load(self): drivers = self.config.getAsList('drivers') for driver in drivers: LoadedDrivers.load(driver) if (self.options.debug): self.log.log('>> Finished Loading Drivers') self.log.log('') self.log.log('') if (self.username == '' and self.config.has('default-username')): self.username = LoadedDrivers.getDefaultBaseDriver( ).getDefaultUsername() # config.get('default-username') if (self.password == '' and self.config.has('default-password')): self.password = LoadedDrivers.getDefaultBaseDriver( ).getDefaultPassword() # config.get('default-password')
def __init__(self, options=Options(), credentials=None, command='', json=True, parameters={}): self.options = options self.parameters = parameters self.credentials = credentials self.command = command self.command = self.command.replace('\\"', '"') self.command = self.command.replace('\\\'', '\'') self.executionTime = None self.commandHandler = None self.logBuffer = [] self.config = Config.read() if (self.options.driver): self.http = LoadedDrivers.getBaseDriver(self.options.driver) else: self.http = LoadedDrivers.getDefaultBaseDriver() self.header = HeaderBuilder() if (json): self.header.build(self.http.getContentTypeJSON()) if (self.credentials.token == ''): preHeader = self.header.header.copy() if (self.http.isTokenable()): auth = AuthRequest(self.credentials, self.http, self.options) auth.authenticate() self.credentials.token = auth.getToken() self.header.header = preHeader self.header.build( self.http.getTokenAuthHeader(self.credentials)) else: self.header.build( self.http.getPasswordAuthHeader(self.credentials)) else: self.header.build(self.http.getTokenAuthHeader(self.credentials))
def visitEndpoint_statement(self, ctx: Ah210Parser.Endpoint_statementContext): name = self.visit(ctx.expr()) driver = None try: name.find('@') name = name.split('@') driver = LoadedDrivers.getBaseDriver(name[1]) name = name[0] except: if (self.appOptions.driver): driver = LoadedDrivers.getBaseDriver(self.appOptions.driver) else: driver = LoadedDrivers.getDefaultBaseDriver() endpoints = driver.getCatalog(self.data.getAuth())['endpoints'] if (name in endpoints): return endpoints[name]['value'] else: self.error("The endpoint requested does not exist") return None
def execute_system_scripts_rename(): driver = LoadedDrivers.getDefaultBaseDriver() if (not driver.renameScript(request.json['file-name-original'], request.json['file-name-new'])): return json.dumps({ 'status': 500, 'message': 'Cannot rename to an existing file.' }) return json.dumps({ 'status': 200, 'file-name': getPath(request.json['file-name-new']) })
def __init__(self, header, command, config, options=Options(), parameters={}, auth=Credentials()): if (type(command) is not list): command = shlex.split(command.strip()) if (len(command) < 1): return self.request = None if ('--debug' in command): options.debug = True if ('--sensitive' in command): options.sensitive = True if ('--driver' in command): options.driver = command[command.index('--driver') + 1] if (command[0] == 'script'): self.request = Script(config, header, auth, parameters, options) elif (command[0] == 'custom'): self.request = Custom(config, header, auth, parameters, options) else: if (options.driver): customCommands = LoadedDrivers.getCommandsDriver( options.driver) else: customCommands = LoadedDrivers.getDefaultCommandsDriver() self.request = customCommands.setup(config, header, auth, parameters, options) self.request = self.request.handle(command) return self.request.handle(command[1:])
def login(credentials): driver = LoadedDrivers.getAuthDriver() role = None if(driver.piggyBackOffApiAuth()): #apiDriver = LoadedDrivers.getPrimaryDriver() apiDriver = driver if('driver' in credentials.extra): apiDriver = LoadedDrivers.getBaseDriver(credentials.extra['driver']) apiAuth = AuthRequest(credentials, apiDriver, State.options) apiAuth.authenticate() if(not apiAuth.isAuthenticated()): return None role = driver.apitaxAuth({"credentials": credentials, "apiAuthRequest": apiAuth}) if(apiDriver.isTokenable()): credentials.token = apiAuth.getToken() else: role = driver.apitaxAuth({"credentials": credentials}) if(not role): return None return {"role": role, "credentials": credentials}
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)
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.getDefaultBaseDriver() driver.deleteScript(delete.script.name) return Response(status=200, body={})
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.getDefaultBaseDriver() driver.saveScript(create.script.name, create.script.content) return Response(status=200, body={'file-name': create.script.name})
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.getDefaultBaseDriver() 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})
def execute_system_driver_status(): driver = LoadedDrivers.getDefaultBaseDriver() driverDict = {"driver": {"name": str(driver.__class__.__name__)}} driverDict['driver'].update(driver.serialize()) return json.dumps(driverDict)
def execute_system_scripts_delete(): driver = LoadedDrivers.getDefaultBaseDriver() driver.deleteScript(request.json['file-name']) return json.dumps({'status': 200})
def execute_system_scripts_catalog(): driver = LoadedDrivers.getDefaultBaseDriver() return json.dumps(driver.getScriptsCatalog())
def execute_system_catalog(): driver = LoadedDrivers.getDefaultBaseDriver() auth = None if (request.json): auth = request.json['token'] return json.dumps(driver.getCatalog(auth))
def execute_system_scripts(): driver = LoadedDrivers.getDefaultBaseDriver() return json.dumps({ 'status': 200, "contents": driver.readScript(request.json['file-name']) })