/
replaces3url.go
74 lines (64 loc) · 1.67 KB
/
replaces3url.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package upgradeinspectorv4
import (
"fmt"
"regexp"
"github.com/chef/automate/components/automate-deployment/pkg/cli"
"github.com/chef/automate/components/automate-deployment/pkg/inspector"
"github.com/fatih/color"
)
type ReplaceS3UrlInspection struct {
writer *cli.Writer
upgradeUtils UpgradeV4Utils
timeout int64
exitError error
exitedWithError bool
}
const (
S3_REGEX = "https?://s3.(.*).amazonaws.com"
NEW_S3_URL = "https://s3.amazonaws.com"
)
func NewReplaceS3UrlInspection(w *cli.Writer, utls UpgradeV4Utils, timeout int64) *ReplaceS3UrlInspection {
return &ReplaceS3UrlInspection{
writer: w,
upgradeUtils: utls,
timeout: timeout,
}
}
func (ru *ReplaceS3UrlInspection) ShowInfo(index *int) error {
return nil
}
func (ru *ReplaceS3UrlInspection) Skip() {
return
}
func (ru *ReplaceS3UrlInspection) GetShortInfo() []string {
return nil
}
func (ru *ReplaceS3UrlInspection) Inspect() (err error) {
endpoint, err := ru.upgradeUtils.GetBackupS3URL(ru.timeout)
if err != nil {
ru.setExitError(err)
return err
}
re := regexp.MustCompile(S3_REGEX)
if re.MatchString(endpoint) {
_, _, err := ru.upgradeUtils.PatchS3backupURL(ru.timeout)
if err != nil {
ru.setExitError(err)
return err
}
}
return nil
}
func (ru *ReplaceS3UrlInspection) setExitError(err error) {
ru.exitError = err
ru.exitedWithError = true
}
func (ru *ReplaceS3UrlInspection) GetInstallationType() inspector.InstallationType {
return inspector.BOTH
}
func (ru *ReplaceS3UrlInspection) ExitHandler() error {
if ru.exitedWithError {
ru.writer.Println(fmt.Errorf("["+color.New(color.FgRed).Sprint("Error")+"] %w", ru.exitError).Error())
}
return nil
}