Environment variables are now built by BorgRepoConfig itself.
| | |
| | | return null; |
| | | } |
| | | Map<String, String> env = EnvironmentUtils.getProcEnvironment(); |
| | | addEnvironmentVariable(env, "BORG_REPO", repoConfig.getRepo()); |
| | | addEnvironmentVariable(env, "BORG_RSH", repoConfig.getRsh()); |
| | | addEnvironmentVariable(env, "BORG_PASSPHRASE", repoConfig.getPassphrase()); |
| | | String passcommand = repoConfig.getPasswordCommand(); |
| | | if (StringUtils.isNotBlank(passcommand)) { |
| | | String[] variables = repoConfig.getEnvironmentVariables(true); |
| | | for (String variable : variables) { |
| | | // For MacOS BORG_PASSCOMMAND="security find-generic-password -a $USER -s borg-passphrase -w" |
| | | passcommand = passcommand.replace("$USER", System.getProperty("user.name")); |
| | | addEnvironmentVariable(env, "BORG_PASSCOMMAND", passcommand); |
| | | String environmentVariable = variable.replace("$USER", System.getProperty("user.name")); |
| | | addEnvironmentVariable(env, environmentVariable); |
| | | } |
| | | return env; |
| | | } |
| | |
| | | @Override |
| | | public BorgJob<?> clone() { |
| | | BorgJob<?> clone = new BorgJob<>(); |
| | | if (command != null) { |
| | | // Needed for getting environment variables: JsonJob of borgbutler-server. |
| | | clone.command = new BorgCommand().setRepoConfig(command.getRepoConfig()); |
| | | } |
| | | clone.setUniqueJobNumber(getUniqueJobNumber()); |
| | | clone.setTitle(getTitle()); |
| | | clone.setExecuteStarted(isExecuteStarted()); |
| | |
| | | package de.micromata.borgbutler.config; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonIgnore; |
| | | import com.fasterxml.jackson.annotation.JsonProperty; |
| | | import lombok.Getter; |
| | | import lombok.Setter; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class BorgRepoConfig { |
| | | /** |
| | | * A name describing this config. Only used for displaying purposes. |
| | | */ |
| | | @Getter @Setter |
| | | @Getter |
| | | @Setter |
| | | private String displayName; |
| | | @Getter @Setter |
| | | @Getter |
| | | @Setter |
| | | private String repo; |
| | | @Getter @Setter |
| | | @Getter |
| | | @Setter |
| | | private String rsh; |
| | | @Getter @Setter |
| | | @Getter |
| | | @Setter |
| | | private String passphrase; |
| | | @Getter @Setter |
| | | @Getter |
| | | @Setter |
| | | private String passwordCommand; |
| | | @Getter @Setter |
| | | @Getter |
| | | @Setter |
| | | @JsonIgnore |
| | | private String id; |
| | | |
| | | public String[] getEnvironmentVariables() { |
| | | return getEnvironmentVariables(false); |
| | | } |
| | | |
| | | public String[] getEnvironmentVariables(boolean showPassphrase) { |
| | | List<String> variables = new ArrayList<>(); |
| | | addVariable(variables, "BORG_REPO", repo); |
| | | addVariable(variables, "BORG_RSH", rsh); |
| | | if (StringUtils.isNotBlank(passphrase)) { |
| | | addVariable(variables, "BORG_PASSPHRASE", showPassphrase ? passphrase : "******"); |
| | | } |
| | | addVariable(variables, "BORG_PASSCOMMAND", passwordCommand); |
| | | return variables.toArray(new String[variables.size()]); |
| | | } |
| | | |
| | | private void addVariable(List<String> list, String variable, String value) { |
| | | if (StringUtils.isBlank(value)) return; |
| | | list.add(variable + "=" + value); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param env |
| | | * @param variable Variable in format "variable=value". |
| | | */ |
| | | protected void addEnvironmentVariable(Map<String, String> env, String variable) { |
| | | if (StringUtils.isNotBlank(variable)) { |
| | | EnvironmentUtils.addVariableToEnvironment(env, variable); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Frees the output streams. |
| | | * Should be called after a job was done, failed or cancelled while running. |
| | | */ |
| | | public void cleanUp() { |
| | | log.info("Freeing resources of job: " + commandLineAsString); |
| | | log.debug("Freeing resources of job: " + commandLineAsString); |
| | | outputStream = null; |
| | | errorOutputStream = null; |
| | | } |