mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
17.24.2021 1c9178997dd15d65b5f84b4870b3e54caa30ff61
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package de.micromata.borgbutler.config;
 
import com.fasterxml.jackson.annotation.JsonIgnore;
import de.micromata.borgbutler.json.JsonUtils;
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.
     */
    private String displayName;
    private String repo;
    private String rsh;
    private String passphrase;
    private String passwordCommand;
    private String id;
 
    @JsonIgnore
    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);
    }
 
    public void copyFrom(BorgRepoConfig other) {
        this.displayName = other.displayName;
        this.repo = other.repo;
        this.rsh = other.rsh;
        this.passphrase = other.passphrase;
        this.passwordCommand = other.passwordCommand;
    }
 
    public String getDisplayName() {
        return this.displayName;
    }
 
    public String getRepo() {
        return this.repo;
    }
 
    public String getRsh() {
        return this.rsh;
    }
 
    public String getPassphrase() {
        return this.passphrase;
    }
 
    public String getPasswordCommand() {
        return this.passwordCommand;
    }
 
    public String getId() {
        return this.id;
    }
 
    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }
 
    public void setRepo(String repo) {
        this.repo = repo;
    }
 
    public void setRsh(String rsh) {
        this.rsh = rsh;
    }
 
    public void setPassphrase(String passphrase) {
        this.passphrase = passphrase;
    }
 
    public void setPasswordCommand(String passwordCommand) {
        this.passwordCommand = passwordCommand;
    }
 
    public void setId(String id) {
        this.id = id;
    }
 
    @Override
    public String toString() {
        return JsonUtils.toJson(this);
    }
}