forked from gobackup/gobackup
/
base.go
53 lines (45 loc) 路 1.08 KB
/
base.go
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
package encryptor
import (
"github.com/auzty/gobackup/config"
"github.com/auzty/gobackup/logger"
"github.com/spf13/viper"
)
// Base encryptor
type Base struct {
model config.ModelConfig
viper *viper.Viper
archivePath string
}
// Context encryptor interface
type Context interface {
perform() (encryptPath string, err error)
}
func newBase(archivePath string, model config.ModelConfig) (base Base) {
base = Base{
archivePath: archivePath,
model: model,
viper: model.EncryptWith.Viper,
}
return
}
// Run compressor
func Run(archivePath string, model config.ModelConfig) (encryptPath string, err error) {
base := newBase(archivePath, model)
var ctx Context
switch model.EncryptWith.Type {
case "openssl":
ctx = &OpenSSL{Base: base}
default:
encryptPath = archivePath
return
}
logger.Info("------------ Encryptor -------------")
logger.Info("=> Encrypt | " + model.EncryptWith.Type)
encryptPath, err = ctx.perform()
if err != nil {
return
}
logger.Info("->", encryptPath)
logger.Info("------------ Encryptor -------------\n")
return
}