use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class SshPostgresTarget method execute.
public ProcessExecution execute(String sql, String maskedSql) throws OpsException {
OpsTarget target = getOpsTarget();
// We probably want psql -A -t -c "command"
Command command = Command.build("psql");
command.addQuoted("--username=", username);
command.addQuoted("--host=", hostname);
command.addArgument(Argument.buildQuoted("--command=", sql).setMasked("--command=" + Command.MASKED));
CommandEnvironment env = new CommandEnvironment();
env.put("PGPASSWORD", password.plaintext());
command.setEnvironment(env);
return target.executeCommand(command);
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class ExpandArchive method handler.
@Handler
public void handler(OpsTarget target) throws OpsException {
if (OpsContext.isConfigure()) {
target.mkdir(extractPath);
String archiveFileName = archiveFile.getName();
if (archiveFileName.endsWith(".zip")) {
// -u = update, for (something close to) idempotency
// -o = overwrite (no prompt)
Command unzipCommand = Command.build("unzip -u -o {0} -d {1}", archiveFile, extractPath);
target.executeCommand(unzipCommand.setTimeout(TimeSpan.FIVE_MINUTES));
} else if (archiveFileName.endsWith(".tgz") || archiveFileName.endsWith(".tar.gz")) {
Command unzipCommand = Command.build("cd {0}; tar zxf {1}", extractPath, archiveFile);
target.executeCommand(unzipCommand.setTimeout(TimeSpan.FIVE_MINUTES));
} else {
throw new UnsupportedOperationException();
}
}
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class RegenerateLocales method getGeneratedLocales.
private List<String> getGeneratedLocales(OpsTarget target) throws OpsException {
Command listLocales = Command.build("localedef --list-archive");
ProcessExecution execution = target.executeCommand(listLocales);
List<String> locales = Lists.newArrayList();
for (String line : Splitter.on("\n").split(execution.getStdOut())) {
line = line.trim();
if (line.isEmpty()) {
continue;
}
locales.add(normalize(line));
}
return locales;
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class IpTablesManager method getCurrentFirewallState.
public static List<FirewallRecord> getCurrentFirewallState(OpsTarget target, Transport transport) throws OpsException {
Command command = getIptablesCommand(transport);
command.addLiteral("--list-rules");
List<FirewallRecord> records = Lists.newArrayList();
ProcessExecution execution = target.executeCommand(command);
String stdout = execution.getStdOut();
for (String line : stdout.split("\n")) {
parseAndAdd(records, line);
}
return records;
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class IpTablesManager method buildCommandAddFirewallRule.
public static Command buildCommandAddFirewallRule(OpsTarget server, FirewallRecord add) throws OpsException {
if (isPolicyDefault(add)) {
Command command = getIptablesCommand(add.getTransport());
command.addLiteral("-P");
command.addLiteral(toChain(add));
command.addLiteral(toIpTableDecision(add.decision));
return command;
}
// iptables --append INPUT -s 74.125.67.103/32 -p tcp -m tcp --dport 22 -j ACCEPT
String action;
// Passes take precedence
switch(add.decision) {
case Pass:
action = " --insert " + toChain(add) + " 1 ";
break;
case Block:
action = " --append " + toChain(add);
break;
default:
throw new IllegalStateException();
}
String ipTableRule = buildIpTableRule(add);
String commandString = getIptablesCommand(add.getTransport()).buildCommandString() + action + ipTableRule;
Command command = Command.build(commandString);
return command;
}
Aggregations