-
Notifications
You must be signed in to change notification settings - Fork 1
/
nexus-repo.go
62 lines (50 loc) · 1.43 KB
/
nexus-repo.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
// SPDX-License-Identifier: Apache-2.0
// (c) 2024, Konstantin Demin
package main
import (
"context"
"encoding/json"
"errors"
"net/http"
"github.com/rs/zerolog/log"
)
type NexusRepo struct {
Name string `json:"name"`
Format string `json:"format"`
Type string `json:"type"`
Attributes map[string]string `json:"attributes,omitempty"`
}
func (p *Plugin) GetNexusRepo(ctx context.Context, repoName string) (NexusRepo, error) {
if repoName == "" {
log.Panic().Msg("empty repository name")
}
var empty NexusRepo
res, err := p.NexusRequest(ctx, "v1/repositories/"+repoName)
if err != nil {
log.Error().Msgf("unable to retrieve information for repository %q", repoName)
return empty, err
}
defer res.Body.Close()
if res.StatusCode == http.StatusNotFound {
log.Error().Msgf("repository %q does not exist", repoName)
return empty, errors.New("notfound")
}
err = GenericResponseHandler(res)
if err != nil {
log.Error().Msgf("unable to retrieve information for repository %q", repoName)
return empty, err
}
var repo NexusRepo
dec := json.NewDecoder(res.Body)
err = dec.Decode(&repo)
if err != nil {
log.Error().Msgf("unable to decode information for repository %q", repoName)
return empty, err
}
switch repo.Type {
case "proxy", "group":
log.Error().Msgf("repository %q is type of %q", repoName, repo.Type)
return empty, errors.ErrUnsupported
}
return repo, nil
}