Source:
<code>public void customize() { Map<?,?> ports = ImmutableMap.of("port", getServerPort()); Networking.checkPortsValid(ports); List<String> commands = new LinkedList<>(); commands.add(String.format("mkdir -p %s", getDataDirectory())); if (MongoDBAuthenticationUtils.usesAuthentication(entity)) { String destinationLocation = Os.mergePaths(getRunDir(), "mongodb-keyfile"); entity.sensors().set(AbstractMongoDBServer.MONGODB_KEYFILE_DESTINATION, destinationLocation); String keyfileContents = entity.config().get(AbstractMongoDBServer.MONGODB_KEYFILE_CONTENTS); if (keyfileContents == null) { String keyfileUrl = entity.config().get(AbstractMongoDBServer.MONGODB_KEYFILE_URL); <START> copyResource(keyfileUrl, destinationLocation); <END> } else { commands.add(BashCommands.pipeTextToFile(keyfileContents, destinationLocation)); } commands.add("chmod 600 " + destinationLocation); } newScript(CUSTOMIZING) .updateTaskAndFailOnNonZeroResultCode() .body.append(commands).execute(); String templateUrl = entity.getConfig(MongoDBServer.MONGODB_CONF_TEMPLATE_URL); if (!Strings.isNullOrEmpty(templateUrl)) copyTemplate(templateUrl, getConfFile()); if (MongoDBAuthenticationUtils.usesAuthentication(entity)) { launch(getArgsBuilderWithNoAuthentication((AbstractMongoDBServer) getEntity()) .add("--dbpath", getDataDirectory())); newScript("create-user") .body.append(String.format("%s --port %s" + " --host localhost admin --eval \"db.createUser({user: '%s',pwd: '%s',roles: [ 'root' ]})\"", Os.mergePaths(getExpandedInstallDir(), "bin/mongo"), getServerPort(), getRootUsername(), MongoDBAuthenticationUtils.getRootPassword(entity))) .updateTaskAndFailOnNonZeroResultCode() .execute(); stop(); } }</code><technical_language>I worth checking keyfileUrl null in case changes behaviour of usesAuthentication realising this block implicitly relies keyfileUrl non-null</technical_language>

Target:
public void customize() { Map<?,?> ports = ImmutableMap.of("port", getServerPort()); Networking.checkPortsValid(ports); List<String> commands = new LinkedList<>(); commands.add(String.format("mkdir -p %s", getDataDirectory())); if (MongoDBAuthenticationUtils.usesAuthentication(entity)) { String destinationLocation = Os.mergePaths(getRunDir(), "mongodb-keyfile"); entity.sensors().set(AbstractMongoDBServer.MONGODB_KEYFILE_DESTINATION, destinationLocation); String keyfileContents = entity.config().get(AbstractMongoDBServer.MONGODB_KEYFILE_CONTENTS); if (Strings.isNullOrEmpty(keyfileContents)) { String keyfileUrl = entity.config().get(AbstractMongoDBServer.MONGODB_KEYFILE_URL); if (Strings.isNullOrEmpty(keyfileUrl)) { throw new IllegalStateException("MongoDBAuthenticationUtils.usesAuthentication returned true, but neither keyfileContents nor keyfileUrl are set"); } copyResource(keyfileUrl, destinationLocation); } else { commands.add(BashCommands.pipeTextToFile(keyfileContents, destinationLocation)); } commands.add("chmod 600 " + destinationLocation); } newScript(CUSTOMIZING) .updateTaskAndFailOnNonZeroResultCode() .body.append(commands).execute(); String templateUrl = entity.getConfig(MongoDBServer.MONGODB_CONF_TEMPLATE_URL); if (!Strings.isNullOrEmpty(templateUrl)) copyTemplate(templateUrl, getConfFile()); if (MongoDBAuthenticationUtils.usesAuthentication(entity)) { launch(getArgsBuilderWithNoAuthentication((AbstractMongoDBServer) getEntity()) .add("--dbpath", getDataDirectory())); newScript("create-user") .body.append(String.format("%s --port %s" + " --host localhost admin --eval \"db.createUser({user: '%s',pwd: '%s',roles: [ 'root' ]})\"", Os.mergePaths(getExpandedInstallDir(), "bin/mongo"), getServerPort(), getRootUsername(), MongoDBAuthenticationUtils.getRootPassword(entity))) .updateTaskAndFailOnNonZeroResultCode() .execute(); stop(); } }