/
repositories_maven.go
122 lines (106 loc) · 4.01 KB
/
repositories_maven.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
// Copyright 2020 Aicura Nexus Client and/or its authors
//
// This file is part of Aicura Nexus Client.
//
// Aicura Nexus Client is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Aicura Nexus Client is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Aicura Nexus Client. If not, see <https://www.gnu.org/licenses/>.
package nexus
import "encoding/json"
const repositoriesMavenProxyPath = "/repositories/maven/proxy"
// MavenVersionPolicy ...
type MavenVersionPolicy string
const (
// VersionPolicyRelease ...
VersionPolicyRelease MavenVersionPolicy = "RELEASE"
// VersionPolicyMixed ...
VersionPolicyMixed MavenVersionPolicy = "MIXED"
// VersionPolicySnapshot ...
VersionPolicySnapshot MavenVersionPolicy = "SNAPSHOT"
)
// MavenLayoutPolicy ...
type MavenLayoutPolicy string
const (
// LayoutPolicyStrict ...
LayoutPolicyStrict MavenLayoutPolicy = "STRICT"
// LayoutPolicyPermissive ...
LayoutPolicyPermissive MavenLayoutPolicy = "PERMISSIVE"
)
// Maven ...
type Maven struct {
VersionPolicy MavenVersionPolicy `json:"versionPolicy,omitempty"`
LayoutPolicy MavenLayoutPolicy `json:"layoutPolicy,omitempty"`
}
// HTTPClient details of how to connect to a Maven Proxy Repository
type HTTPClient struct {
AutoBlock bool `json:"autoBlock,omitempty"`
Blocked *bool `json:"blocked,omitempty"`
Connection *Connection `json:"connection,omitempty"`
Authentication *Authentication `json:"authentication,omitempty"`
}
// Connection for a HTTPClient
type Connection struct {
Retries *int `json:"retries,omitempty"`
UserAgentSuffix *string `json:"userAgentSuffix,omitempty"`
Timeout *int32 `json:"timeout,omitempty"`
EnableCircularRedirects bool `json:"enableCircularRedirects,omitempty"`
EnableCookies bool `json:"enableCookies,omitempty"`
}
// Authentication for a HTTPClient
type Authentication struct {
Type string `json:"type,omitempty"`
Username string `json:"username,omitempty"`
NtlmHost string `json:"ntlmHost,omitempty"`
NtlmDomain string `json:"ntlmDomain,omitempty"`
}
// MavenProxyRepository basic structure for a Maven Proxy Repository
type MavenProxyRepository struct {
Repository `json:",inline"`
HTTPClient HTTPClient `json:"httpClient,omitempty"`
Maven Maven `json:"maven,omitempty"`
NegativeCache NegativeCache `json:"negativeCache,omitempty"`
Proxy Proxy `json:"proxy,omitempty"`
Storage Storage `json:"storage,omitempty"`
CleanUp *CleanUp `json:"cleanup,omitempty"`
RoutingRule string `json:"routingRule,omitempty"`
}
// MavenGroupRepository structure for Maven Group Repository
type MavenGroupRepository struct {
Repository `json:",inline"`
Group MavenGroup `json:"group"`
Storage Storage `json:"storage,omitempty"`
}
// MavenGroup describes a collection of Maven repositories in a given group
type MavenGroup struct {
MemberNames []string `json:"memberNames"`
}
type mavenRepositoryService service
func (m *mavenRepositoryService) list(repoType RepositoryType, unmarshalValue interface{}) error {
req, err := m.client.get(m.client.appendVersion(repositoriesPath), "")
if err != nil {
return err
}
var jsonRepos json.RawMessage
_, err = m.client.do(req, &jsonRepos)
if err != nil {
return err
}
filtered, err := filterRepository(jsonRepos, RepositoryFormatMaven2, repoType)
if err != nil {
return err
}
if filtered != nil {
err = json.Unmarshal(filtered, unmarshalValue)
return err
}
return nil
}