public void redFlag(String msg, String tag) { if (!_redFlagRecord) { return; } _redFlagWarnings.add(new Warning(msg, tag)); }
/** Policy with actual circular reference as statement */ @Test public void testRoutingPolicyCircularReference() { String parentPolicyName = "parent"; _rpb.setName(parentPolicyName) .setStatements(ImmutableList.of(new CallStatement(parentPolicyName))) .build(); _c.computeRoutingPolicySources(_w); /* * A circular reference warning should be emitted containing the name of the circularly * referenced policy. */ assertThat(_w.getRedFlagWarnings(), not(empty())); assertThat( _w.getRedFlagWarnings().iterator().next().getText(), containsString(parentPolicyName)); }
/** Policy with actual circular reference as expr */ @Test public void testRoutingPolicyCircularReferenceExpr() { String parentPolicyName = "parent"; CallExpr callExpr = new CallExpr(parentPolicyName); If ifStatement = new If(); ifStatement.setGuard(callExpr); _rpb.setName(parentPolicyName).setStatements(ImmutableList.of(ifStatement)).build(); _c.computeRoutingPolicySources(_w); /* * A circular reference warning should be emitted containing the name of the circularly * referenced policy. */ assertThat(_w.getRedFlagWarnings(), not(empty())); assertThat( _w.getRedFlagWarnings().iterator().next().getText(), containsString(parentPolicyName)); }
@Override public String prettyPrint() { StringBuilder retString = new StringBuilder("Results of parsing vendor configurations\n"); for (String name : _warnings.keySet()) { retString.append("\n " + name + "[Parser warnings]\n"); for (Warning warning : _warnings.get(name).getRedFlagWarnings()) { retString.append(" RedFlag " + warning.getTag() + " : " + warning.getText() + "\n"); } for (Warning warning : _warnings.get(name).getUnimplementedWarnings()) { retString.append( " Unimplemented " + warning.getTag() + " : " + warning.getText() + "\n"); } for (Warning warning : _warnings.get(name).getPedanticWarnings()) { retString.append(" Pedantic " + warning.getTag() + " : " + warning.getText() + "\n"); } } for (String name : _errors.keySet()) { retString.append("\n " + name + "[Parser errors]\n"); for (String line : _errors.get(name).getLineMap()) { retString.append(" " + line + "\n"); } } for (String name : _parseTrees.keySet()) { retString.append("\n " + name + " [Parse trees]\n"); for (String sentence : _parseTrees.get(name).getSentences()) { retString.append(" ParseTreeSentence : " + sentence + "\n"); } } return retString.toString(); }
_w.getRedFlagWarnings().iterator().next().getText(), containsString(parentPolicyName));
public void unimplemented(String msg) { if (!_unimplementedRecord) { return; } _unimplementedWarnings.add(new Warning(msg, TAG_UNIMPLEMENTED)); }
public void pedantic(String msg, String tag) { _pedanticWarnings.add(new Warning(msg, tag)); }
sb.append(" " + name + ":\n"); for (Warning warning : _warnings.get(name).getRedFlagWarnings()) { sb.append(" RedFlag " + warning.getTag() + " : " + warning.getText() + "\n"); redFlagCount++; sb.append(" Unimplemented " + warning.getTag() + " : " + warning.getText() + "\n"); unimplementedCount++; sb.append(" Pedantic " + warning.getTag() + " : " + warning.getText() + "\n"); pedanticCount++;
@VisibleForTesting public static AwsConfiguration parseAwsConfigurations( Map<Path, String> configurationData, ParseVendorConfigurationAnswerElement pvcae) { AwsConfiguration config = new AwsConfiguration(); for (Entry<Path, String> configFile : configurationData.entrySet()) { Path path = configFile.getKey(); int pathLength = configFile.getKey().getNameCount(); String fileText = configFile.getValue(); String regionName = path.getName(pathLength - 2).toString(); // parent dir name String fileName = path.subpath(pathLength - 3, pathLength).toString(); pvcae.getFileMap().put(BfConsts.RELPATH_AWS_CONFIGS_FILE, fileName); JSONObject jsonObj = null; try { jsonObj = new JSONObject(fileText); } catch (JSONException e) { pvcae.addRedFlagWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning(String.format("AWS file %s is not valid JSON", fileName), "AWS")); } if (jsonObj != null) { try { config.addConfigElement(regionName, jsonObj, fileName, pvcae); } catch (JSONException e) { throw new BatfishException("Problems parsing JSON in " + fileName, e); } } } return config; }
sb.append("\n " + name + "[Conversion warnings]\n"); for (Warning warning : warnings.getRedFlagWarnings()) { sb.append(" RedFlag " + warning.getTag() + " : " + warning.getText() + "\n"); sb.append(" Unimplemented " + warning.getTag() + " : " + warning.getText() + "\n"); sb.append(" Pedantic " + warning.getTag() + " : " + warning.getText() + "\n");
public void addConfigElement( JSONObject jsonObj, String sourceFileName, ParseVendorConfigurationAnswerElement pvcae) throws JSONException { Iterator<?> keys = jsonObj.keys(); while (keys.hasNext()) { String key = (String) keys.next(); if (ignoreElement(key)) { continue; } // All objects nested under the current key will be subjected to this function, which will // integrate them appropriately into this Region. Returns null on unrecognized keys. ThrowingConsumer<JSONObject, JSONException> integratorFunction = getChildConsumer(key); if (integratorFunction == null) { // Add warning for unrecognized key in AWS file pvcae.addUnimplementedWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format("Unrecognized element '%s' in AWS file %s", key, sourceFileName), "AWS")); } else { JSONArray jsonArray = jsonObj.getJSONArray(key); for (int index = 0; index < jsonArray.length(); index++) { integratorFunction.accept(jsonArray.getJSONObject(index)); } } } }
answerElement.addRedFlagWarning( name, new Warning( "Cannot serialize network config. Bad hostname " + name.replace("\\", "/"), "MISCELLANEOUS"));