pr-karasz-corewrap #59

Closed
karasz wants to merge 2 commits from pr-karasz-corewrap into main
  1. 2
      Makefile
  2. 4
      cmd/jpictl/dns.go
  3. 6
      pkg/ceph/config_parser.go
  4. 6
      pkg/cluster/cluster_scan.go
  5. 8
      pkg/cluster/machine_rings.go
  6. 4
      pkg/cluster/machine_scan.go
  7. 2
      pkg/dns/manager.go
  8. 12
      pkg/wireguard/config_parser.go

2
Makefile

@ -10,7 +10,7 @@ TOOLSDIR := $(CURDIR)/pkg/tools
TMPDIR ?= $(CURDIR)/.tmp TMPDIR ?= $(CURDIR)/.tmp
OUTDIR ?= $(TMPDIR) OUTDIR ?= $(TMPDIR)
GOLANGCI_LINT_VERSION ?= v1.59.1 GOLANGCI_LINT_VERSION ?= v1.60.0
REVIVE_VERSION ?= v1.3.7 REVIVE_VERSION ?= v1.3.7
GOLANGCI_LINT_URL ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) GOLANGCI_LINT_URL ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

4
cmd/jpictl/dns.go

@ -163,9 +163,9 @@ var dnsAddCmd = &cobra.Command{
addr, err := core.ParseAddr(s) addr, err := core.ParseAddr(s)
switch { switch {
case err != nil: case err != nil:
return core.Wrap(err, s) return core.Wrap(err, "cannot parse address %q", s)
case !addr.IsValid(), addr.IsUnspecified(), addr.IsPrivate(), addr.IsMulticast(): case !addr.IsValid(), addr.IsUnspecified(), addr.IsPrivate(), addr.IsMulticast():
return core.Wrap(core.ErrInvalid, s) return core.Wrap(core.ErrInvalid, "address %q is invalid", s)
default: default:
addrs = append(addrs, addr) addrs = append(addrs, addr)
} }

6
pkg/ceph/config_parser.go

@ -54,7 +54,7 @@ func loadGlobalConfField(cfg *GlobalConfig, field basic.Field) error {
err := cfg.FSID.UnmarshalText([]byte(field.Value)) err := cfg.FSID.UnmarshalText([]byte(field.Value))
switch { switch {
case err != nil: case err != nil:
return core.Wrap(err, field.Key) return core.Wrap(err, "unmarshal failed on field %q", field.Key)
default: default:
return nil return nil
} }
@ -64,7 +64,7 @@ func loadGlobalConfField(cfg *GlobalConfig, field basic.Field) error {
var addr netip.Addr var addr netip.Addr
if err := addr.UnmarshalText([]byte(s)); err != nil { if err := addr.UnmarshalText([]byte(s)); err != nil {
return core.Wrap(err, field.Key) return core.Wrap(err, "unmarshal failed on field %q", field.Key)
} }
cfg.MonitorsAddr = append(cfg.MonitorsAddr, addr) cfg.MonitorsAddr = append(cfg.MonitorsAddr, addr)
@ -83,7 +83,7 @@ func loadGlobalConfField(cfg *GlobalConfig, field basic.Field) error {
err := cfg.ClusterNetwork.UnmarshalText([]byte(field.Value)) err := cfg.ClusterNetwork.UnmarshalText([]byte(field.Value))
switch { switch {
case err != nil: case err != nil:
return core.Wrap(err, field.Key) return core.Wrap(err, "unmarshal failed on field %q", field.Key)
default: default:
return nil return nil
} }

6
pkg/cluster/cluster_scan.go

@ -51,7 +51,7 @@ func (m *Cluster) scanDirectory(opts *ScanOptions) error {
ok, err := m.scanSubdirectory(opts, e.Name()) ok, err := m.scanSubdirectory(opts, e.Name())
switch { switch {
case err != nil: case err != nil:
return core.Wrap(err, e.Name()) return core.Wrap(err, "cannot scan directory %q", e.Name())
case !ok: case !ok:
m.warn(nil). m.warn(nil).
WithField("zone", e.Name()). WithField("zone", e.Name()).
@ -220,7 +220,7 @@ func (z *Zone) loadRegions() error {
// parsed // parsed
err = z.appendRegions(regions...) err = z.appendRegions(regions...)
if err != nil { if err != nil {
err = core.Wrap(err, filename) err = core.Wrap(err, "cannot append region from file %q", filename)
} }
} }
@ -247,7 +247,7 @@ func (z *Zone) loadClusterToken() error {
err = z.zones.setRegionClusterToken(z.Name, token) err = z.zones.setRegionClusterToken(z.Name, token)
if err != nil { if err != nil {
err = core.Wrap(err, filename) err = core.Wrap(err, "wrong cluster token in file %q", filename)
} }
return err return err

8
pkg/cluster/machine_rings.go

@ -36,7 +36,7 @@ func (m *Machine) GetWireguardKeys(ringID rings.RingID) (wireguard.KeyPair, erro
out.PrivateKey, err = wireguard.PrivateKeyFromBase64(string(data)) out.PrivateKey, err = wireguard.PrivateKeyFromBase64(string(data))
if err != nil { if err != nil {
// bad key // bad key
err = core.Wrap(err, keyFile) err = core.Wrap(err, "bad private key in file %q", keyFile)
return out, err return out, err
} }
@ -52,7 +52,7 @@ func (m *Machine) GetWireguardKeys(ringID rings.RingID) (wireguard.KeyPair, erro
out.PublicKey, err = wireguard.PublicKeyFromBase64(string(data)) out.PublicKey, err = wireguard.PublicKeyFromBase64(string(data))
if err != nil { if err != nil {
// bad key // bad key
err = core.Wrap(err, pubFile) err = core.Wrap(err, "bad public key in %q", pubFile)
return out, err return out, err
} }
} }
@ -227,10 +227,10 @@ func (m *Machine) applyWireguardPeerConfig(ring rings.RingID,
switch { switch {
case !found: case !found:
// unknown // unknown
return core.Wrap(ErrUnknownNode, pc.Endpoint.Host) return core.Wrap(ErrUnknownNode, "peer %q not found", pc.Endpoint.Host)
case ring == 1 && m.zone != peer.zone: case ring == 1 && m.zone != peer.zone:
// invalid zone // invalid zone
return core.Wrap(ErrInvalidNode, peer.Name) return core.Wrap(ErrInvalidNode, "peer %q invalid zone", peer.Name)
default: default:
// apply RingInfo // apply RingInfo
ri := &RingInfo{ ri := &RingInfo{

4
pkg/cluster/machine_scan.go

@ -36,12 +36,12 @@ func (m *Machine) UpdatePublicAddresses() error {
func (m *Machine) init() error { func (m *Machine) init() error {
if err := m.setID(); err != nil { if err := m.setID(); err != nil {
return core.Wrap(err, m.Name) return core.Wrap(err, "cannot set ID for machine %q", m.Name)
} }
for _, ring := range Rings { for _, ring := range Rings {
if err := m.tryReadWireguardKeys(ring.ID); err != nil { if err := m.tryReadWireguardKeys(ring.ID); err != nil {
return core.Wrap(err, m.Name) return core.Wrap(err, "cannot read keys for machine %q", m.Name)
} }
} }

2
pkg/dns/manager.go

@ -30,7 +30,7 @@ type ManagerOption func(*Manager) error
func newErrorManagerOption(err error, hint string) ManagerOption { func newErrorManagerOption(err error, hint string) ManagerOption {
return func(*Manager) error { return func(*Manager) error {
return core.Wrap(err, hint) return core.Wrap(err, "%q", hint)
} }
} }

12
pkg/wireguard/config_parser.go

@ -65,7 +65,7 @@ func loadInterfaceConfField(cfg *InterfaceConfig, field basic.Field) error {
err := cfg.Address.UnmarshalText([]byte(field.Value)) err := cfg.Address.UnmarshalText([]byte(field.Value))
switch { switch {
case err != nil: case err != nil:
return core.Wrap(err, field.Key) return core.Wrap(err, "unmarshal failed on field %q", field.Key)
default: default:
return nil return nil
} }
@ -77,7 +77,7 @@ func loadInterfaceConfField(cfg *InterfaceConfig, field basic.Field) error {
err := cfg.PrivateKey.UnmarshalText([]byte(field.Value)) err := cfg.PrivateKey.UnmarshalText([]byte(field.Value))
switch { switch {
case err != nil: case err != nil:
return core.Wrap(err, field.Key) return core.Wrap(err, "unmarshal failed on field %q", field.Key)
default: default:
return nil return nil
} }
@ -89,7 +89,7 @@ func loadInterfaceConfField(cfg *InterfaceConfig, field basic.Field) error {
u64, err := strconv.ParseUint(field.Value, 10, 16) u64, err := strconv.ParseUint(field.Value, 10, 16)
switch { switch {
case err != nil: case err != nil:
return core.Wrap(err, field.Key) return core.Wrap(err, "field %q is not an integer", field.Key)
case u64 == 0: case u64 == 0:
return core.Wrap(fs.ErrInvalid, "invalid %q value", field.Key) return core.Wrap(fs.ErrInvalid, "invalid %q value", field.Key)
default: default:
@ -117,7 +117,7 @@ func loadPeerConfField(cfg *PeerConfig, field basic.Field) error {
err := cfg.PublicKey.UnmarshalText([]byte(field.Value)) err := cfg.PublicKey.UnmarshalText([]byte(field.Value))
switch { switch {
case err != nil: case err != nil:
return core.Wrap(err, field.Key) return core.Wrap(err, "unmarshal failed on field %q", field.Key)
default: default:
return nil return nil
} }
@ -129,7 +129,7 @@ func loadPeerConfField(cfg *PeerConfig, field basic.Field) error {
err := cfg.Endpoint.UnmarshalText([]byte(field.Value)) err := cfg.Endpoint.UnmarshalText([]byte(field.Value))
switch { switch {
case err != nil: case err != nil:
return core.Wrap(err, field.Key) return core.Wrap(err, "unmarshal failed on field %q", field.Key)
default: default:
return nil return nil
} }
@ -137,7 +137,7 @@ func loadPeerConfField(cfg *PeerConfig, field basic.Field) error {
s, err := parseAllowedIPs(field.Value) s, err := parseAllowedIPs(field.Value)
switch { switch {
case err != nil: case err != nil:
return core.Wrap(err, field.Key) return core.Wrap(err, "%q is not an IP", field.Key)
case len(s) > 0: case len(s) > 0:
cfg.AllowedIPs = append(cfg.AllowedIPs, s...) cfg.AllowedIPs = append(cfg.AllowedIPs, s...)
return nil return nil

Loading…
Cancel
Save