-
Notifications
You must be signed in to change notification settings - Fork 58
/
props.go
103 lines (91 loc) · 2.62 KB
/
props.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
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
103
package generic
import (
"errors"
"github.com/jfrog/jfrog-cli-core/artifactory/spec"
"github.com/jfrog/jfrog-cli-core/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/utils/config"
"github.com/jfrog/jfrog-cli-core/utils/coreutils"
"github.com/jfrog/jfrog-client-go/artifactory"
"github.com/jfrog/jfrog-client-go/artifactory/services"
clientConfig "github.com/jfrog/jfrog-client-go/config"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/content"
"github.com/jfrog/jfrog-client-go/utils/log"
)
type PropsCommand struct {
props string
threads int
GenericCommand
}
func NewPropsCommand() *PropsCommand {
return &PropsCommand{GenericCommand: *NewGenericCommand()}
}
func (pc *PropsCommand) Threads() int {
return pc.threads
}
func (pc *PropsCommand) SetThreads(threads int) *PropsCommand {
pc.threads = threads
return pc
}
func (pc *PropsCommand) Props() string {
return pc.props
}
func (pc *PropsCommand) SetProps(props string) *PropsCommand {
pc.props = props
return pc
}
func createPropsServiceManager(threads int, serverDetails *config.ServerDetails) (artifactory.ArtifactoryServicesManager, error) {
certsPath, err := coreutils.GetJfrogCertsDir()
if err != nil {
return nil, err
}
artAuth, err := serverDetails.CreateArtAuthConfig()
if err != nil {
return nil, err
}
serviceConfig, err := clientConfig.NewConfigBuilder().
SetServiceDetails(artAuth).
SetCertificatesPath(certsPath).
SetInsecureTls(serverDetails.InsecureTls).
SetThreads(threads).
Build()
return artifactory.New(serviceConfig)
}
func searchItems(spec *spec.SpecFiles, servicesManager artifactory.ArtifactoryServicesManager) (resultReader *content.ContentReader, err error) {
var errorOccurred = false
temp := []*content.ContentReader{}
defer func() {
for _, reader := range temp {
reader.Close()
}
}()
for i := 0; i < len(spec.Files); i++ {
searchParams, err := utils.GetSearchParams(spec.Get(i))
if err != nil {
errorOccurred = true
log.Error(err)
continue
}
reader, err := servicesManager.SearchFiles(searchParams)
if err != nil {
errorOccurred = true
log.Error(err)
continue
}
temp = append(temp, reader)
}
resultReader, err = content.MergeReaders(temp, content.DefaultKey)
if err != nil {
return
}
if errorOccurred {
err = errorutils.CheckError(errors.New("Operation finished with errors, please review the logs."))
}
return
}
func GetPropsParams(reader *content.ContentReader, properties string) (propsParams services.PropsParams) {
propsParams = services.NewPropsParams()
propsParams.Reader = reader
propsParams.Props = properties
return
}