mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
chore: replace interface{} with any
This commit is contained in:
@@ -12,9 +12,9 @@ import (
|
||||
)
|
||||
|
||||
// StartStopComponents activate/deactivate components in order.
|
||||
func StartStopComponents(r *reporter.Reporter, daemonComponent daemon.Component, otherComponents []interface{}) error {
|
||||
components := append([]interface{}{r, daemonComponent}, otherComponents...)
|
||||
startedComponents := []interface{}{}
|
||||
func StartStopComponents(r *reporter.Reporter, daemonComponent daemon.Component, otherComponents []any) error {
|
||||
components := append([]any{r, daemonComponent}, otherComponents...)
|
||||
startedComponents := []any{}
|
||||
defer func() {
|
||||
for _, cmp := range startedComponents {
|
||||
if stopperC, ok := cmp.(stopper); ok {
|
||||
@@ -30,7 +30,7 @@ func StartStopComponents(r *reporter.Reporter, daemonComponent daemon.Component,
|
||||
return fmt.Errorf("unable to start component: %w", err)
|
||||
}
|
||||
}
|
||||
startedComponents = append([]interface{}{cmp}, startedComponents...)
|
||||
startedComponents = append([]any{cmp}, startedComponents...)
|
||||
}
|
||||
|
||||
r.Info().
|
||||
|
||||
@@ -55,7 +55,7 @@ func (c ComponentStartError) Start() error {
|
||||
func TestStartStopError(t *testing.T) {
|
||||
r := reporter.NewMock(t)
|
||||
daemonComponent := daemon.NewMock(t)
|
||||
otherComponents := []interface{}{
|
||||
otherComponents := []any{
|
||||
&ComponentStartStop{},
|
||||
&ComponentStop{},
|
||||
&ComponentStart{},
|
||||
@@ -67,7 +67,7 @@ func TestStartStopError(t *testing.T) {
|
||||
t.Error("StartStopComponents() did not trigger an error")
|
||||
}
|
||||
|
||||
expected := []interface{}{
|
||||
expected := []any{
|
||||
&ComponentStartStop{
|
||||
Startable: Startable{Started: true},
|
||||
Stopable: Stopable{Stopped: true},
|
||||
@@ -90,7 +90,7 @@ func TestStartStopError(t *testing.T) {
|
||||
func TestStartStop(t *testing.T) {
|
||||
r := reporter.NewMock(t)
|
||||
daemonComponent := daemon.NewMock(t)
|
||||
otherComponents := []interface{}{
|
||||
otherComponents := []any{
|
||||
&ComponentStartStop{},
|
||||
&ComponentStop{},
|
||||
&ComponentStart{},
|
||||
@@ -104,7 +104,7 @@ func TestStartStop(t *testing.T) {
|
||||
t.Errorf("StartStopComponents() error:\n%+v", err)
|
||||
}
|
||||
|
||||
expected := []interface{}{
|
||||
expected := []any{
|
||||
&ComponentStartStop{
|
||||
Startable: Startable{Started: true},
|
||||
Stopable: Stopable{Stopped: true},
|
||||
|
||||
@@ -35,7 +35,7 @@ type ConfigRelatedOptions struct {
|
||||
|
||||
// Parse parses the configuration file (if present) and the
|
||||
// environment variables into the provided configuration.
|
||||
func (c ConfigRelatedOptions) Parse(out io.Writer, component string, config interface{}) error {
|
||||
func (c ConfigRelatedOptions) Parse(out io.Writer, component string, config any) error {
|
||||
var rawConfig gin.H
|
||||
if cfgFile := c.Path; cfgFile != "" {
|
||||
if strings.HasPrefix(cfgFile, "http://") || strings.HasPrefix(cfgFile, "https://") {
|
||||
@@ -112,11 +112,11 @@ func (c ConfigRelatedOptions) Parse(out io.Writer, component string, config inte
|
||||
// build a map "squid -> purple -> quirk ->
|
||||
// 47". From AKVORADO_CFG_CMP_SQUID_3_PURPLE=47, we
|
||||
// build "squid[3] -> purple -> 47"
|
||||
var rawConfig interface{}
|
||||
var rawConfig any
|
||||
rawConfig = kv[1]
|
||||
for i := len(kk) - 1; i > 2; i-- {
|
||||
if index, err := strconv.Atoi(kk[i]); err == nil {
|
||||
newRawConfig := make([]interface{}, index+1)
|
||||
newRawConfig := make([]any, index+1)
|
||||
newRawConfig[index] = rawConfig
|
||||
rawConfig = newRawConfig
|
||||
} else {
|
||||
@@ -171,7 +171,7 @@ func (c ConfigRelatedOptions) Parse(out io.Writer, component string, config inte
|
||||
// the Reset() method if present.
|
||||
func DefaultHook() (mapstructure.DecodeHookFunc, func()) {
|
||||
disabled := false
|
||||
hook := func(from, to reflect.Value) (interface{}, error) {
|
||||
hook := func(from, to reflect.Value) (any, error) {
|
||||
if disabled {
|
||||
return from.Interface(), nil
|
||||
}
|
||||
@@ -217,7 +217,7 @@ func DefaultHook() (mapstructure.DecodeHookFunc, func()) {
|
||||
// non-nil slice. Like DefaultHook, it can be disabled.
|
||||
func ZeroSliceHook() (mapstructure.DecodeHookFunc, func()) {
|
||||
disabled := false
|
||||
hook := func(from, to reflect.Value) (interface{}, error) {
|
||||
hook := func(from, to reflect.Value) (any, error) {
|
||||
if disabled {
|
||||
return from.Interface(), nil
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ module2:
|
||||
"workers": 5,
|
||||
"intervalvalue": "20m0s",
|
||||
},
|
||||
"elements": []interface{}{
|
||||
"elements": []any{
|
||||
gin.H{
|
||||
"name": "first",
|
||||
"gauge": 67,
|
||||
@@ -356,7 +356,7 @@ invalid key "unused"`); diff != "" {
|
||||
}
|
||||
|
||||
func TestDefaultInSlice(t *testing.T) {
|
||||
try := func(t *testing.T, parse func(cmd.ConfigRelatedOptions, *bytes.Buffer) interface{}) {
|
||||
try := func(t *testing.T, parse func(cmd.ConfigRelatedOptions, *bytes.Buffer) any) {
|
||||
// Configuration file
|
||||
config := `---
|
||||
modules:
|
||||
@@ -434,7 +434,7 @@ modules:
|
||||
}
|
||||
}
|
||||
t.Run("without pointer", func(t *testing.T) {
|
||||
try(t, func(c cmd.ConfigRelatedOptions, out *bytes.Buffer) interface{} {
|
||||
try(t, func(c cmd.ConfigRelatedOptions, out *bytes.Buffer) any {
|
||||
parsed := struct {
|
||||
Modules []dummyConfiguration
|
||||
}{}
|
||||
@@ -445,7 +445,7 @@ modules:
|
||||
})
|
||||
})
|
||||
t.Run("with pointer", func(t *testing.T) {
|
||||
try(t, func(c cmd.ConfigRelatedOptions, out *bytes.Buffer) interface{} {
|
||||
try(t, func(c cmd.ConfigRelatedOptions, out *bytes.Buffer) any {
|
||||
parsed := struct {
|
||||
Modules []*dummyConfiguration
|
||||
}{}
|
||||
|
||||
@@ -51,7 +51,7 @@ containers started with the label "akvorado.conntrack.fix=1".`,
|
||||
addCommonHTTPHandlers(r, "conntrack-fixer", httpComponent)
|
||||
versionMetrics(r)
|
||||
|
||||
components := []interface{}{
|
||||
components := []any{
|
||||
httpComponent,
|
||||
conntrackFixerComponent,
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ func consoleStart(r *reporter.Reporter, config ConsoleConfiguration, checkOnly b
|
||||
}
|
||||
|
||||
// Start all the components.
|
||||
components := []interface{}{
|
||||
components := []any{
|
||||
httpComponent,
|
||||
clickhouseComponent,
|
||||
authenticationComponent,
|
||||
|
||||
@@ -124,7 +124,7 @@ func demoExporterStart(r *reporter.Reporter, config DemoExporterConfiguration, c
|
||||
}
|
||||
|
||||
// Start all the components.
|
||||
components := []interface{}{
|
||||
components := []any{
|
||||
httpComponent,
|
||||
snmpComponent,
|
||||
bmpComponent,
|
||||
|
||||
@@ -108,7 +108,7 @@ func inletStart(r *reporter.Reporter, config InletConfiguration, checkOnly bool)
|
||||
}
|
||||
|
||||
// Start all the components.
|
||||
components := []interface{}{
|
||||
components := []any{
|
||||
httpComponent,
|
||||
kafkaComponent,
|
||||
flowComponent,
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestOrchestratorConfig(t *testing.T) {
|
||||
t.Fatalf("ReadFile() error:\n%+v", err)
|
||||
}
|
||||
var expectedYAML struct {
|
||||
Paths map[string]interface{} `yaml:"paths"`
|
||||
Paths map[string]any `yaml:"paths"`
|
||||
}
|
||||
if err := yaml.Unmarshal(expected, &expectedYAML); err != nil {
|
||||
t.Fatalf("yaml.Unmarshal(expected) error:\n%+v", err)
|
||||
@@ -57,30 +57,30 @@ func TestOrchestratorConfig(t *testing.T) {
|
||||
if err := root.Execute(); err != nil {
|
||||
t.Fatalf("`orchestrator` command error:\n%+v", err)
|
||||
}
|
||||
var gotYAML map[string]interface{}
|
||||
var gotYAML map[string]any
|
||||
if err := yaml.Unmarshal(buf.Bytes(), &gotYAML); err != nil {
|
||||
t.Fatalf("yaml.Unmarshal(output) error:\n%+v", err)
|
||||
}
|
||||
for path, expected := range expectedYAML.Paths {
|
||||
var got interface{}
|
||||
var got any
|
||||
got = gotYAML
|
||||
i := 0
|
||||
for _, component := range strings.Split(path, ".") {
|
||||
var ok bool
|
||||
i++
|
||||
switch gotConcrete := got.(type) {
|
||||
case []interface{}:
|
||||
case []any:
|
||||
index, err := strconv.Atoi(component)
|
||||
if err != nil {
|
||||
t.Fatalf("key %q at level %d should be an int", path, i)
|
||||
}
|
||||
got = gotConcrete[index]
|
||||
case map[interface{}]interface{}:
|
||||
case map[any]any:
|
||||
got, ok = gotConcrete[component]
|
||||
if !ok {
|
||||
t.Fatalf("key %q does not exist in result", path)
|
||||
}
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
got, ok = gotConcrete[component]
|
||||
if !ok {
|
||||
t.Fatalf("key %q does not exist in result", path)
|
||||
|
||||
@@ -188,7 +188,7 @@ func outletStart(r *reporter.Reporter, config OutletConfiguration, checkOnly boo
|
||||
// OutletConfigurationUnmarshallerHook renames SNMP configuration to metadata and
|
||||
// BMP configuration to routing.
|
||||
func OutletConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc {
|
||||
return func(from, to reflect.Value) (interface{}, error) {
|
||||
return func(from, to reflect.Value) (any, error) {
|
||||
if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(OutletConfiguration{}) {
|
||||
return from.Interface(), nil
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func TestMock(t *testing.T) {
|
||||
Return(mockRows, nil)
|
||||
mockRows.EXPECT().Next().Return(true)
|
||||
mockRows.EXPECT().Close()
|
||||
mockRows.EXPECT().Scan(gomock.Any()).DoAndReturn(func(args ...interface{}) interface{} {
|
||||
mockRows.EXPECT().Scan(gomock.Any()).DoAndReturn(func(args ...any) any {
|
||||
arg0 := args[0].(*uint64)
|
||||
*arg0 = uint64(10)
|
||||
arg1 := args[1].(*uint64)
|
||||
|
||||
@@ -75,7 +75,7 @@ func SameTypeOrSuperset(input, ref reflect.Type) bool {
|
||||
// GetMapStructureDecoderConfig returns a decoder config for
|
||||
// mapstructure with all registered hooks as well as appropriate
|
||||
// default configuration.
|
||||
func GetMapStructureDecoderConfig(config interface{}, hooks ...mapstructure.DecodeHookFunc) *mapstructure.DecoderConfig {
|
||||
func GetMapStructureDecoderConfig(config any, hooks ...mapstructure.DecodeHookFunc) *mapstructure.DecoderConfig {
|
||||
return &mapstructure.DecoderConfig{
|
||||
Result: config,
|
||||
ErrorUnused: true,
|
||||
@@ -99,8 +99,8 @@ func StringToSliceHookFunc(sep string) mapstructure.DecodeHookFunc {
|
||||
return func(
|
||||
f reflect.Kind,
|
||||
t reflect.Kind,
|
||||
data interface{},
|
||||
) (interface{}, error) {
|
||||
data any,
|
||||
) (any, error) {
|
||||
if f != reflect.String || t != reflect.Slice {
|
||||
return data, nil
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func StringToSliceHookFunc(sep string) mapstructure.DecodeHookFunc {
|
||||
|
||||
// ProtectedDecodeHookFunc wraps a DecodeHookFunc to recover and returns an error on panic.
|
||||
func ProtectedDecodeHookFunc(hook mapstructure.DecodeHookFunc) mapstructure.DecodeHookFunc {
|
||||
return func(from, to reflect.Value) (v interface{}, err error) {
|
||||
return func(from, to reflect.Value) (v any, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
v = nil
|
||||
@@ -137,7 +137,7 @@ func MapStructureMatchName(mapKey, fieldName string) bool {
|
||||
// DefaultValuesUnmarshallerHook adds default values from the provided
|
||||
// configuration. For each missing non-default key, it will add them.
|
||||
func DefaultValuesUnmarshallerHook[Configuration any](defaultConfiguration Configuration) mapstructure.DecodeHookFunc {
|
||||
return func(from, to reflect.Value) (interface{}, error) {
|
||||
return func(from, to reflect.Value) (any, error) {
|
||||
from = ElemOrIdentity(from)
|
||||
to = ElemOrIdentity(to)
|
||||
if to.Type() != reflect.TypeOf(defaultConfiguration) {
|
||||
@@ -180,7 +180,7 @@ func DefaultValuesUnmarshallerHook[Configuration any](defaultConfiguration Confi
|
||||
|
||||
// RenameKeyUnmarshallerHook move a configuration setting from one place to another.
|
||||
func RenameKeyUnmarshallerHook[Configuration any](zeroConfiguration Configuration, fromLabel, toLabel string) mapstructure.DecodeHookFunc {
|
||||
return func(from, to reflect.Value) (interface{}, error) {
|
||||
return func(from, to reflect.Value) (any, error) {
|
||||
if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(zeroConfiguration) {
|
||||
return from.Interface(), nil
|
||||
}
|
||||
@@ -218,7 +218,7 @@ func RenameKeyUnmarshallerHook[Configuration any](zeroConfiguration Configuratio
|
||||
// type. A map from configuration types to a function providing the inner
|
||||
// default config should be provided.
|
||||
func ParametrizedConfigurationUnmarshallerHook[OuterConfiguration any, InnerConfiguration any](zeroOuterConfiguration OuterConfiguration, innerConfigurationMap map[string](func() InnerConfiguration)) mapstructure.DecodeHookFunc {
|
||||
return func(from, to reflect.Value) (interface{}, error) {
|
||||
return func(from, to reflect.Value) (any, error) {
|
||||
if to.Type() != reflect.TypeOf(zeroOuterConfiguration) {
|
||||
return from.Interface(), nil
|
||||
}
|
||||
@@ -306,7 +306,7 @@ func ParametrizedConfigurationUnmarshallerHook[OuterConfiguration any, InnerConf
|
||||
}
|
||||
|
||||
// ParametrizedConfigurationMarshalYAML undoes ParametrizedConfigurationUnmarshallerHook().
|
||||
func ParametrizedConfigurationMarshalYAML[OuterConfiguration any, InnerConfiguration any](oc OuterConfiguration, innerConfigurationMap map[string](func() InnerConfiguration)) (interface{}, error) {
|
||||
func ParametrizedConfigurationMarshalYAML[OuterConfiguration any, InnerConfiguration any](oc OuterConfiguration, innerConfigurationMap map[string](func() InnerConfiguration)) (any, error) {
|
||||
var innerConfigStruct reflect.Value
|
||||
outerConfigStruct := ElemOrIdentity(reflect.ValueOf(oc))
|
||||
result := gin.H{}
|
||||
|
||||
@@ -44,8 +44,8 @@ func TestStringToSliceHookFunc(t *testing.T) {
|
||||
}
|
||||
TestConfigurationDecode(t, ConfigurationDecodeCases{
|
||||
{
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"a": "blip,blop",
|
||||
"b": "1,2,3,4",
|
||||
@@ -64,7 +64,7 @@ func TestProtectedDecodeHook(t *testing.T) {
|
||||
A string
|
||||
B string
|
||||
}
|
||||
panicHook := func(from, _ reflect.Type, data interface{}) (interface{}, error) {
|
||||
panicHook := func(from, _ reflect.Type, data any) (any, error) {
|
||||
if from.Kind() == reflect.String {
|
||||
panic(errors.New("noooo"))
|
||||
}
|
||||
@@ -106,8 +106,8 @@ func TestDefaultValuesConfig(t *testing.T) {
|
||||
}))
|
||||
TestConfigurationDecode(t, ConfigurationDecodeCases{
|
||||
{
|
||||
Initial: func() interface{} { return OuterConfiguration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return OuterConfiguration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"dd": []gin.H{
|
||||
{
|
||||
@@ -150,8 +150,8 @@ func TestRenameConfig(t *testing.T) {
|
||||
TestConfigurationDecode(t, ConfigurationDecodeCases{
|
||||
{
|
||||
Description: "no rename needed",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"unchanged-label": "hello",
|
||||
"new-label": "bye",
|
||||
@@ -163,8 +163,8 @@ func TestRenameConfig(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "rename needed",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"unchanged-label": "hello",
|
||||
"old-label": "bye",
|
||||
@@ -176,8 +176,8 @@ func TestRenameConfig(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "conflicts",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"unchanged-label": "hello",
|
||||
"old-label": "bye",
|
||||
@@ -201,16 +201,16 @@ func TestParametrizedConfig(t *testing.T) {
|
||||
type OuterConfiguration struct {
|
||||
AA string
|
||||
BB string
|
||||
Config interface{}
|
||||
Config any
|
||||
}
|
||||
available := map[string](func() interface{}){
|
||||
"type1": func() interface{} {
|
||||
available := map[string](func() any){
|
||||
"type1": func() any {
|
||||
return InnerConfigurationType1{
|
||||
CC: "cc1",
|
||||
DD: "dd1",
|
||||
}
|
||||
},
|
||||
"type2": func() interface{} {
|
||||
"type2": func() any {
|
||||
return InnerConfigurationType2{
|
||||
CC: "cc2",
|
||||
EE: "ee2",
|
||||
@@ -223,8 +223,8 @@ func TestParametrizedConfig(t *testing.T) {
|
||||
TestConfigurationDecode(t, ConfigurationDecodeCases{
|
||||
{
|
||||
Description: "type1",
|
||||
Initial: func() interface{} { return OuterConfiguration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return OuterConfiguration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"type": "type1",
|
||||
"aa": "a1",
|
||||
@@ -243,8 +243,8 @@ func TestParametrizedConfig(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "type2",
|
||||
Initial: func() interface{} { return OuterConfiguration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return OuterConfiguration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"type": "type2",
|
||||
"aa": "a2",
|
||||
@@ -263,8 +263,8 @@ func TestParametrizedConfig(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "unknown type",
|
||||
Initial: func() interface{} { return OuterConfiguration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return OuterConfiguration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"type": "type3",
|
||||
"aa": "a2",
|
||||
@@ -345,8 +345,8 @@ func TestDeprecatedFields(t *testing.T) {
|
||||
RegisterMapstructureDeprecatedFields[Configuration]("C", "D")
|
||||
TestConfigurationDecode(t, ConfigurationDecodeCases{
|
||||
{
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"a": "hello",
|
||||
"b": "bye",
|
||||
@@ -359,8 +359,8 @@ func TestDeprecatedFields(t *testing.T) {
|
||||
B: "bye",
|
||||
},
|
||||
}, {
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"a": "hello",
|
||||
"b": "bye",
|
||||
|
||||
@@ -161,7 +161,7 @@ func LooksLikeSubnetMap(v reflect.Value) (result bool) {
|
||||
// valid networks are provided as key. It also accepts a single value
|
||||
// instead of a map for backward compatibility.
|
||||
func SubnetMapUnmarshallerHook[V any]() mapstructure.DecodeHookFunc {
|
||||
return func(from, to reflect.Value) (interface{}, error) {
|
||||
return func(from, to reflect.Value) (any, error) {
|
||||
if to.Type() != reflect.TypeOf(SubnetMap[V]{}) {
|
||||
return from.Interface(), nil
|
||||
}
|
||||
@@ -248,7 +248,7 @@ func SubnetMapParseKey(k string) (string, error) {
|
||||
}
|
||||
|
||||
// MarshalYAML turns a subnet into a map that can be marshaled.
|
||||
func (sm SubnetMap[V]) MarshalYAML() (interface{}, error) {
|
||||
func (sm SubnetMap[V]) MarshalYAML() (any, error) {
|
||||
return sm.ToMap(), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ func TestSubnetMapUnmarshalHook(t *testing.T) {
|
||||
var nilMap map[string]string
|
||||
cases := []struct {
|
||||
Description string
|
||||
Input interface{}
|
||||
Input any
|
||||
Tests map[string]string
|
||||
Error bool
|
||||
YAML interface{}
|
||||
YAML any
|
||||
}{
|
||||
{
|
||||
Description: "nil",
|
||||
|
||||
@@ -79,7 +79,7 @@ func CheckExternalService(t *testing.T, name string, candidates []string) string
|
||||
}
|
||||
|
||||
// StartStop starts a component and stops it on cleanup.
|
||||
func StartStop(t *testing.T, component interface{}) {
|
||||
func StartStop(t *testing.T, component any) {
|
||||
t.Helper()
|
||||
if starterC, ok := component.(starter); ok {
|
||||
if err := starterC.Start(); err != nil {
|
||||
|
||||
@@ -20,9 +20,9 @@ import (
|
||||
type ConfigurationDecodeCases []struct {
|
||||
Description string
|
||||
Pos Pos
|
||||
Initial func() interface{} // initial value for configuration
|
||||
Configuration func() interface{} // configuration to decode
|
||||
Expected interface{}
|
||||
Initial func() any // initial value for configuration
|
||||
Configuration func() any // configuration to decode
|
||||
Expected any
|
||||
Error bool
|
||||
SkipValidation bool
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func TestConfigurationDecode(t *testing.T, cases ConfigurationDecodeCases, optio
|
||||
}
|
||||
t.Run(title, func(t *testing.T) {
|
||||
t.Helper()
|
||||
var configuration interface{}
|
||||
var configuration any
|
||||
if fromYAML {
|
||||
// Encode and decode with YAML
|
||||
out, err := yaml.Marshal(tc.Configuration())
|
||||
|
||||
@@ -22,12 +22,12 @@ var prettyC = pretty.Config{
|
||||
IncludeUnexported: false,
|
||||
}
|
||||
|
||||
func formatByte(v interface{}) string {
|
||||
func formatByte(v any) string {
|
||||
return fmt.Sprintf("0x%x", v)
|
||||
}
|
||||
|
||||
func defaultPrettyFormatters() map[reflect.Type]interface{} {
|
||||
result := map[reflect.Type]interface{}{
|
||||
func defaultPrettyFormatters() map[reflect.Type]any {
|
||||
result := map[reflect.Type]any{
|
||||
reflect.TypeOf(net.IP{}): fmt.Sprint,
|
||||
reflect.TypeOf(netip.Addr{}): fmt.Sprint,
|
||||
reflect.TypeOf(time.Time{}): fmt.Sprint,
|
||||
@@ -42,11 +42,11 @@ func defaultPrettyFormatters() map[reflect.Type]interface{} {
|
||||
return result
|
||||
}
|
||||
|
||||
var nonDefaultPrettyFormatters = map[reflect.Type]interface{}{}
|
||||
var nonDefaultPrettyFormatters = map[reflect.Type]any{}
|
||||
|
||||
// AddPrettyFormatter add a global pretty formatter. We cannot put everything in
|
||||
// the default map due to cycles.
|
||||
func AddPrettyFormatter(t reflect.Type, fn interface{}) {
|
||||
func AddPrettyFormatter(t reflect.Type, fn any) {
|
||||
nonDefaultPrettyFormatters[t] = fn
|
||||
}
|
||||
|
||||
@@ -55,12 +55,12 @@ type DiffOption struct {
|
||||
kind int
|
||||
// When this is a formatter
|
||||
t reflect.Type
|
||||
fn interface{}
|
||||
fn any
|
||||
}
|
||||
|
||||
// Diff return a diff of two objects. If no diff, an empty string is
|
||||
// returned.
|
||||
func Diff(a, b interface{}, options ...DiffOption) string {
|
||||
func Diff(a, b any, options ...DiffOption) string {
|
||||
prettyC := prettyC
|
||||
prettyC.Formatter = defaultPrettyFormatters()
|
||||
for _, option := range options {
|
||||
@@ -84,6 +84,6 @@ var (
|
||||
)
|
||||
|
||||
// DiffFormatter adds a new formatter
|
||||
func DiffFormatter(t reflect.Type, fn interface{}) DiffOption {
|
||||
func DiffFormatter(t reflect.Type, fn any) DiffOption {
|
||||
return DiffOption{kind: 3, t: t, fn: fn}
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ type HTTPEndpointCases []struct {
|
||||
Method string
|
||||
URL string
|
||||
Header http.Header
|
||||
JSONInput interface{}
|
||||
JSONInput any
|
||||
|
||||
ContentType string
|
||||
StatusCode int
|
||||
FirstLines []string
|
||||
JSONOutput interface{}
|
||||
JSONOutput any
|
||||
}
|
||||
|
||||
// TestHTTPEndpoints test a few HTTP endpoints
|
||||
|
||||
@@ -20,7 +20,7 @@ var Validate *validator.Validate
|
||||
// register all subnetmaps.
|
||||
func RegisterSubnetMapValidation[V any]() {
|
||||
var zero SubnetMap[V]
|
||||
validatorFunc := func(field reflect.Value) interface{} {
|
||||
validatorFunc := func(field reflect.Value) any {
|
||||
switch subnetMap := field.Interface().(type) {
|
||||
case SubnetMap[V]:
|
||||
return subnetMap.ToMap()
|
||||
@@ -33,7 +33,7 @@ func RegisterSubnetMapValidation[V any]() {
|
||||
}
|
||||
|
||||
// netipValidation validates netip.Addr and netip.Prefix by turning them into a string.
|
||||
func netipValidation(fl reflect.Value) interface{} {
|
||||
func netipValidation(fl reflect.Value) any {
|
||||
switch netipSomething := fl.Interface().(type) {
|
||||
case netip.Addr:
|
||||
if (netipSomething == netip.Addr{}) {
|
||||
|
||||
@@ -93,7 +93,7 @@ func TestSubnetMapValidator(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
Description string
|
||||
Value interface{}
|
||||
Value any
|
||||
Error bool
|
||||
}{
|
||||
{
|
||||
@@ -179,7 +179,7 @@ func TestNetIPValidation(t *testing.T) {
|
||||
}
|
||||
cases := []struct {
|
||||
Description string
|
||||
Value interface{}
|
||||
Value any
|
||||
Error bool
|
||||
}{
|
||||
{
|
||||
|
||||
@@ -8,6 +8,6 @@ import "gopkg.in/yaml.v3"
|
||||
// Marshal serializes the value provided into a YAML document. The structure of
|
||||
// the generated document will reflect the structure of the value itself. Maps
|
||||
// and pointers (to struct, string, int, etc) are accepted as the in value.
|
||||
func Marshal(in interface{}) (out []byte, err error) {
|
||||
func Marshal(in any) (out []byte, err error) {
|
||||
return yaml.Marshal(in)
|
||||
}
|
||||
|
||||
@@ -15,14 +15,14 @@ import (
|
||||
|
||||
// Unmarshal decodes the first document found within the in byte slice and
|
||||
// assigns decoded values into the out value.
|
||||
func Unmarshal(in []byte, out interface{}) (err error) {
|
||||
func Unmarshal(in []byte, out any) (err error) {
|
||||
return yaml.Unmarshal(in, out)
|
||||
}
|
||||
|
||||
// UnmarshalWithInclude decodes the first document found within the in byte
|
||||
// slice and assigns decoded values into the out value. It also accepts the
|
||||
// "!include" tag to include additional files contained in the provided fs.
|
||||
func UnmarshalWithInclude(fsys fs.FS, input string, out interface{}) (err error) {
|
||||
func UnmarshalWithInclude(fsys fs.FS, input string, out any) (err error) {
|
||||
var outNode yaml.Node
|
||||
in, err := fs.ReadFile(fsys, input)
|
||||
if err != nil {
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
func TestUnmarshalWithIn(t *testing.T) {
|
||||
fsys := os.DirFS("testdata")
|
||||
var got interface{}
|
||||
var got any
|
||||
if err := yaml.UnmarshalWithInclude(fsys, "base.yaml", &got); err != nil {
|
||||
t.Fatalf("UnmarshalWithInclude() error:\n%+v", err)
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func TestUnmarshalWithIn(t *testing.T) {
|
||||
"file1": gin.H{"name": "1.yaml"},
|
||||
},
|
||||
"list1": []string{"el1", "el2", "el3"},
|
||||
"list2": []interface{}{gin.H{
|
||||
"list2": []any{gin.H{
|
||||
"protocol": "tcp",
|
||||
"size": 1300,
|
||||
}, "el2", "el3"},
|
||||
|
||||
@@ -61,6 +61,6 @@ type cacheLogger struct {
|
||||
r *reporter.Reporter
|
||||
}
|
||||
|
||||
func (cl cacheLogger) Errorf(msg string, args ...interface{}) {
|
||||
func (cl cacheLogger) Errorf(msg string, args ...any) {
|
||||
cl.r.Error().Msgf(msg, args...)
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ func DefaultConfiguration() Configuration {
|
||||
}
|
||||
|
||||
// MarshalYAML undoes ConfigurationUnmarshallerHook().
|
||||
func (cc CacheConfiguration) MarshalYAML() (interface{}, error) {
|
||||
func (cc CacheConfiguration) MarshalYAML() (any, error) {
|
||||
return helpers.ParametrizedConfigurationMarshalYAML(cc, cacheConfigurationMap)
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ func NewConfig(r *reporter.Reporter, config Configuration) ([]kgo.Opt, error) {
|
||||
// ConfigurationUnmarshallerHook normalize Kafka configuration:
|
||||
// - move SASL related parameters from TLS section to SASL section
|
||||
func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc {
|
||||
return func(from, to reflect.Value) (interface{}, error) {
|
||||
return func(from, to reflect.Value) (any, error) {
|
||||
if from.Kind() != reflect.Map || from.IsNil() || !helpers.SameTypeOrSuperset(to.Type(), reflect.TypeOf(Configuration{})) {
|
||||
return from.Interface(), nil
|
||||
}
|
||||
|
||||
@@ -93,13 +93,13 @@ func TestTLSConfiguration(t *testing.T) {
|
||||
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
|
||||
{
|
||||
Description: "no TLS",
|
||||
Initial: func() interface{} { return DefaultConfiguration() },
|
||||
Configuration: func() interface{} { return nil },
|
||||
Initial: func() any { return DefaultConfiguration() },
|
||||
Configuration: func() any { return nil },
|
||||
Expected: DefaultConfiguration(),
|
||||
}, {
|
||||
Description: "TLS without auth",
|
||||
Initial: func() interface{} { return DefaultConfiguration() },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return DefaultConfiguration() },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"tls": gin.H{
|
||||
"enable": true,
|
||||
@@ -116,8 +116,8 @@ func TestTLSConfiguration(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "TLS SASL plain, skip cert verification (old style)",
|
||||
Initial: func() interface{} { return DefaultConfiguration() },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return DefaultConfiguration() },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"tls": gin.H{
|
||||
"enable": true,
|
||||
@@ -143,8 +143,8 @@ func TestTLSConfiguration(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "TLS SASL plain, skip cert verification",
|
||||
Initial: func() interface{} { return DefaultConfiguration() },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return DefaultConfiguration() },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"sasl": gin.H{
|
||||
"username": "hello",
|
||||
@@ -168,8 +168,8 @@ func TestTLSConfiguration(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "TLS SASL SCRAM 256",
|
||||
Initial: func() interface{} { return DefaultConfiguration() },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return DefaultConfiguration() },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"tls": gin.H{
|
||||
"enable": true,
|
||||
@@ -197,8 +197,8 @@ func TestTLSConfiguration(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "TLS SASL OAuth",
|
||||
Initial: func() interface{} { return DefaultConfiguration() },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return DefaultConfiguration() },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"tls": gin.H{
|
||||
"enable": true,
|
||||
@@ -230,8 +230,8 @@ func TestTLSConfiguration(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "OAuth requires a token URL",
|
||||
Initial: func() interface{} { return DefaultConfiguration() },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return DefaultConfiguration() },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"sasl": gin.H{
|
||||
"username": "hello",
|
||||
@@ -243,8 +243,8 @@ func TestTLSConfiguration(t *testing.T) {
|
||||
Error: true,
|
||||
}, {
|
||||
Description: "OAuth token URL only with OAuth",
|
||||
Initial: func() interface{} { return DefaultConfiguration() },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return DefaultConfiguration() },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"sasl": gin.H{
|
||||
"username": "hello",
|
||||
|
||||
@@ -18,8 +18,8 @@ func TestSourceDecode(t *testing.T) {
|
||||
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
|
||||
{
|
||||
Description: "Empty",
|
||||
Initial: func() interface{} { return Source{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Source{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"url": "https://example.net",
|
||||
"interval": "10m",
|
||||
@@ -33,8 +33,8 @@ func TestSourceDecode(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "Simple transform",
|
||||
Initial: func() interface{} { return Source{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Source{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"url": "https://example.net",
|
||||
"interval": "10m",
|
||||
@@ -50,8 +50,8 @@ func TestSourceDecode(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "Use POST",
|
||||
Initial: func() interface{} { return Source{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Source{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"url": "https://example.net",
|
||||
"method": "POST",
|
||||
@@ -69,8 +69,8 @@ func TestSourceDecode(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "Complex transform",
|
||||
Initial: func() interface{} { return Source{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Source{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"url": "https://example.net",
|
||||
"interval": "10m",
|
||||
@@ -90,8 +90,8 @@ func TestSourceDecode(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "Incorrect transform",
|
||||
Initial: func() interface{} { return Source{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Source{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"url": "https://example.net",
|
||||
"interval": "10m",
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
type ProviderFunc func(ctx context.Context, name string, source Source) (int, error)
|
||||
|
||||
// Component represents a remote data source fetcher.
|
||||
type Component[T interface{}] struct {
|
||||
type Component[T any] struct {
|
||||
r *reporter.Reporter
|
||||
t tomb.Tomb
|
||||
provider ProviderFunc
|
||||
@@ -40,7 +40,7 @@ type Component[T interface{}] struct {
|
||||
}
|
||||
|
||||
// New creates a new remote data source fetcher component.
|
||||
func New[T interface{}](r *reporter.Reporter, provider ProviderFunc, dataType string, dataSources map[string]Source) (*Component[T], error) {
|
||||
func New[T any](r *reporter.Reporter, provider ProviderFunc, dataType string, dataSources map[string]Source) (*Component[T], error) {
|
||||
c := Component[T]{
|
||||
r: r,
|
||||
provider: provider,
|
||||
@@ -104,7 +104,7 @@ func (c *Component[T]) Fetch(ctx context.Context, name string, source Source) ([
|
||||
}
|
||||
reader := bufio.NewReader(resp.Body)
|
||||
decoder := json.NewDecoder(reader)
|
||||
var got interface{}
|
||||
var got any
|
||||
if err := decoder.Decode(&got); err != nil {
|
||||
l.Err(err).Msg("cannot decode JSON output")
|
||||
return nil, ErrJSONDecode
|
||||
|
||||
@@ -15,7 +15,7 @@ type promHTTPLogger struct {
|
||||
}
|
||||
|
||||
// Println outputs
|
||||
func (m promHTTPLogger) Println(v ...interface{}) {
|
||||
func (m promHTTPLogger) Println(v ...any) {
|
||||
if e := m.l.Debug(); e.Enabled() {
|
||||
e.Msg(fmt.Sprint(v...))
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ type Call uintptr
|
||||
type Trace []Call
|
||||
|
||||
var pcStackPool = sync.Pool{
|
||||
New: func() interface{} { return make([]uintptr, 1000) },
|
||||
New: func() any { return make([]uintptr, 1000) },
|
||||
}
|
||||
|
||||
func poolBuf() []uintptr {
|
||||
|
||||
@@ -47,7 +47,7 @@ func (customHeaderBinding) Name() string {
|
||||
}
|
||||
|
||||
// Bind will bind struct fields to HTTP headers using the configured mapping.
|
||||
func (b customHeaderBinding) Bind(req *http.Request, obj interface{}) error {
|
||||
func (b customHeaderBinding) Bind(req *http.Request, obj any) error {
|
||||
value := reflect.ValueOf(obj).Elem()
|
||||
tValue := reflect.TypeOf(obj).Elem()
|
||||
if value.Kind() != reflect.Struct {
|
||||
|
||||
@@ -22,15 +22,15 @@ func (l *logger) LogMode(gormlogger.LogLevel) gormlogger.Interface {
|
||||
return l
|
||||
}
|
||||
|
||||
func (l *logger) Info(_ context.Context, s string, args ...interface{}) {
|
||||
func (l *logger) Info(_ context.Context, s string, args ...any) {
|
||||
l.r.Info().Msgf(s, args...)
|
||||
}
|
||||
|
||||
func (l *logger) Warn(_ context.Context, s string, args ...interface{}) {
|
||||
func (l *logger) Warn(_ context.Context, s string, args ...any) {
|
||||
l.r.Warn().Msgf(s, args...)
|
||||
}
|
||||
|
||||
func (l *logger) Error(_ context.Context, s string, args ...interface{}) {
|
||||
func (l *logger) Error(_ context.Context, s string, args ...any) {
|
||||
l.r.Error().Msgf(s, args...)
|
||||
}
|
||||
|
||||
|
||||
@@ -188,18 +188,18 @@ func lastIP(subnet netip.Prefix) netip.Addr {
|
||||
return netip.AddrFrom16(a16)
|
||||
}
|
||||
|
||||
func quote(v interface{}) string {
|
||||
func quote(v any) string {
|
||||
return "'" + strings.NewReplacer(`\`, `\\`, `'`, `\'`).Replace(toString(v)) + "'"
|
||||
}
|
||||
|
||||
func toSlice(v interface{}) []interface{} {
|
||||
func toSlice(v any) []any {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
return v.([]interface{})
|
||||
return v.([]any)
|
||||
}
|
||||
|
||||
func toString(v interface{}) string {
|
||||
func toString(v any) string {
|
||||
switch s := v.(type) {
|
||||
case string:
|
||||
return s
|
||||
|
||||
@@ -64,7 +64,7 @@ LIMIT 1`, strings.Join(selectClause, ",\n "))
|
||||
var (
|
||||
response = gin.H{}
|
||||
columnTypes = rows.ColumnTypes()
|
||||
vars = make([]interface{}, len(columnTypes))
|
||||
vars = make([]any, len(columnTypes))
|
||||
)
|
||||
for i := range columnTypes {
|
||||
vars[i] = reflect.New(columnTypes[i].ScanType()).Interface()
|
||||
|
||||
@@ -67,7 +67,7 @@ LIMIT 1`).
|
||||
}).AnyTimes()
|
||||
|
||||
mockRows.EXPECT().Scan(gomock.Any()).
|
||||
DoAndReturn(func(args ...interface{}) interface{} {
|
||||
DoAndReturn(func(args ...any) any {
|
||||
arg0 := args[0].(*time.Time)
|
||||
*arg0 = time.Date(2022, 4, 4, 8, 36, 11, 10, time.UTC)
|
||||
arg1 := args[1].(*uint64)
|
||||
|
||||
@@ -17,7 +17,7 @@ func (c *Component) newOID(oid string, t gosnmp.Asn1BER, onGet GoSNMPServer.Func
|
||||
return &GoSNMPServer.PDUValueControlItem{
|
||||
OID: oid,
|
||||
Type: t,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
c.metrics.requests.WithLabelValues(oid).Inc()
|
||||
return onGet()
|
||||
},
|
||||
@@ -28,7 +28,7 @@ func (c *Component) startSNMPServer() error {
|
||||
oids := make([]*GoSNMPServer.PDUValueControlItem, 1+4*len(c.config.Interfaces))
|
||||
oids[0] = c.newOID("1.3.6.1.2.1.1.5.0",
|
||||
gosnmp.OctetString,
|
||||
func() (interface{}, error) {
|
||||
func() (any, error) {
|
||||
return c.config.Name, nil
|
||||
},
|
||||
)
|
||||
@@ -38,25 +38,25 @@ func (c *Component) startSNMPServer() error {
|
||||
d := description
|
||||
oids[4*count+1] = c.newOID(fmt.Sprintf("1.3.6.1.2.1.2.2.1.2.%d", i),
|
||||
gosnmp.OctetString,
|
||||
func() (interface{}, error) {
|
||||
func() (any, error) {
|
||||
return fmt.Sprintf("Gi0/0/0/%d", i), nil
|
||||
},
|
||||
)
|
||||
oids[4*count+2] = c.newOID(fmt.Sprintf("1.3.6.1.2.1.31.1.1.1.1.%d", i),
|
||||
gosnmp.OctetString,
|
||||
func() (interface{}, error) {
|
||||
func() (any, error) {
|
||||
return fmt.Sprintf("Gi0/0/0/%d", i), nil
|
||||
},
|
||||
)
|
||||
oids[4*count+3] = c.newOID(fmt.Sprintf("1.3.6.1.2.1.31.1.1.1.15.%d", i),
|
||||
gosnmp.Gauge32,
|
||||
func() (interface{}, error) {
|
||||
func() (any, error) {
|
||||
return uint(10000), nil
|
||||
},
|
||||
)
|
||||
oids[4*count+4] = c.newOID(fmt.Sprintf("1.3.6.1.2.1.31.1.1.1.18.%d", i),
|
||||
gosnmp.OctetString,
|
||||
func() (interface{}, error) {
|
||||
func() (any, error) {
|
||||
return d, nil
|
||||
},
|
||||
)
|
||||
|
||||
@@ -46,7 +46,7 @@ type InputConfiguration struct {
|
||||
}
|
||||
|
||||
// MarshalYAML undoes ConfigurationUnmarshallerHook().
|
||||
func (ic InputConfiguration) MarshalYAML() (interface{}, error) {
|
||||
func (ic InputConfiguration) MarshalYAML() (any, error) {
|
||||
return helpers.ParametrizedConfigurationMarshalYAML(ic, inputs)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
|
||||
{
|
||||
Description: "from empty configuration",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"inputs": []gin.H{
|
||||
{
|
||||
@@ -61,7 +61,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "from existing configuration",
|
||||
Initial: func() interface{} {
|
||||
Initial: func() any {
|
||||
return Configuration{
|
||||
Inputs: []InputConfiguration{{
|
||||
Decoder: pb.RawFlow_DECODER_NETFLOW,
|
||||
@@ -72,7 +72,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
}},
|
||||
}
|
||||
},
|
||||
Configuration: func() interface{} {
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"inputs": []gin.H{
|
||||
{
|
||||
@@ -108,7 +108,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "change type",
|
||||
Initial: func() interface{} {
|
||||
Initial: func() any {
|
||||
return Configuration{
|
||||
Inputs: []InputConfiguration{{
|
||||
Decoder: pb.RawFlow_DECODER_NETFLOW,
|
||||
@@ -116,7 +116,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
}},
|
||||
}
|
||||
},
|
||||
Configuration: func() interface{} {
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"inputs": []gin.H{
|
||||
{
|
||||
@@ -136,7 +136,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "only set one item",
|
||||
Initial: func() interface{} {
|
||||
Initial: func() any {
|
||||
return Configuration{
|
||||
Inputs: []InputConfiguration{{
|
||||
Decoder: pb.RawFlow_DECODER_NETFLOW,
|
||||
@@ -149,7 +149,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
}},
|
||||
}
|
||||
},
|
||||
Configuration: func() interface{} {
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"inputs": []gin.H{
|
||||
{
|
||||
@@ -170,10 +170,10 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "incorrect decoder",
|
||||
Initial: func() interface{} {
|
||||
Initial: func() any {
|
||||
return Configuration{}
|
||||
},
|
||||
Configuration: func() interface{} {
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"inputs": []gin.H{
|
||||
{
|
||||
@@ -194,7 +194,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Description: "netflow timestamp source netflow-packet",
|
||||
Initial: func() interface{} {
|
||||
Initial: func() any {
|
||||
return Configuration{
|
||||
Inputs: []InputConfiguration{{
|
||||
Decoder: pb.RawFlow_DECODER_NETFLOW,
|
||||
@@ -206,7 +206,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
}},
|
||||
}
|
||||
},
|
||||
Configuration: func() interface{} {
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"inputs": []gin.H{
|
||||
{
|
||||
@@ -230,7 +230,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Description: "netflow timestamp source netflow-first-switched",
|
||||
Initial: func() interface{} {
|
||||
Initial: func() any {
|
||||
return Configuration{
|
||||
Inputs: []InputConfiguration{{
|
||||
Decoder: pb.RawFlow_DECODER_NETFLOW,
|
||||
@@ -242,7 +242,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
}},
|
||||
}
|
||||
},
|
||||
Configuration: func() interface{} {
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"inputs": []gin.H{
|
||||
{
|
||||
|
||||
@@ -105,7 +105,7 @@ type NetworkAttributes struct {
|
||||
// also accepts a string instead of attributes for backward
|
||||
// compatibility.
|
||||
func NetworkAttributesUnmarshallerHook() mapstructure.DecodeHookFunc {
|
||||
return func(from, to reflect.Value) (interface{}, error) {
|
||||
return func(from, to reflect.Value) (any, error) {
|
||||
from = helpers.ElemOrIdentity(from)
|
||||
to = helpers.ElemOrIdentity(to)
|
||||
if to.Type() != reflect.TypeOf(NetworkAttributes{}) {
|
||||
|
||||
@@ -17,46 +17,46 @@ func TestNetworkNamesUnmarshalHook(t *testing.T) {
|
||||
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
|
||||
{
|
||||
Description: "nil",
|
||||
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() interface{} { return nil },
|
||||
Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() any { return nil },
|
||||
Expected: helpers.SubnetMap[NetworkAttributes]{},
|
||||
}, {
|
||||
Description: "empty",
|
||||
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() interface{} { return gin.H{} },
|
||||
Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() any { return gin.H{} },
|
||||
Expected: helpers.SubnetMap[NetworkAttributes]{},
|
||||
}, {
|
||||
Description: "IPv4",
|
||||
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() interface{} { return gin.H{"203.0.113.0/24": gin.H{"name": "customer"}} },
|
||||
Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() any { return gin.H{"203.0.113.0/24": gin.H{"name": "customer"}} },
|
||||
Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{
|
||||
"::ffff:203.0.113.0/120": {Name: "customer"},
|
||||
}),
|
||||
}, {
|
||||
Description: "IPv6",
|
||||
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() interface{} { return gin.H{"2001:db8:1::/64": gin.H{"name": "customer"}} },
|
||||
Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() any { return gin.H{"2001:db8:1::/64": gin.H{"name": "customer"}} },
|
||||
Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{
|
||||
"2001:db8:1::/64": {Name: "customer"},
|
||||
}),
|
||||
}, {
|
||||
Description: "IPv4 subnet (compatibility)",
|
||||
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() interface{} { return gin.H{"203.0.113.0/24": "customer"} },
|
||||
Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() any { return gin.H{"203.0.113.0/24": "customer"} },
|
||||
Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{
|
||||
"::ffff:203.0.113.0/120": {Name: "customer"},
|
||||
}),
|
||||
}, {
|
||||
Description: "IPv6 subnet (compatibility)",
|
||||
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() interface{} { return gin.H{"2001:db8:1::/64": "customer"} },
|
||||
Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() any { return gin.H{"2001:db8:1::/64": "customer"} },
|
||||
Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{
|
||||
"2001:db8:1::/64": {Name: "customer"},
|
||||
}),
|
||||
}, {
|
||||
Description: "all attributes",
|
||||
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{"203.0.113.0/24": gin.H{
|
||||
"name": "customer1",
|
||||
"role": "customer",
|
||||
@@ -74,13 +74,13 @@ func TestNetworkNamesUnmarshalHook(t *testing.T) {
|
||||
}}),
|
||||
}, {
|
||||
Description: "Invalid subnet (1)",
|
||||
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() interface{} { return gin.H{"192.0.2.1/38": "customer"} },
|
||||
Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() any { return gin.H{"192.0.2.1/38": "customer"} },
|
||||
Error: true,
|
||||
}, {
|
||||
Description: "Invalid subnet (2)",
|
||||
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() interface{} { return gin.H{"192.0.2.1/255.0.255.0": "customer"} },
|
||||
Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
|
||||
Configuration: func() any { return gin.H{"192.0.2.1/255.0.255.0": "customer"} },
|
||||
Error: true,
|
||||
},
|
||||
}, helpers.DiffFormatter(reflect.TypeOf(helpers.SubnetMap[NetworkAttributes]{}), fmt.Sprint))
|
||||
|
||||
@@ -19,7 +19,7 @@ type migrationStep struct {
|
||||
// CheckQuery to execute to check if the step is needed.
|
||||
CheckQuery string
|
||||
// Arguments to use for the query
|
||||
Args []interface{}
|
||||
Args []any
|
||||
// Function to execute if the query returns no row or returns `0'.
|
||||
Do func() error
|
||||
}
|
||||
|
||||
@@ -15,18 +15,18 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
|
||||
{
|
||||
Description: "nil",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} { return nil },
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any { return nil },
|
||||
Expected: Configuration{},
|
||||
}, {
|
||||
Description: "empty",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} { return gin.H{} },
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any { return gin.H{} },
|
||||
Expected: Configuration{},
|
||||
}, {
|
||||
Description: "no country-database, no geoip-database",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"asn-database": []string{"something"},
|
||||
"optional": true,
|
||||
@@ -38,8 +38,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "country-database, no geoip-database",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"asn-database": []string{"something"},
|
||||
"country-database": []string{"something else"},
|
||||
@@ -51,8 +51,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "no country-database, geoip-database",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"asn-database": []string{"something"},
|
||||
"geo-database": []string{"something else"},
|
||||
@@ -64,8 +64,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "both country-database, geoip-database",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"asn-database": []string{"something"},
|
||||
"geo-database": []string{"something else"},
|
||||
|
||||
@@ -20,7 +20,7 @@ func (c *Component) configurationHandlerFunc(gc *gin.Context) {
|
||||
}
|
||||
|
||||
c.serviceLock.Lock()
|
||||
var configuration interface{}
|
||||
var configuration any
|
||||
serviceConfigurations, ok := c.serviceConfigurations[ServiceType(service)]
|
||||
if ok {
|
||||
l := len(serviceConfigurations)
|
||||
|
||||
@@ -18,7 +18,7 @@ type Component struct {
|
||||
config Configuration
|
||||
|
||||
serviceLock sync.Mutex
|
||||
serviceConfigurations map[ServiceType][]interface{}
|
||||
serviceConfigurations map[ServiceType][]any
|
||||
}
|
||||
|
||||
// Dependencies define the dependencies of the broker.
|
||||
@@ -49,7 +49,7 @@ func New(r *reporter.Reporter, configuration Configuration, dependencies Depende
|
||||
d: &dependencies,
|
||||
config: configuration,
|
||||
|
||||
serviceConfigurations: map[ServiceType][]interface{}{},
|
||||
serviceConfigurations: map[ServiceType][]any{},
|
||||
}
|
||||
|
||||
c.d.HTTP.GinRouter.GET("/api/v0/orchestrator/configuration/:service", c.configurationHandlerFunc)
|
||||
@@ -59,10 +59,10 @@ func New(r *reporter.Reporter, configuration Configuration, dependencies Depende
|
||||
}
|
||||
|
||||
// RegisterConfiguration registers the configuration for a service.
|
||||
func (c *Component) RegisterConfiguration(service ServiceType, configuration interface{}) {
|
||||
func (c *Component) RegisterConfiguration(service ServiceType, configuration any) {
|
||||
c.serviceLock.Lock()
|
||||
if _, ok := c.serviceConfigurations[service]; !ok {
|
||||
c.serviceConfigurations[service] = []interface{}{}
|
||||
c.serviceConfigurations[service] = []any{}
|
||||
}
|
||||
c.serviceConfigurations[service] = append(c.serviceConfigurations[service], configuration)
|
||||
c.serviceLock.Unlock()
|
||||
|
||||
@@ -75,7 +75,7 @@ const (
|
||||
// ASNProviderUnmarshallerHook normalize a net provider configuration:
|
||||
// - map bmp to routing
|
||||
func ASNProviderUnmarshallerHook() mapstructure.DecodeHookFunc {
|
||||
return func(from, to reflect.Value) (interface{}, error) {
|
||||
return func(from, to reflect.Value) (any, error) {
|
||||
if from.Kind() != reflect.String || to.Type() != reflect.TypeOf(ASNProvider(0)) {
|
||||
return from.Interface(), nil
|
||||
}
|
||||
@@ -92,7 +92,7 @@ func ASNProviderUnmarshallerHook() mapstructure.DecodeHookFunc {
|
||||
// NetProviderUnmarshallerHook normalize a net provider configuration:
|
||||
// - map bmp to routing
|
||||
func NetProviderUnmarshallerHook() mapstructure.DecodeHookFunc {
|
||||
return func(from, to reflect.Value) (interface{}, error) {
|
||||
return func(from, to reflect.Value) (any, error) {
|
||||
if from.Kind() != reflect.String || to.Type() != reflect.TypeOf(NetProvider(0)) {
|
||||
return from.Interface(), nil
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func NetProviderUnmarshallerHook() mapstructure.DecodeHookFunc {
|
||||
// ConfigurationUnmarshallerHook normalize core configuration:
|
||||
// - replace ignore-asn-from-flow by asn-providers
|
||||
func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc {
|
||||
return func(from, to reflect.Value) (interface{}, error) {
|
||||
return func(from, to reflect.Value) (any, error) {
|
||||
if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(Configuration{}) {
|
||||
return from.Interface(), nil
|
||||
}
|
||||
|
||||
@@ -21,20 +21,20 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
|
||||
{
|
||||
Description: "nil",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} { return nil },
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any { return nil },
|
||||
Expected: Configuration{},
|
||||
SkipValidation: true,
|
||||
}, {
|
||||
Description: "empty",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} { return gin.H{} },
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any { return gin.H{} },
|
||||
Expected: Configuration{},
|
||||
SkipValidation: true,
|
||||
}, {
|
||||
Description: "ignore-asn-from-flow = false",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"ignore-asn-from-flow": false,
|
||||
}
|
||||
@@ -43,8 +43,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
SkipValidation: true,
|
||||
}, {
|
||||
Description: "ignore-asn-from-flow = true",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"ignore-asn-from-flow": true,
|
||||
}
|
||||
@@ -55,8 +55,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
SkipValidation: true,
|
||||
}, {
|
||||
Description: "ignore-asn-from-flow and asn-providers",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"ignore-asn-from-flow": true,
|
||||
"asn-providers": []string{"routing", "flow"},
|
||||
@@ -66,8 +66,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
SkipValidation: true,
|
||||
}, {
|
||||
Description: "asn-providers only",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"asn-providers": []string{"flow-except-private", "routing", "flow"},
|
||||
}
|
||||
@@ -78,8 +78,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
SkipValidation: true,
|
||||
}, {
|
||||
Description: "net-providers with bmp",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"net-providers": []string{"flow", "bmp"},
|
||||
}
|
||||
@@ -90,8 +90,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
SkipValidation: true,
|
||||
}, {
|
||||
Description: "asn-providers with bmp",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"asn-providers": []string{"flow", "bmp", "bmp-except-private"},
|
||||
}
|
||||
@@ -102,8 +102,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
SkipValidation: true,
|
||||
}, {
|
||||
Description: "net-providers",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"net-providers": []string{"flow", "routing"},
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func TestEnrich(t *testing.T) {
|
||||
InIf: 100,
|
||||
OutIf: 200,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnInIfName: "Gi0/0/100",
|
||||
schema.ColumnOutIfName: "Gi0/0/200",
|
||||
@@ -82,7 +82,7 @@ func TestEnrich(t *testing.T) {
|
||||
InIf: 100,
|
||||
OutIf: 200,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnInIfName: "Gi0/0/100",
|
||||
schema.ColumnOutIfName: "Gi0/0/200",
|
||||
@@ -107,7 +107,7 @@ func TestEnrich(t *testing.T) {
|
||||
InIf: 100,
|
||||
OutIf: 200,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnInIfName: "Gi0/0/100",
|
||||
schema.ColumnOutIfName: "Gi0/0/200",
|
||||
@@ -136,7 +136,7 @@ func TestEnrich(t *testing.T) {
|
||||
InIf: 100,
|
||||
OutIf: 200,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnInIfName: "Gi0/0/100",
|
||||
schema.ColumnOutIfName: "Gi0/0/200",
|
||||
@@ -168,7 +168,7 @@ func TestEnrich(t *testing.T) {
|
||||
InIf: 100,
|
||||
OutIf: 200,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnExporterRegion: "asia",
|
||||
schema.ColumnExporterTenant: "alfred",
|
||||
@@ -202,7 +202,7 @@ func TestEnrich(t *testing.T) {
|
||||
InIf: 100,
|
||||
OutIf: 200,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnExporterTenant: "alfred",
|
||||
schema.ColumnInIfName: "Gi0/0/100",
|
||||
@@ -266,7 +266,7 @@ func TestEnrich(t *testing.T) {
|
||||
InIf: 100,
|
||||
OutIf: 200,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnInIfProvider: "index1",
|
||||
schema.ColumnOutIfProvider: "index2",
|
||||
@@ -299,7 +299,7 @@ func TestEnrich(t *testing.T) {
|
||||
InIf: 100,
|
||||
OutIf: 200,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnInIfName: "eth100",
|
||||
schema.ColumnOutIfName: "Gi0/0/200",
|
||||
@@ -333,7 +333,7 @@ func TestEnrich(t *testing.T) {
|
||||
SrcVlan: 10,
|
||||
DstVlan: 300,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnInIfName: "Gi0/0/100",
|
||||
schema.ColumnOutIfName: "Gi0/0/200.300",
|
||||
@@ -368,7 +368,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
|
||||
InIf: 100,
|
||||
OutIf: 200,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnInIfName: "Gi0/0/100",
|
||||
schema.ColumnOutIfName: "Gi0/0/200",
|
||||
@@ -401,7 +401,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
|
||||
InIf: 100,
|
||||
OutIf: 200,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnInIfName: "Gi0/0/100",
|
||||
schema.ColumnOutIfName: "Gi0/0/200",
|
||||
@@ -434,7 +434,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
|
||||
InIf: 100,
|
||||
OutIf: 200,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnInIfName: "Gi0/0/100",
|
||||
schema.ColumnOutIfName: "Gi0/0/200",
|
||||
@@ -468,7 +468,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
|
||||
InIf: 100,
|
||||
OutIf: 200,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnInIfName: "Gi0/0/100",
|
||||
schema.ColumnOutIfName: "Gi0/0/200",
|
||||
@@ -507,7 +507,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
|
||||
InIf: 1010,
|
||||
OutIf: 2010,
|
||||
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnExporterGroup: "metadata group",
|
||||
schema.ColumnExporterRegion: "metadata region",
|
||||
@@ -553,7 +553,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
|
||||
DstAS: 174,
|
||||
SrcNetMask: 27,
|
||||
DstNetMask: 27,
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnExporterName: "192_0_2_142",
|
||||
schema.ColumnInIfName: "Gi0/0/100",
|
||||
schema.ColumnOutIfName: "Gi0/0/200",
|
||||
|
||||
@@ -82,7 +82,7 @@ func TestCore(t *testing.T) {
|
||||
OutIf: out,
|
||||
SrcAddr: netip.MustParseAddr("::ffff:67.43.156.77"),
|
||||
DstAddr: netip.MustParseAddr("::ffff:2.125.160.216"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnBytes: 6765,
|
||||
schema.ColumnPackets: 4,
|
||||
schema.ColumnEType: 0x800,
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestDecodeMPLSAndIPv4(t *testing.T) {
|
||||
expected := schema.FlowMessage{
|
||||
SrcAddr: netip.MustParseAddr("::ffff:10.31.0.1"),
|
||||
DstAddr: netip.MustParseAddr("::ffff:10.34.0.1"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnEType: helpers.ETypeIPv4,
|
||||
schema.ColumnProto: 6,
|
||||
schema.ColumnSrcPort: 11001,
|
||||
@@ -54,7 +54,7 @@ func TestDecodeVLANAndIPv6(t *testing.T) {
|
||||
SrcVlan: 100,
|
||||
SrcAddr: netip.MustParseAddr("2402:f000:1:8e01::5555"),
|
||||
DstAddr: netip.MustParseAddr("2607:fcd0:100:2300::b108:2a6b"),
|
||||
OtherColumns: map[schema.ColumnKey]interface{}{
|
||||
OtherColumns: map[schema.ColumnKey]any{
|
||||
schema.ColumnEType: helpers.ETypeIPv6,
|
||||
schema.ColumnProto: 4,
|
||||
schema.ColumnIPTTL: 246,
|
||||
|
||||
@@ -54,7 +54,7 @@ func (nd *Decoder) decodeNFv5(packet *netflowlegacy.PacketNetFlowV5, ts, sysUpti
|
||||
}
|
||||
}
|
||||
|
||||
func (nd *Decoder) decodeNFv9IPFIX(version uint16, obsDomainID uint32, flowSets []interface{}, samplingRateSys *samplingRateSystem, ts, sysUptime uint64, options decoder.Option, bf *schema.FlowMessage, finalize decoder.FinalizeFlowFunc) {
|
||||
func (nd *Decoder) decodeNFv9IPFIX(version uint16, obsDomainID uint32, flowSets []any, samplingRateSys *samplingRateSystem, ts, sysUptime uint64, options decoder.Option, bf *schema.FlowMessage, finalize decoder.FinalizeFlowFunc) {
|
||||
// Look for sampling rate in option data flowsets
|
||||
for _, flowSet := range flowSets {
|
||||
switch tFlowSet := flowSet.(type) {
|
||||
|
||||
@@ -97,7 +97,7 @@ type templateSystem struct {
|
||||
templates netflow.NetFlowTemplateSystem
|
||||
}
|
||||
|
||||
func (s *templateSystem) AddTemplate(version uint16, obsDomainID uint32, templateID uint16, template interface{}) error {
|
||||
func (s *templateSystem) AddTemplate(version uint16, obsDomainID uint32, templateID uint16, template any) error {
|
||||
if err := s.templates.AddTemplate(version, obsDomainID, templateID, template); err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -125,11 +125,11 @@ func (s *templateSystem) AddTemplate(version uint16, obsDomainID uint32, templat
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *templateSystem) GetTemplate(version uint16, obsDomainID uint32, templateID uint16) (interface{}, error) {
|
||||
func (s *templateSystem) GetTemplate(version uint16, obsDomainID uint32, templateID uint16) (any, error) {
|
||||
return s.templates.GetTemplate(version, obsDomainID, templateID)
|
||||
}
|
||||
|
||||
func (s *templateSystem) RemoveTemplate(version uint16, obsDomainID uint32, templateID uint16) (interface{}, error) {
|
||||
func (s *templateSystem) RemoveTemplate(version uint16, obsDomainID uint32, templateID uint16) (any, error) {
|
||||
return s.templates.RemoveTemplate(version, obsDomainID, templateID)
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ func DefaultModels() []Model {
|
||||
// ConfigurationUnmarshallerHook normalize gnmi configuration:
|
||||
// - replace an occurrence of "default" in the list of models with the list of default models.
|
||||
func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc {
|
||||
return func(from, to reflect.Value) (interface{}, error) {
|
||||
return func(from, to reflect.Value) (any, error) {
|
||||
if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(Configuration{}) {
|
||||
return from.Interface(), nil
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc {
|
||||
val := helpers.ElemOrIdentity(modelsValue.Index(i))
|
||||
if val.Kind() == reflect.String && val.String() == "defaults" {
|
||||
// We need to replace this item with the default values.
|
||||
newValue := reflect.MakeSlice(reflect.SliceOf(reflect.TypeOf(new(interface{})).Elem()), 0, 0)
|
||||
newValue := reflect.MakeSlice(reflect.SliceOf(reflect.TypeOf(new(any)).Elem()), 0, 0)
|
||||
for j := range modelsValue.Len() {
|
||||
if i != j {
|
||||
newValue = reflect.Append(newValue, modelsValue.Index(j))
|
||||
|
||||
@@ -22,22 +22,22 @@ func TestDefaults(t *testing.T) {
|
||||
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
|
||||
{
|
||||
Description: "nil",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} { return nil },
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any { return nil },
|
||||
Expected: Configuration{},
|
||||
SkipValidation: true,
|
||||
}, {
|
||||
Description: "empty",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} { return gin.H{} },
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any { return gin.H{} },
|
||||
Expected: Configuration{},
|
||||
SkipValidation: true,
|
||||
}, {
|
||||
Description: "override models",
|
||||
Initial: func() interface{} {
|
||||
Initial: func() any {
|
||||
return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute}
|
||||
},
|
||||
Configuration: func() interface{} {
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"models": []gin.H{
|
||||
{
|
||||
@@ -73,10 +73,10 @@ func TestDefaults(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "defaults only",
|
||||
Initial: func() interface{} {
|
||||
Initial: func() any {
|
||||
return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute}
|
||||
},
|
||||
Configuration: func() interface{} {
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"models": []string{"defaults"},
|
||||
}
|
||||
@@ -88,12 +88,12 @@ func TestDefaults(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "defaults first",
|
||||
Initial: func() interface{} {
|
||||
Initial: func() any {
|
||||
return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute}
|
||||
},
|
||||
Configuration: func() interface{} {
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"models": []interface{}{
|
||||
"models": []any{
|
||||
"defaults",
|
||||
gin.H{
|
||||
"name": "custom",
|
||||
@@ -126,12 +126,12 @@ func TestDefaults(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "defaults last",
|
||||
Initial: func() interface{} {
|
||||
Initial: func() any {
|
||||
return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute}
|
||||
},
|
||||
Configuration: func() interface{} {
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"models": []interface{}{
|
||||
"models": []any{
|
||||
gin.H{
|
||||
"name": "custom",
|
||||
"if-index-paths": "/some/path",
|
||||
@@ -166,12 +166,12 @@ func TestDefaults(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "defaults in the middle",
|
||||
Initial: func() interface{} {
|
||||
Initial: func() any {
|
||||
return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute}
|
||||
},
|
||||
Configuration: func() interface{} {
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"models": []interface{}{
|
||||
"models": []any{
|
||||
gin.H{
|
||||
"name": "custom1",
|
||||
"if-index-paths": "/some/path",
|
||||
|
||||
@@ -66,7 +66,7 @@ func subscribeResponseToEvents(response *gnmi.SubscribeResponse) []event {
|
||||
}
|
||||
// For JSON, we need to walk the structure to create events. We
|
||||
// assume that we only get simple cases: no keys, no slice.
|
||||
var value interface{}
|
||||
var value any
|
||||
if err := json.Unmarshal(jsondata, &value); err != nil {
|
||||
continue
|
||||
}
|
||||
@@ -91,13 +91,13 @@ func subscribeResponsesToEvents(responses []*gnmi.SubscribeResponse) []event {
|
||||
|
||||
// jsonAppendToEvents appends the events derived from the provided event plus
|
||||
// the JSON-decoded value.
|
||||
func jsonAppendToEvents(events []event, ev event, value interface{}) []event {
|
||||
func jsonAppendToEvents(events []event, ev event, value any) []event {
|
||||
switch value := value.(type) {
|
||||
default:
|
||||
return events
|
||||
// Slices: not handled
|
||||
// Maps
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
for k, v := range value {
|
||||
currentEvent := ev
|
||||
currentEvent.Path = path.Join(currentEvent.Path, k)
|
||||
|
||||
@@ -66,7 +66,7 @@ func DefaultConfiguration() provider.Configuration {
|
||||
// - convert default-community to credentials (as ::/0)
|
||||
// - merge security parameters and communities into credentials
|
||||
func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc {
|
||||
return func(from, to reflect.Value) (interface{}, error) {
|
||||
return func(from, to reflect.Value) (any, error) {
|
||||
if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(Configuration{}) {
|
||||
return from.Interface(), nil
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
|
||||
{
|
||||
Description: "nil",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} { return nil },
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any { return nil },
|
||||
Expected: Configuration{},
|
||||
SkipValidation: true,
|
||||
}, {
|
||||
Description: "empty",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} { return gin.H{} },
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any { return gin.H{} },
|
||||
Expected: Configuration{
|
||||
Credentials: helpers.MustNewSubnetMap(map[string]Credentials{
|
||||
"::/0": {Communities: []string{"public"}},
|
||||
@@ -38,8 +38,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
SkipValidation: true,
|
||||
}, {
|
||||
Description: "single port",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"ports": "1161",
|
||||
@@ -56,8 +56,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "per-prefix port",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"ports": gin.H{
|
||||
@@ -78,8 +78,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "no communities, no default community",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-retries": 10,
|
||||
"poller-timeout": "200ms",
|
||||
@@ -94,8 +94,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "communities, no default community",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"communities": gin.H{
|
||||
@@ -114,8 +114,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "communities, default community",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"default-community": "private",
|
||||
@@ -135,8 +135,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "communities as a string",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"communities": "private",
|
||||
@@ -150,8 +150,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "communities, default-community empty",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"default-community": "",
|
||||
@@ -171,8 +171,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "SNMP security parameters",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"security-parameters": gin.H{
|
||||
@@ -198,8 +198,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "SNMP security parameters with AES256C",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"security-parameters": gin.H{
|
||||
@@ -225,8 +225,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "SNMP security parameters without privacy protocol",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"security-parameters": gin.H{
|
||||
@@ -248,8 +248,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "SNMP security parameters without authentication protocol",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"security-parameters": gin.H{
|
||||
@@ -262,8 +262,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
Error: true,
|
||||
}, {
|
||||
Description: "SNMP security parameters without authentication passphrase",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"security-parameters": gin.H{
|
||||
@@ -275,8 +275,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
Error: true,
|
||||
}, {
|
||||
Description: "SNMP security parameters without username",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"credentials": gin.H{
|
||||
@@ -290,8 +290,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
Error: true,
|
||||
}, {
|
||||
Description: "merge communities and security-parameters",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"communities": gin.H{
|
||||
@@ -321,8 +321,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "merge communities, security-parameters and credentials",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"communities": gin.H{
|
||||
@@ -358,8 +358,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "merge communities, security-parameters and default credentials",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"communities": gin.H{
|
||||
@@ -393,8 +393,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
|
||||
},
|
||||
}, {
|
||||
Description: "conflicting SNMP version",
|
||||
Initial: func() interface{} { return Configuration{} },
|
||||
Configuration: func() interface{} {
|
||||
Initial: func() any { return Configuration{} },
|
||||
Configuration: func() any {
|
||||
return gin.H{
|
||||
"poller-timeout": "200ms",
|
||||
"credentials": gin.H{
|
||||
|
||||
@@ -215,13 +215,13 @@ type goSNMPLogger struct {
|
||||
r *reporter.Reporter
|
||||
}
|
||||
|
||||
func (l *goSNMPLogger) Print(v ...interface{}) {
|
||||
func (l *goSNMPLogger) Print(v ...any) {
|
||||
if e := l.r.Debug(); e.Enabled() {
|
||||
e.Msg(fmt.Sprint(v...))
|
||||
}
|
||||
}
|
||||
|
||||
func (l *goSNMPLogger) Printf(format string, v ...interface{}) {
|
||||
func (l *goSNMPLogger) Printf(format string, v ...any) {
|
||||
if e := l.r.Debug(); e.Enabled() {
|
||||
e.Msg(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
@@ -143,91 +143,91 @@ func TestPoller(t *testing.T) {
|
||||
{
|
||||
OID: "1.3.6.1.2.1.1.5.0",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return "exporter62", nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.2.2.1.2.641",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/0", nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.2.2.1.2.642",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/1", nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.2.2.1.2.643",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/2", nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.2.2.1.2.645",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return "Correct description", nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.1.641",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/0", nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.1.642",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/1", nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.1.643",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/2", nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.1.645",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/5", nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.15.641",
|
||||
Type: gosnmp.Gauge32,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return uint(10000), nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.15.642",
|
||||
Type: gosnmp.Gauge32,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return uint(20000), nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.15.643",
|
||||
Type: gosnmp.Gauge32,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return uint(10000), nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.15.645",
|
||||
Type: gosnmp.Gauge32,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return uint(1000), nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.18.641",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return "Transit", nil
|
||||
},
|
||||
}, {
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.18.642",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return "Peering", nil
|
||||
},
|
||||
},
|
||||
@@ -235,7 +235,7 @@ func TestPoller(t *testing.T) {
|
||||
{
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.18.645",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (interface{}, error) {
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/5", nil
|
||||
},
|
||||
},
|
||||
|
||||
@@ -28,7 +28,7 @@ type ProviderConfiguration struct {
|
||||
}
|
||||
|
||||
// MarshalYAML undoes ConfigurationUnmarshallerHook().
|
||||
func (pc ProviderConfiguration) MarshalYAML() (interface{}, error) {
|
||||
func (pc ProviderConfiguration) MarshalYAML() (any, error) {
|
||||
return helpers.ParametrizedConfigurationMarshalYAML(pc, providers)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user