def compile(source_text, filename=''): # Steps taken: # 1) parser .calvin file -> IR. May produce syntax errors/warnings # 2) checker IR -> IR. May produce syntax errors/warnings # 3) analyzer IR -> app. Should not fail. Sets 'valid' property of IR to True/False deployable = {'valid': False, 'actors': {}, 'connections': {}} ir, errors, warnings = calvin_parser(source_text, filename) # If there were errors during parsing no IR will be generated if not errors: c_errors, c_warnings = check(ir) errors.extend(c_errors) warnings.extend(c_warnings) deployable = generate_app_info(ir) return deployable, errors, warnings
def compile(source_text, filename='', verify=True): # Steps taken: # 1) parser .calvin file -> IR. May produce syntax errors/warnings # 2) checker IR -> IR. May produce syntax errors/warnings # 3) analyzer IR -> app. Should not fail. Sets 'valid' property of IR to True/False deployable = {'valid': False, 'actors': {}, 'connections': {}} _log.debug("Parsing...") ir, errors, warnings = calvin_parser(source_text, filename) _log.debug("Parsed %s, %s, %s" % (ir, errors, warnings)) # If there were errors during parsing no IR will be generated if not errors: c_errors, c_warnings = check(ir, verify=verify) errors.extend(c_errors) warnings.extend(c_warnings) deployable = generate_app_info(ir, verify=verify) if errors: deployable['valid'] = False _log.debug("Compiled %s, %s, %s" % (deployable, errors, warnings)) return deployable, errors, warnings
def compile(source_text, filename='', content=None, credentials=None, verify=True, node=None): # Steps taken: # 1) Verify signature when credentials supplied # 2) parser .calvin file -> IR. May produce syntax errors/warnings # 3) checker IR -> IR. May produce syntax errors/warnings # 4) analyzer IR -> app. Should not fail. Sets 'valid' property of IR to True/False deployable = {'valid': False, 'actors': {}, 'connections': {}} errors = [] #TODO: fill in something meaningful warnings = [] if credentials: _log.debug("Check credentials...") sec = Security(node) sec.set_subject(credentials) if not sec.authenticate_subject(): _log.error("Check credentials...failed authentication") # This error reason is detected in calvin control and gives proper REST response errors.append({'reason': "401: UNAUTHORIZED", 'line': 0, 'col': 0}) return deployable, errors, warnings if (not sec.verify_signature_content(content, "application") or not sec.check_security_policy()): # Verification not OK if sign or cert not OK or if the signer is denied by security policies print "\n IN DEPLOYER\n " _log.error("Check credentials...failed application verification") # This error reason is detected in calvin control and gives proper REST response errors.append({'reason': "401: UNAUTHORIZED", 'line': None, 'col': None}) return deployable, errors, warnings _log.debug("Parsing...") ir, errors, warnings = calvin_parser(source_text, filename) _log.debug("Parsed %s, %s, %s" % (ir, errors, warnings)) # If there were errors during parsing no IR will be generated if not errors: c_errors, c_warnings = check(ir, verify=verify) errors.extend(c_errors) warnings.extend(c_warnings) deployable = generate_app_info(ir, verify=verify) if errors: deployable['valid'] = False _log.debug("Compiled %s, %s, %s" % (deployable, errors, warnings)) return deployable, errors, warnings
def testMissingActor(self): script = """a:std.NotLikely()""" result = self.invoke_parser_assert_syntax("inline", script) app_info = generate_app_info(result) self.assertFalse(app_info["valid"])
def testSimpleScript(self): test = "test9" # First make sure result below is error-free result = self.invoke_parser_assert_syntax(test) app_info = generate_app_info(result) self.assert_app_info(test, app_info)
def testMissingActor(self): script = """a:std.NotLikely()""" result = self.invoke_parser_assert_syntax('inline', script) app_info = generate_app_info(result) self.assertFalse(app_info['valid'])
def testSimpleScript(self): test = 'test9' # First make sure result below is error-free result = self.invoke_parser_assert_syntax(test) app_info = generate_app_info(result) self.assert_app_info(test, app_info)