-
Notifications
You must be signed in to change notification settings - Fork 1
/
nexus-status.go
61 lines (51 loc) · 1.43 KB
/
nexus-status.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
// SPDX-License-Identifier: Apache-2.0
// (c) 2024, Konstantin Demin
package main
import (
"context"
"encoding/json"
"errors"
"github.com/rs/zerolog/log"
)
type ReadOnlyStatus struct {
Frozen bool `json:"frozen"`
SystemInitiated bool `json:"systemInitiated"`
Reason string `json:"summaryReason"`
}
func (p *Plugin) GetNexusStatus(ctx context.Context) error {
res, err := p.NexusRequest(ctx, "v1/status/writable")
if err == nil {
defer res.Body.Close()
err = GenericResponseHandler(res)
}
if err != nil {
log.Error().Msg("Nexus is not writable")
return err
}
res, err = p.NexusRequest(ctx, "v1/read-only")
if err == nil {
defer res.Body.Close()
err = GenericResponseHandler(res)
}
if err != nil {
log.Error().Msg("Nexus is unable to report it's \"read-only\" status")
return err
}
var roStatus ReadOnlyStatus
dec := json.NewDecoder(res.Body)
err = dec.Decode(&roStatus)
if err != nil {
log.Error().Msg("unable to decode information for \"read-only\" status")
return err
}
if roStatus.Frozen {
if roStatus.Reason == "" {
log.Error().Msgf("Nexus is read-only (system-initiated: %v)", roStatus.SystemInitiated)
} else {
log.Error().Msgf("Nexus is read-only (system-initiated: %v), reason: %q", roStatus.SystemInitiated, roStatus.Reason)
}
return errors.New("readonly")
}
//TODO: determine early whether supplied credentials allows one to proceed with Sonatype Nexus
return nil
}