-
Notifications
You must be signed in to change notification settings - Fork 17
/
cmd.go
67 lines (55 loc) · 1.8 KB
/
cmd.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
package artifacts
import (
"errors"
"time"
"github.com/saucelabs/saucectl/internal/artifacts"
"github.com/saucelabs/saucectl/internal/config"
"github.com/saucelabs/saucectl/internal/credentials"
"github.com/saucelabs/saucectl/internal/http"
"github.com/saucelabs/saucectl/internal/region"
"github.com/saucelabs/saucectl/internal/saucecloud"
"github.com/saucelabs/saucectl/internal/segment"
"github.com/spf13/cobra"
)
var (
artifactSvc artifacts.Service
rdcTimeout = 1 * time.Minute
restoTimeout = 1 * time.Minute
testComposerTimeout = 1 * time.Minute
)
func Command(preRun func(cmd *cobra.Command, args []string)) *cobra.Command {
var regio string
cmd := &cobra.Command{
Use: "artifacts",
Short: "Interact with job artifacts",
SilenceUsage: true,
TraverseChildren: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if preRun != nil {
preRun(cmd, args)
}
reg := region.FromString(regio)
if reg == region.None {
return errors.New("invalid region")
}
if reg == region.Staging {
segment.DefaultTracker.Enabled = false
}
creds := credentials.Get()
url := reg.APIBaseURL()
restoClient := http.NewResto(url, creds.Username, creds.AccessKey, restoTimeout)
rdcClient := http.NewRDCService(url, creds.Username, creds.AccessKey, rdcTimeout, config.ArtifactDownload{})
testcompClient := http.NewTestComposer(url, creds, testComposerTimeout)
artifactSvc = saucecloud.NewArtifactService(&restoClient, &rdcClient, &testcompClient)
return nil
},
}
flags := cmd.PersistentFlags()
flags.StringVarP(®io, "region", "r", "us-west-1", "The Sauce Labs region. Options: us-west-1, eu-central-1.")
cmd.AddCommand(
DownloadCommand(),
ListCommand(),
UploadCommand(),
)
return cmd
}