forked from sonatype-nexus-community/gonexus
/
groovyRepository.go
207 lines (188 loc) · 8.76 KB
/
groovyRepository.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package nexusrm
import (
"bytes"
"fmt"
"text/template"
)
const (
groovyCreateHostedMaven = "repository.createMavenHosted('{{.Name}}'{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateHostedNpm = "repository.createNpmHosted('{{.Name}}'{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateHostedNuget = "repository.createNugetHosted('{{.Name}}'{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateHostedApt = "repository.createAptHosted('{{.Name}}'{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateHostedDocker = "repository.createDockerHosted('{{.Name}}'{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateHostedGolang = "repository.createGolangHosted('{{.Name}}'{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateHostedRaw = "repository.createRawHosted('{{.Name}}'{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateHostedRubygems = "repository.createRubygemsHosted('{{.Name}}'{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateHostedBower = "repository.createBowerHosted('{{.Name}}'{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateHostedPypi = "repository.createPypiHosted('{{.Name}}'{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateHostedYum = "repository.createYumHosted('{{.Name}}'{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateHostedGitLfs = "repository.createGitLfsHosted('{{.Name}}'{{with .BlobStore}}, '{{.}}'{{end}})"
)
type repositoryHosted struct {
Name, BlobStore string
StrictContentTypeValidation bool
// versionPolicy VersionPolicy
// writePolicy WritePolicy
// layoutPolicy LayoutPolicy
}
const (
groovyCreateProxyMaven = "repository.createMavenProxy('{{.Name}}'{{with .RemoteURL}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateProxyNpm = "repository.createNpmProxy('{{.Name}}'{{with .RemoteURL}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateProxyNuget = "repository.createNugetProxy('{{.Name}}'{{with .RemoteURL}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateProxyApt = "repository.createAptProxy('{{.Name}}'{{with .RemoteURL}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateProxyDocker = "repository.createDockerProxy('{{.Name}}'{{with .RemoteURL}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateProxyGolang = "repository.createGolangProxy('{{.Name}}'{{with .RemoteURL}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateProxyRaw = "repository.createRawProxy('{{.Name}}'{{with .RemoteURL}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateProxyRubygems = "repository.createRubygemsProxy('{{.Name}}'{{with .RemoteURL}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateProxyBower = "repository.createBowerProxy('{{.Name}}'{{with .RemoteURL}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateProxyPypi = "repository.createPypiProxy('{{.Name}}'{{with .RemoteURL}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateProxyYum = "repository.createYumProxy('{{.Name}}'{{with .RemoteURL}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateProxyGitLfs = "repository.createGitLfsProxy('{{.Name}}'{{with .RemoteURL}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
)
type repositoryProxy struct {
Name, RemoteURL, BlobStore string
StrictContentTypeValidation bool
// versionPolicy VersionPolicy
// layoutPolicy LayoutPolicy
}
const (
groovyCreateGroupMaven = "repository.createMavenGroup('{{.Name}}'{{with .Members}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateGroupNpm = "repository.createNpmGroup('{{.Name}}'{{with .Members}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateGroupNuget = "repository.createNugetGroup('{{.Name}}'{{with .Members}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateGroupApt = "repository.createAptGroup('{{.Name}}'{{with .Members}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateGroupDocker = "repository.createDockerGroup('{{.Name}}'{{with .Members}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateGroupGolang = "repository.createGolangGroup('{{.Name}}'{{with .Members}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateGroupRaw = "repository.createRawGroup('{{.Name}}'{{with .Members}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateGroupRubygems = "repository.createRubygemsGroup('{{.Name}}'{{with .Members}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateGroupBower = "repository.createBowerGroup('{{.Name}}'{{with .Members}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateGroupPypi = "repository.createPypiGroup('{{.Name}}'{{with .Members}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateGroupYum = "repository.createYumGroup('{{.Name}}'{{with .Members}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
groovyCreateGroupGitLfs = "repository.createGitLfsGroup('{{.Name}}'{{with .Members}}, '{{.}}'{{end}}{{with .BlobStore}}, '{{.}}'{{end}})"
)
type repositoryGroup struct {
Name, BlobStore string
Members []string
}
// CreateHostedRepository creates a hosted repository of the indicated format
func CreateHostedRepository(rm RM, format repositoryFormat, config repositoryHosted) error {
var groovyTmpl string
switch format {
case Maven:
groovyTmpl = groovyCreateHostedMaven
case Npm:
groovyTmpl = groovyCreateHostedNpm
case Nuget:
groovyTmpl = groovyCreateHostedNuget
case Apt:
groovyTmpl = groovyCreateHostedApt
case Docker:
groovyTmpl = groovyCreateHostedDocker
case Golang:
groovyTmpl = groovyCreateHostedGolang
case Raw:
groovyTmpl = groovyCreateHostedRaw
case Rubygems:
groovyTmpl = groovyCreateHostedRubygems
case Bower:
groovyTmpl = groovyCreateHostedBower
case Pypi:
groovyTmpl = groovyCreateHostedPypi
case Yum:
groovyTmpl = groovyCreateHostedYum
case GitLfs:
groovyTmpl = groovyCreateHostedGitLfs
}
tmpl, err := template.New("hosted").Parse(groovyTmpl)
if err != nil {
return fmt.Errorf("could not parse template: %v", err)
}
buf := new(bytes.Buffer)
err = tmpl.Execute(buf, config)
if err != nil {
return fmt.Errorf("could not create hosted repository from template: %v", err)
}
_, err = ScriptRunOnce(rm, newAnonGroovyScript(buf.String()), nil)
return fmt.Errorf("could not create hosted repository: %v", err)
}
// CreateProxyRepository creates a proxy repository of the indicated format
func CreateProxyRepository(rm RM, format repositoryFormat, config repositoryProxy) error {
var groovyTmpl string
switch format {
case Maven:
groovyTmpl = groovyCreateProxyMaven
case Npm:
groovyTmpl = groovyCreateProxyNpm
case Nuget:
groovyTmpl = groovyCreateProxyNuget
case Apt:
groovyTmpl = groovyCreateProxyApt
case Docker:
groovyTmpl = groovyCreateProxyDocker
case Golang:
groovyTmpl = groovyCreateProxyGolang
case Raw:
groovyTmpl = groovyCreateProxyRaw
case Rubygems:
groovyTmpl = groovyCreateProxyRubygems
case Bower:
groovyTmpl = groovyCreateProxyBower
case Pypi:
groovyTmpl = groovyCreateProxyPypi
case Yum:
groovyTmpl = groovyCreateProxyYum
case GitLfs:
groovyTmpl = groovyCreateProxyGitLfs
}
tmpl, err := template.New("proxy").Parse(groovyTmpl)
if err != nil {
return fmt.Errorf("could not parse template: %v", err)
}
buf := new(bytes.Buffer)
err = tmpl.Execute(buf, config)
if err != nil {
return fmt.Errorf("could not create proxy repository from template: %v", err)
}
_, err = ScriptRunOnce(rm, newAnonGroovyScript(buf.String()), nil)
return fmt.Errorf("could not create proxy repository: %v", err)
}
// CreateGroupRepository creates a group repository of the indicated format
func CreateGroupRepository(rm RM, format repositoryFormat, config repositoryGroup) error {
var groovyTmpl string
switch format {
case Maven:
groovyTmpl = groovyCreateGroupMaven
case Npm:
groovyTmpl = groovyCreateGroupNpm
case Nuget:
groovyTmpl = groovyCreateGroupNuget
case Apt:
groovyTmpl = groovyCreateGroupApt
case Docker:
groovyTmpl = groovyCreateGroupDocker
case Golang:
groovyTmpl = groovyCreateGroupGolang
case Raw:
groovyTmpl = groovyCreateGroupRaw
case Rubygems:
groovyTmpl = groovyCreateGroupRubygems
case Bower:
groovyTmpl = groovyCreateGroupBower
case Pypi:
groovyTmpl = groovyCreateGroupPypi
case Yum:
groovyTmpl = groovyCreateGroupYum
case GitLfs:
groovyTmpl = groovyCreateGroupGitLfs
}
tmpl, err := template.New("group").Parse(groovyTmpl)
if err != nil {
return fmt.Errorf("could not parse template: %v", err)
}
buf := new(bytes.Buffer)
err = tmpl.Execute(buf, config)
if err != nil {
return fmt.Errorf("could not create group repository from template: %v", err)
}
_, err = ScriptRunOnce(rm, newAnonGroovyScript(buf.String()), nil)
return fmt.Errorf("could not create group repository: %v", err)
}