From cb2dbb0eccc29d0e478053515b76cc0d0f5f33f6 Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov <58589910+Ex4amp1e@users.noreply.github.com> Date: Tue, 19 Nov 2024 15:12:50 +0500 Subject: [PATCH] Upgrade go to v1.23 (#1664) * Upgrade go to v1.23 Signed-off-by: Vladislav Byrgazov * Update linter config Signed-off-by: Vladislav Byrgazov * Add todo to fix linters Signed-off-by: Vladislav Byrgazov * Skip TestNSMGRHealEndpoint_DatapathHealthy_CtrlPlaneBroken test Signed-off-by: Vladislav Byrgazov --------- Signed-off-by: Vladislav Byrgazov Co-authored-by: Vladislav Byrgazov --- .ci/yamllint.yml | 2 + .github/workflows/ci.yaml | 6 +- .golangci.yml | 138 +++++++----------- go.mod | 2 +- go.sum | 23 +++ .../chains/endpoint/combine_test.go | 1 - pkg/networkservice/chains/nsmgr/heal_test.go | 7 +- .../chains/nsmgr/reselect_test.go | 4 +- .../common/clientinfo/client_test.go | 3 +- .../monitor/monitor_connection_server.go | 3 +- .../common/switchcase/client_test.go | 4 +- .../common/switchcase/common_test.go | 4 +- .../common/switchcase/server_test.go | 4 +- .../connectioncontext/ipcontext/vl3/ipam.go | 8 - pkg/registry/common/authorize/common.go | 4 +- pkg/registry/common/authorize/ns_client.go | 22 +-- pkg/registry/common/authorize/ns_server.go | 18 +-- .../common/authorize/ns_server_test.go | 2 +- pkg/registry/common/authorize/nse_client.go | 22 +-- pkg/registry/common/authorize/nse_server.go | 18 +-- .../common/authorize/nse_server_test.go | 2 +- pkg/registry/common/authorize/options.go | 10 +- pkg/registry/common/clientinfo/client_test.go | 3 +- pkg/registry/common/clientinfo/server_test.go | 3 +- pkg/registry/common/dnsresolve/ns_server.go | 12 +- pkg/registry/common/dnsresolve/nse_server.go | 14 +- pkg/registry/common/recvfd/server_notlinux.go | 5 +- pkg/registry/common/updatepath/common.go | 12 +- pkg/registry/common/updatepath/ns_server.go | 10 +- pkg/registry/common/updatepath/nse_server.go | 8 +- pkg/tools/clockmock/mock_test.go | 4 +- pkg/tools/debug/self.go | 6 +- pkg/tools/log/logruslogger/logruslogger.go | 4 +- pkg/tools/matchutils/utils_test.go | 5 +- .../monitorconnection/authorize/server.go | 6 +- .../authorize/server_test.go | 6 +- pkg/tools/nanoid/generator_test.go | 14 +- pkg/tools/opa/registry_client_allowed_test.go | 8 +- .../opa/service_connection_policy_test.go | 6 +- 39 files changed, 191 insertions(+), 242 deletions(-) diff --git a/.ci/yamllint.yml b/.ci/yamllint.yml index d4a3b49db..ef3c765b5 100644 --- a/.ci/yamllint.yml +++ b/.ci/yamllint.yml @@ -11,5 +11,7 @@ rules: line-length: disable comments-indentation: ignore: .circleci/config.yml + comments: + min-spaces-from-content: 1 ignore: scripts/aws/aws-k8s-cni.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9fc348db9..b88066568 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,7 +17,7 @@ jobs: golangci-lint: uses: networkservicemesh/.github/.github/workflows/golangci-lint.yaml@main with: - linter-version: v1.53.3 + linter-version: v1.60.3 exclude-fmt-errorf: uses: networkservicemesh/.github/.github/workflows/exclude-fmt-errorf.yaml@main @@ -45,9 +45,9 @@ jobs: - name: Check out code uses: actions/checkout@v2 - name: Setup Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v5 with: - go-version: 1.20.5 + go-version: 1.23.1 - run: | go test -coverprofile=coverage-${{ matrix.os }}.txt -covermode=atomic -race ./... - name: Upload coverage reports to Codecov with GitHub Action diff --git a/.golangci.yml b/.golangci.yml index 3d9c8b0fe..6816afee2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,7 @@ --- run: # concurrency: 6 - go: "1.20" + go: "1.23" timeout: 2m issues-exit-code: 1 tests: true @@ -11,13 +11,14 @@ linters-settings: values: regexp: company: .* - copyright-holder: Copyright \(c\) ({{year-range}}) {{company}}\n\n + copyright-holder: Copyright \(c\) ({{mod-year-range}}) {{company}}\n\n copyright-holders: ({{copyright-holder}})+ errcheck: check-type-assertions: false check-blank: false govet: - check-shadowing: true + enable: + - shadow settings: printf: funcs: @@ -25,19 +26,38 @@ linters-settings: - (github.com/sirupsen/logrus.FieldLogger).Warnf - (github.com/sirupsen/logrus.FieldLogger).Errorf - (github.com/sirupsen/logrus.FieldLogger).Fatalf - golint: - min-confidence: 0.8 + revive: + confidence: 0.8 + rules: + - name: exported + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: error-return + - name: error-strings + - name: error-naming + - name: exported + - name: increment-decrement + - name: var-naming + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: superfluous-else + - name: unreachable-code goimports: local-prefixes: github.com/networkservicemesh/sdk gocyclo: min-complexity: 15 - maligned: - suggest-new: true dupl: threshold: 150 funlen: - Lines: 120 - Statements: 60 + lines: 120 + statements: 60 goconst: min-len: 2 min-occurrences: 2 @@ -57,79 +77,55 @@ linters-settings: simple: true range-loops: true for-loops: false + # TODO - Fix gosec linter errors - https://github.com/networkservicemesh/sdk/issues/1690 + gosec: + excludes: + - G115 + - G204 + - G301 + - G302 + - G306 gocritic: enabled-checks: - - appendAssign - - assignOp - appendCombine - - argOrder - - badCall - - badCond - boolExprSimplify - builtinShadow - - captLocal - - caseOrder - - codegenComment - - commentFormatting - commentedOutCode - commentedOutImport - - defaultCaseOrder - - deprecatedComment - docStub - - dupArg - - dupBranchBody - - dupCase - dupImport - - dupSubExpr - - elseif - emptyFallthrough - emptyStringTest - equalFold - evalOrder - - exitAfterDefer - - flagDeref - - flagName - hexLiteral - hugeParam - - ifElseChain - importShadow - indexAlloc - initClause - methodExprCall - nestingReduce - - newDeref - nilValReturn - octalLiteral - - offBy1 - paramTypeCombine - rangeExprCopy - rangeValCopy - - regexpMust - regexpPattern - - singleCaseSwitch - - sloppyLen - sloppyReassign - stringXbytes - - switchTrue - typeAssertChain - - typeSwitchVar - typeUnparen - unlabelStmt - unnamedResult - unnecessaryBlock - - underef - - unlambda - - unslice - - valSwap - weakCond - - wrapperFunc - yodaStyleExpr linters: disable-all: true enable: - goheader - bodyclose - - deadcode + - unused - depguard - dogsled - dupl @@ -141,22 +137,19 @@ linters: - gocyclo - gofmt - goimports - - golint + - revive - gosec - gosimple - govet - ineffassign - - interfacer - misspell - nakedret - - scopelint + - copyloopvar - staticcheck - - structcheck - stylecheck - typecheck - unconvert - unparam - - varcheck - whitespace issues: exclude-use-default: false @@ -165,13 +158,6 @@ issues: exclude-rules: # We really *do* want to pass a pointer to an interface in these cases. See comments in file for New{Server,Client} # function for why - - path: .*\.gen\.go - linters: - - dupl - - golint - - path: pkg/tools/opa/policies.go - linters: - - golint - path: .*registry.*.go linters: - dupl @@ -211,10 +197,6 @@ issues: linters: - dupl text: "lines are duplicate of" - - path: pkg/tools/spiffeutils/spiffeutils.go - linters: - - interfacer - text: "can be `fmt.Stringer`" - path: pkg/networkservice/core/trace/client.go linters: - dupl @@ -227,30 +209,10 @@ issues: linters: - dupl text: "lines are duplicate of" - - path: pkg/tools/spiffeutils/tls_peer.go - linters: - - gosec - text: "G402: TLS InsecureSkipVerify set true" - path: pkg/networkservice/common/updatepath/server_test.go linters: - gochecknoinits text: "don't use `init` function" - - path: pkg/tools/debug/self.go - linters: - - gosec - text: "G204: Subprocess launched with variable" - - path: pkg/tools/executils/start.go - linters: - - gosec - text: "G204: Subprocess launched with variable" - - path: pkg/tools/executils/run.go - linters: - - gosec - text: "G204: Subprocess launched with variable" - - path: pkg/tools/executils/output.go - linters: - - gosec - text: "G204: Subprocess launched with variable" - path: pkg/tools/spire/start.go linters: - funlen @@ -269,14 +231,6 @@ issues: - path: pkg/networkservice/chains/nsmgr/single_test.go linters: - funlen - - path: pkg/registry/common/recvfd/gen.go - linters: - - structcheck - text: "is unused" - - path: pkg/networkservice/common/mechanisms/recvfd/gen.go - linters: - - structcheck - text: "is unused" - path: pkg/networkservice/common/discover/server_test.go linters: - dupl @@ -293,10 +247,16 @@ issues: - path: pkg/networkservice/common/switchcase/.*_test.go linters: - dupl - - path: pkg/networkservice/chains/endpoint/combine_monitor_server.go + - path: pkg/tools/ippool/ippool.go + linters: + - unused + - path: pkg/networkservice/common/switchcase/common_test.go + linters: + - revive + - path: pkg/tools/opa/policies.go linters: - - interfacer - text: "`rawSrv` can be `github.com/networkservicemesh/sdk/pkg/networkservice/common/monitor.EventConsumer`" + - revive + # TODO - remove deprecated opentelemetry functions - https://github.com/networkservicemesh/sdk/issues/1691 - path: pkg/tools/tracing/grpcoptions.go linters: - staticcheck diff --git a/go.mod b/go.mod index 23763a260..fdd6b9156 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/networkservicemesh/sdk -go 1.20 +go 1.23 require ( github.com/RoaringBitmap/roaring v0.9.4 diff --git a/go.sum b/go.sum index 627615c88..f67ccdc14 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,7 @@ cloud.google.com/go v0.110.2 h1:sdFPBr6xG9/wkBbfhmUz/JmZC7X6LavQgcrVINrKiVA= cloud.google.com/go/compute v1.23.1 h1:V97tBoDaZHb6leicZ1G6DLK2BAaZLJ/7+9BB/En3hR0= cloud.google.com/go/compute v1.23.1/go.mod h1:CqB3xpmPKKt3OJpW2ndFIXnA9A4xAy/F3Xp1ixncW78= cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= +cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= @@ -15,6 +16,7 @@ github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRB github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/antonfisher/nested-logrus-formatter v1.3.1 h1:NFJIr+pzwv5QLHTPyKz9UMEoHck02Q9L0FP13b/xSbQ= github.com/antonfisher/nested-logrus-formatter v1.3.1/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= @@ -34,6 +36,7 @@ github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqy github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= @@ -41,14 +44,18 @@ github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k= +github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/badger/v3 v3.2103.2 h1:dpyM5eCJAtQCBcMCZcT4UBZchuTJgCywerHHgmxfxM8= +github.com/dgraph-io/badger/v3 v3.2103.2/go.mod h1:RHo4/GmYcKKh5Lxu63wLEMHJ70Pac2JqZRYGhlyAo2M= github.com/dgraph-io/ristretto v0.1.0 h1:Jv3CGQHp9OjuMBSne1485aDpUkTKEcUqF+jm/LuerPI= +github.com/dgraph-io/ristretto v0.1.0/go.mod h1:fux0lOrBhrVCJd3lcTHsIJhq1T2rokOu6v9Vcb3Q9ug= github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g= github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/edwarnicke/exechelper v1.0.2 h1:dD49Ui2U0FBFxxhalnKw6vLS0P0TkgnXBRvKL/xmC5w= github.com/edwarnicke/exechelper v1.0.2/go.mod h1:/T271jtNX/ND4De6pa2aRy2+8sNtyCDB1A2pp4M+fUs= github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29 h1:4/2wgileNvQB4HfJbq7u4FFLKIfc38a6P0S/51ZGgX8= @@ -63,11 +70,14 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA= +github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= +github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/foxcpp/go-mockdns v0.0.0-20210729171921-fb145fc6f897 h1:E52jfcE64UG42SwLmrW0QByONfGynWuzBvm86BoB9z8= +github.com/foxcpp/go-mockdns v0.0.0-20210729171921-fb145fc6f897/go.mod h1:lgRN6+KxQBawyIghpnl5CezHFGS9VLzvtVlwxvzXTQ4= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= @@ -90,8 +100,10 @@ github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= +github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -108,6 +120,7 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/flatbuffers v2.0.8+incompatible h1:ivUb1cGomAB101ZM1T0nOiWz9pSrTMoa9+EiY7igmkM= github.com/google/flatbuffers v2.0.8+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -140,6 +153,7 @@ github.com/hashicorp/go-msgpack v1.1.5/go.mod h1:gWVc3sv/wbDmR3rQsj1CAktEZzoz1YN github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= +github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -153,9 +167,11 @@ github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGC github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk= github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= @@ -226,7 +242,9 @@ github.com/r3labs/diff v1.1.0/go.mod h1:7WjXasNzi0vJetRcB/RqNl5dlIsmXcTTLmF5IoH6 github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spiffe/go-spiffe/v2 v2.1.7 h1:VUkM1yIyg/x8X7u1uXqSRVRCdMdfRIEdFBzpqoeASGk= @@ -339,6 +357,7 @@ golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY= +golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -350,6 +369,7 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -420,10 +440,12 @@ gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= +google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b h1:+YaDE2r2OG8t/z5qmsh7Y+XXwCbvadxxZ0YY6mTdrVA= +google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:CgAqfJo+Xmu0GwA0411Ht3OU3OntXwsGmrmjI8ioGXI= google.golang.org/genproto/googleapis/api v0.0.0-20231012201019-e917dd12ba7a h1:myvhA4is3vrit1a6NZCWBIwN0kNEnX21DJOJX/NvIfI= google.golang.org/genproto/googleapis/api v0.0.0-20231012201019-e917dd12ba7a/go.mod h1:SUBoKXbI1Efip18FClrQVGjWcyd0QZd8KkvdP34t7ww= google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 h1:AB/lmRny7e2pLhFEYIbl5qkDAUt2h0ZRO4wGPhZf+ik= @@ -452,6 +474,7 @@ google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHh gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/pkg/networkservice/chains/endpoint/combine_test.go b/pkg/networkservice/chains/endpoint/combine_test.go index f65012a23..7e8fca0b3 100644 --- a/pkg/networkservice/chains/endpoint/combine_test.go +++ b/pkg/networkservice/chains/endpoint/combine_test.go @@ -73,7 +73,6 @@ func TestCombine(t *testing.T) { for _, s := range samples { t.Run(s.name, func(t *testing.T) { - // nolint:scopelint testCombine(t, s.mechanism) }) } diff --git a/pkg/networkservice/chains/nsmgr/heal_test.go b/pkg/networkservice/chains/nsmgr/heal_test.go index ac54b5b22..f395e908a 100644 --- a/pkg/networkservice/chains/nsmgr/heal_test.go +++ b/pkg/networkservice/chains/nsmgr/heal_test.go @@ -69,7 +69,6 @@ func TestNSMGR_HealEndpoint(t *testing.T) { for _, sample := range samples { t.Run(sample.name, func(t *testing.T) { - // nolint:scopelint testNSMGRHealEndpoint(t, sample.nodeNum) }) } @@ -249,6 +248,8 @@ func TestNSMGRHealEndpoint_DataPlaneBroken_CtrlPlaneHealthy(t *testing.T) { } func TestNSMGRHealEndpoint_DatapathHealthy_CtrlPlaneBroken(t *testing.T) { + t.Skip("https://github.com/networkservicemesh/sdk/issues/1573") + t.Cleanup(func() { goleak.VerifyNone(t) }) ctx, cancel := context.WithTimeout(context.Background(), timeout) @@ -309,7 +310,6 @@ func TestNSMGR_HealForwarder(t *testing.T) { for _, sample := range samples { t.Run(sample.name, func(t *testing.T) { - // nolint:scopelint testNSMGRHealForwarder(t, sample.nodeNum) }) } @@ -391,7 +391,6 @@ func TestNSMGR_HealNSMgr(t *testing.T) { for _, sample := range samples { t.Run(sample.name, func(t *testing.T) { - // nolint:scopelint testNSMGRHealNSMgr(t, sample.nodeNum, sample.restored) }) } @@ -531,7 +530,6 @@ func TestNSMGR_CloseHeal(t *testing.T) { for _, sample := range samples { t.Run(sample.name, func(t *testing.T) { - // nolint:scopelint testNSMGRCloseHeal(t, sample.withNSEExpiration) }) } @@ -645,7 +643,6 @@ func Test_ForwarderShouldBeSelectedCorrectlyOnNSMgrRestart(t *testing.T) { for _, sample := range samples { t.Run(sample.name, func(t *testing.T) { - // nolint:scopelint testForwarderShouldBeSelectedCorrectlyOnNSMgrRestart(t, sample.nodeNum, sample.pathSegmentCount) }) } diff --git a/pkg/networkservice/chains/nsmgr/reselect_test.go b/pkg/networkservice/chains/nsmgr/reselect_test.go index 0f0cffb09..1a5bac772 100644 --- a/pkg/networkservice/chains/nsmgr/reselect_test.go +++ b/pkg/networkservice/chains/nsmgr/reselect_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2023 Cisco and/or its affiliates. +// Copyright (c) 2023-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -64,7 +64,6 @@ func TestReselect_NsmgrRestart(t *testing.T) { for _, sample := range samples { t.Run(sample.name, func(t *testing.T) { - // nolint:scopelint testReselectWithNsmgrRestart(t, sample.nodeNum, sample.restartLocal, sample.restartRemote) }) } @@ -178,7 +177,6 @@ func TestReselect_LocalForwarderRestart(t *testing.T) { for _, sample := range samples { t.Run(sample.name, func(t *testing.T) { - // nolint:scopelint testReselectWithLocalForwarderRestart(t, sample.nodeNum) }) } diff --git a/pkg/networkservice/common/clientinfo/client_test.go b/pkg/networkservice/common/clientinfo/client_test.go index 42abfd1ec..d412b8e71 100644 --- a/pkg/networkservice/common/clientinfo/client_test.go +++ b/pkg/networkservice/common/clientinfo/client_test.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2021 Doc.ai and/or its affiliates. // +// Copyright (c) 2024 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -133,7 +135,6 @@ func TestClientInfo(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { err := setEnvs(tc.envs) require.NoError(t, err) diff --git a/pkg/networkservice/common/monitor/monitor_connection_server.go b/pkg/networkservice/common/monitor/monitor_connection_server.go index 2403c0dc3..7bc31e56a 100644 --- a/pkg/networkservice/common/monitor/monitor_connection_server.go +++ b/pkg/networkservice/common/monitor/monitor_connection_server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021-2023 Cisco and/or its affiliates. +// Copyright (c) 2021-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -82,7 +82,6 @@ func (m *monitorConnectionServer) Send(event *networkservice.ConnectionEvent) (_ return } for id, filter := range m.filters { - id, filter := id, filter e := event.Clone() filter.executor.AsyncExec(func() { var err error diff --git a/pkg/networkservice/common/switchcase/client_test.go b/pkg/networkservice/common/switchcase/client_test.go index 275bc2148..fb85c853c 100644 --- a/pkg/networkservice/common/switchcase/client_test.go +++ b/pkg/networkservice/common/switchcase/client_test.go @@ -1,5 +1,7 @@ // Copyright (c) 2021 Doc.ai and/or its affiliates. // +// Copyright (c) 2024 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,7 +35,6 @@ import ( func TestSwitchClient(t *testing.T) { for _, s := range testSamples() { t.Run(s.name, func(t *testing.T) { - // nolint:scopelint testSwitchClient(t, s.conditions, s.result) }) } @@ -44,7 +45,6 @@ func testSwitchClient(t *testing.T, conditions []switchcase.Condition, expected var cases []*switchcase.ClientCase for i, cond := range conditions { - i := i cases = append(cases, &switchcase.ClientCase{ Condition: cond, Client: checkcontext.NewClient(t, func(*testing.T, context.Context) { diff --git a/pkg/networkservice/common/switchcase/common_test.go b/pkg/networkservice/common/switchcase/common_test.go index 3ee81c03b..c0f888349 100644 --- a/pkg/networkservice/common/switchcase/common_test.go +++ b/pkg/networkservice/common/switchcase/common_test.go @@ -1,5 +1,7 @@ // Copyright (c) 2021 Doc.ai and/or its affiliates. // +// Copyright (c) 2024 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -70,6 +72,6 @@ func condition(n int) switchcase.Condition { } func withN(ctx context.Context, n int) context.Context { - // nolint:golint,staticcheck + // nolint:staticcheck return context.WithValue(ctx, "key", n) } diff --git a/pkg/networkservice/common/switchcase/server_test.go b/pkg/networkservice/common/switchcase/server_test.go index f643ca86c..d20e3b427 100644 --- a/pkg/networkservice/common/switchcase/server_test.go +++ b/pkg/networkservice/common/switchcase/server_test.go @@ -1,5 +1,7 @@ // Copyright (c) 2021 Doc.ai and/or its affiliates. // +// Copyright (c) 2024 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,7 +35,6 @@ import ( func TestSwitchServer(t *testing.T) { for _, s := range testSamples() { t.Run(s.name, func(t *testing.T) { - // nolint:scopelint testSwitchServer(t, s.conditions, s.result) }) } @@ -44,7 +45,6 @@ func testSwitchServer(t *testing.T, conditions []switchcase.Condition, expected var cases []*switchcase.ServerCase for i, cond := range conditions { - i := i cases = append(cases, &switchcase.ServerCase{ Condition: cond, Server: checkcontext.NewServer(t, func(*testing.T, context.Context) { diff --git a/pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go b/pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go index 6973db61d..75a1b2ad4 100644 --- a/pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go +++ b/pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go @@ -137,14 +137,6 @@ func (p *IPAM) freeIfAllocated(ipNet string) { } } -func (p *IPAM) isExcluded(ipNet string) bool { - p.Lock() - defer p.Unlock() - - _, r := p.excludedPrefixes[ipNet] - return r -} - // Reset resets IPAM's ippol by setting new prefix func (p *IPAM) Reset(prefix string, excludePrefixes ...string) error { p.Lock() diff --git a/pkg/registry/common/authorize/common.go b/pkg/registry/common/authorize/common.go index b0aca2086..203e1d1f0 100644 --- a/pkg/registry/common/authorize/common.go +++ b/pkg/registry/common/authorize/common.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022-2023 Cisco and/or its affiliates. +// Copyright (c) 2022-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -32,7 +32,7 @@ import ( type RegistryOpaInput struct { ResourceID string `json:"resource_id"` ResourceName string `json:"resource_name"` - ResourcePathIdsMap map[string][]string `json:"resource_path_ids_map"` + ResourcePathIDsMap map[string][]string `json:"resource_path_ids_map"` PathSegments []*grpcmetadata.PathSegment `json:"path_segments"` Index uint32 `json:"index"` } diff --git a/pkg/registry/common/authorize/ns_client.go b/pkg/registry/common/authorize/ns_client.go index 7a24454be..ae9710361 100644 --- a/pkg/registry/common/authorize/ns_client.go +++ b/pkg/registry/common/authorize/ns_client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022-2023 Cisco and/or its affiliates. +// Copyright (c) 2022-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -35,14 +35,14 @@ import ( type authorizeNSClient struct { policies policiesList - nsPathIdsMap *genericsync.Map[string, []string] + nsPathIDsMap *genericsync.Map[string, []string] } // NewNetworkServiceRegistryClient - returns a new authorization registry.NetworkServiceRegistryClient // Authorize registry client checks spiffeID of NS. func NewNetworkServiceRegistryClient(opts ...Option) registry.NetworkServiceRegistryClient { o := &options{ - resourcePathIdsMap: new(genericsync.Map[string, []string]), + resourcePathIDsMap: new(genericsync.Map[string, []string]), } for _, opt := range opts { @@ -51,7 +51,7 @@ func NewNetworkServiceRegistryClient(opts ...Option) registry.NetworkServiceRegi return &authorizeNSClient{ policies: o.policies, - nsPathIdsMap: o.resourcePathIdsMap, + nsPathIDsMap: o.resourcePathIDsMap, } } @@ -79,17 +79,17 @@ func (c *authorizeNSClient) Register(ctx context.Context, ns *registry.NetworkSe path = grpcmetadata.PathFromContext(ctx) spiffeID := getSpiffeIDFromPath(ctx, path) - rawMap := getRawMap(c.nsPathIdsMap) + rawMap := getRawMap(c.nsPathIDsMap) input := RegistryOpaInput{ ResourceID: spiffeID.String(), ResourceName: resp.Name, - ResourcePathIdsMap: rawMap, + ResourcePathIDsMap: rawMap, PathSegments: path.PathSegments, Index: path.Index, } if err := c.policies.check(ctx, input); err != nil { - if _, load := c.nsPathIdsMap.Load(resp.Name); !load { + if _, load := c.nsPathIDsMap.Load(resp.Name); !load { unregisterCtx, cancelUnregister := postponeCtxFunc() defer cancelUnregister() @@ -101,7 +101,7 @@ func (c *authorizeNSClient) Register(ctx context.Context, ns *registry.NetworkSe return nil, err } - c.nsPathIdsMap.Store(resp.Name, resp.PathIds) + c.nsPathIDsMap.Store(resp.Name, resp.PathIds) return resp, nil } @@ -130,12 +130,12 @@ func (c *authorizeNSClient) Unregister(ctx context.Context, ns *registry.Network } spiffeID := getSpiffeIDFromPath(ctx, path) - rawMap := getRawMap(c.nsPathIdsMap) + rawMap := getRawMap(c.nsPathIDsMap) input := RegistryOpaInput{ ResourceID: spiffeID.String(), ResourceName: ns.Name, - ResourcePathIdsMap: rawMap, + ResourcePathIDsMap: rawMap, PathSegments: path.PathSegments, Index: path.Index, } @@ -143,6 +143,6 @@ func (c *authorizeNSClient) Unregister(ctx context.Context, ns *registry.Network return nil, err } - c.nsPathIdsMap.Delete(ns.Name) + c.nsPathIDsMap.Delete(ns.Name) return resp, nil } diff --git a/pkg/registry/common/authorize/ns_server.go b/pkg/registry/common/authorize/ns_server.go index 9dfb8933b..38214c9d6 100644 --- a/pkg/registry/common/authorize/ns_server.go +++ b/pkg/registry/common/authorize/ns_server.go @@ -31,14 +31,14 @@ import ( type authorizeNSServer struct { policies policiesList - nsPathIdsMap *genericsync.Map[string, []string] + nsPathIDsMap *genericsync.Map[string, []string] } // NewNetworkServiceRegistryServer - returns a new authorization registry.NetworkServiceRegistryServer // Authorize registry server checks spiffeID of NS. func NewNetworkServiceRegistryServer(opts ...Option) registry.NetworkServiceRegistryServer { o := &options{ - resourcePathIdsMap: new(genericsync.Map[string, []string]), + resourcePathIDsMap: new(genericsync.Map[string, []string]), } for _, opt := range opts { @@ -47,7 +47,7 @@ func NewNetworkServiceRegistryServer(opts ...Option) registry.NetworkServiceRegi return &authorizeNSServer{ policies: o.policies, - nsPathIdsMap: o.resourcePathIdsMap, + nsPathIDsMap: o.resourcePathIDsMap, } } @@ -60,11 +60,11 @@ func (s *authorizeNSServer) Register(ctx context.Context, ns *registry.NetworkSe spiffeID := getSpiffeIDFromPath(ctx, path) leftSide := getLeftSideOfPath(path) - rawMap := getRawMap(s.nsPathIdsMap) + rawMap := getRawMap(s.nsPathIDsMap) input := RegistryOpaInput{ ResourceID: spiffeID.String(), ResourceName: ns.Name, - ResourcePathIdsMap: rawMap, + ResourcePathIDsMap: rawMap, PathSegments: leftSide.PathSegments, Index: leftSide.Index, } @@ -76,7 +76,7 @@ func (s *authorizeNSServer) Register(ctx context.Context, ns *registry.NetworkSe if err != nil { return nil, err } - s.nsPathIdsMap.Store(ns.Name, ns.PathIds) + s.nsPathIDsMap.Store(ns.Name, ns.PathIds) return ns, nil } @@ -93,11 +93,11 @@ func (s *authorizeNSServer) Unregister(ctx context.Context, ns *registry.Network spiffeID := getSpiffeIDFromPath(ctx, path) leftSide := getLeftSideOfPath(path) - rawMap := getRawMap(s.nsPathIdsMap) + rawMap := getRawMap(s.nsPathIDsMap) input := RegistryOpaInput{ ResourceID: spiffeID.String(), ResourceName: ns.Name, - ResourcePathIdsMap: rawMap, + ResourcePathIDsMap: rawMap, PathSegments: leftSide.PathSegments, Index: leftSide.Index, } @@ -105,6 +105,6 @@ func (s *authorizeNSServer) Unregister(ctx context.Context, ns *registry.Network return nil, err } - s.nsPathIdsMap.Delete(ns.Name) + s.nsPathIDsMap.Delete(ns.Name) return next.NetworkServiceRegistryServer(ctx).Unregister(ctx, ns) } diff --git a/pkg/registry/common/authorize/ns_server_test.go b/pkg/registry/common/authorize/ns_server_test.go index 09ebb9c8e..77d9d59ad 100644 --- a/pkg/registry/common/authorize/ns_server_test.go +++ b/pkg/registry/common/authorize/ns_server_test.go @@ -107,7 +107,7 @@ func TestNetworkServiceRegistryAuthorize_ResourcePathIdMapHaveNoLeaks(t *testing server := next.NewNetworkServiceRegistryServer( authorize.NewNetworkServiceRegistryServer( authorize.WithPolicies("etc/nsm/opa/registry/client_allowed.rego"), - authorize.WithResourcePathIdsMap(&authorizeMap)), + authorize.WithResourcePathIDsMap(&authorizeMap)), NewNetworkServiceRegistryServer(0.5), ) diff --git a/pkg/registry/common/authorize/nse_client.go b/pkg/registry/common/authorize/nse_client.go index 70b324462..1f7a6d77f 100644 --- a/pkg/registry/common/authorize/nse_client.go +++ b/pkg/registry/common/authorize/nse_client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022-2023 Cisco and/or its affiliates. +// Copyright (c) 2022-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -35,14 +35,14 @@ import ( type authorizeNSEClient struct { policies policiesList - nsePathIdsMap *genericsync.Map[string, []string] + nsePathIDsMap *genericsync.Map[string, []string] } // NewNetworkServiceEndpointRegistryClient - returns a new authorization registry.NetworkServiceEndpointRegistryClient // Authorize registry client checks path of NSE. func NewNetworkServiceEndpointRegistryClient(opts ...Option) registry.NetworkServiceEndpointRegistryClient { o := &options{ - resourcePathIdsMap: new(genericsync.Map[string, []string]), + resourcePathIDsMap: new(genericsync.Map[string, []string]), } for _, opt := range opts { @@ -51,7 +51,7 @@ func NewNetworkServiceEndpointRegistryClient(opts ...Option) registry.NetworkSer return &authorizeNSEClient{ policies: o.policies, - nsePathIdsMap: o.resourcePathIdsMap, + nsePathIDsMap: o.resourcePathIDsMap, } } @@ -79,16 +79,16 @@ func (c *authorizeNSEClient) Register(ctx context.Context, nse *registry.Network } spiffeID := getSpiffeIDFromPath(ctx, path) - rawMap := getRawMap(c.nsePathIdsMap) + rawMap := getRawMap(c.nsePathIDsMap) input := RegistryOpaInput{ ResourceID: spiffeID.String(), ResourceName: resp.Name, - ResourcePathIdsMap: rawMap, + ResourcePathIDsMap: rawMap, PathSegments: path.PathSegments, Index: path.Index, } if err := c.policies.check(ctx, input); err != nil { - if _, load := c.nsePathIdsMap.Load(resp.Name); !load { + if _, load := c.nsePathIDsMap.Load(resp.Name); !load { unregisterCtx, cancelUnregister := postponeCtxFunc() defer cancelUnregister() @@ -100,7 +100,7 @@ func (c *authorizeNSEClient) Register(ctx context.Context, nse *registry.Network return nil, err } - c.nsePathIdsMap.Store(resp.Name, resp.PathIds) + c.nsePathIDsMap.Store(resp.Name, resp.PathIds) return resp, nil } @@ -129,11 +129,11 @@ func (c *authorizeNSEClient) Unregister(ctx context.Context, nse *registry.Netwo } spiffeID := getSpiffeIDFromPath(ctx, path) - rawMap := getRawMap(c.nsePathIdsMap) + rawMap := getRawMap(c.nsePathIDsMap) input := RegistryOpaInput{ ResourceID: spiffeID.String(), ResourceName: nse.Name, - ResourcePathIdsMap: rawMap, + ResourcePathIDsMap: rawMap, PathSegments: path.PathSegments, Index: path.Index, } @@ -142,6 +142,6 @@ func (c *authorizeNSEClient) Unregister(ctx context.Context, nse *registry.Netwo return nil, err } - c.nsePathIdsMap.Delete(nse.Name) + c.nsePathIDsMap.Delete(nse.Name) return resp, nil } diff --git a/pkg/registry/common/authorize/nse_server.go b/pkg/registry/common/authorize/nse_server.go index 8851ae0ef..6ccbadc3b 100644 --- a/pkg/registry/common/authorize/nse_server.go +++ b/pkg/registry/common/authorize/nse_server.go @@ -31,14 +31,14 @@ import ( type authorizeNSEServer struct { policies policiesList - nsePathIdsMap *genericsync.Map[string, []string] + nsePathIDsMap *genericsync.Map[string, []string] } // NewNetworkServiceEndpointRegistryServer - returns a new authorization registry.NetworkServiceEndpointRegistryServer // Authorize registry server checks spiffeID of NSE. func NewNetworkServiceEndpointRegistryServer(opts ...Option) registry.NetworkServiceEndpointRegistryServer { o := &options{ - resourcePathIdsMap: new(genericsync.Map[string, []string]), + resourcePathIDsMap: new(genericsync.Map[string, []string]), } for _, opt := range opts { @@ -47,7 +47,7 @@ func NewNetworkServiceEndpointRegistryServer(opts ...Option) registry.NetworkSer return &authorizeNSEServer{ policies: o.policies, - nsePathIdsMap: o.resourcePathIdsMap, + nsePathIDsMap: o.resourcePathIDsMap, } } @@ -60,11 +60,11 @@ func (s *authorizeNSEServer) Register(ctx context.Context, nse *registry.Network spiffeID := getSpiffeIDFromPath(ctx, path) leftSide := getLeftSideOfPath(path) - rawMap := getRawMap(s.nsePathIdsMap) + rawMap := getRawMap(s.nsePathIDsMap) input := RegistryOpaInput{ ResourceID: spiffeID.String(), ResourceName: nse.Name, - ResourcePathIdsMap: rawMap, + ResourcePathIDsMap: rawMap, PathSegments: leftSide.PathSegments, Index: leftSide.Index, } @@ -77,7 +77,7 @@ func (s *authorizeNSEServer) Register(ctx context.Context, nse *registry.Network if err != nil { return nil, err } - s.nsePathIdsMap.Store(nse.Name, nse.PathIds) + s.nsePathIDsMap.Store(nse.Name, nse.PathIds) return nse, nil } @@ -94,11 +94,11 @@ func (s *authorizeNSEServer) Unregister(ctx context.Context, nse *registry.Netwo spiffeID := getSpiffeIDFromPath(ctx, path) leftSide := getLeftSideOfPath(path) - rawMap := getRawMap(s.nsePathIdsMap) + rawMap := getRawMap(s.nsePathIDsMap) input := RegistryOpaInput{ ResourceID: spiffeID.String(), ResourceName: nse.Name, - ResourcePathIdsMap: rawMap, + ResourcePathIDsMap: rawMap, PathSegments: leftSide.PathSegments, Index: leftSide.Index, } @@ -107,6 +107,6 @@ func (s *authorizeNSEServer) Unregister(ctx context.Context, nse *registry.Netwo return nil, err } - s.nsePathIdsMap.Delete(nse.Name) + s.nsePathIDsMap.Delete(nse.Name) return next.NetworkServiceEndpointRegistryServer(ctx).Unregister(ctx, nse) } diff --git a/pkg/registry/common/authorize/nse_server_test.go b/pkg/registry/common/authorize/nse_server_test.go index 4793418ca..deb1a4c91 100644 --- a/pkg/registry/common/authorize/nse_server_test.go +++ b/pkg/registry/common/authorize/nse_server_test.go @@ -107,7 +107,7 @@ func TestNetworkServiceEndpointRegistryAuthorize_ResourcePathIdMapHaveNoLeaks(t server := next.NewNetworkServiceEndpointRegistryServer( authorize.NewNetworkServiceEndpointRegistryServer( authorize.WithPolicies("etc/nsm/opa/registry/client_allowed.rego"), - authorize.WithResourcePathIdsMap(&authorizeMap)), + authorize.WithResourcePathIDsMap(&authorizeMap)), NewNetworkServiceEndpointRegistryServer(0.5), ) diff --git a/pkg/registry/common/authorize/options.go b/pkg/registry/common/authorize/options.go index 01fa4ded5..24c828ebe 100644 --- a/pkg/registry/common/authorize/options.go +++ b/pkg/registry/common/authorize/options.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022-2023 Cisco and/or its affiliates. +// Copyright (c) 2022-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -25,7 +25,7 @@ import ( type options struct { policies policiesList - resourcePathIdsMap *genericsync.Map[string, []string] + resourcePathIDsMap *genericsync.Map[string, []string] } // Option is authorization option for server @@ -53,9 +53,9 @@ func WithPolicies(policyPaths ...string) Option { } } -// WithResourcePathIdsMap sets map to keep resourcePathIdsMap to authorize connections with Registry Authorize Chain Element -func WithResourcePathIdsMap(m *genericsync.Map[string, []string]) Option { +// WithResourcePathIDsMap sets map to keep resourcePathIdsMap to authorize connections with Registry Authorize Chain Element +func WithResourcePathIDsMap(m *genericsync.Map[string, []string]) Option { return func(o *options) { - o.resourcePathIdsMap = m + o.resourcePathIDsMap = m } } diff --git a/pkg/registry/common/clientinfo/client_test.go b/pkg/registry/common/clientinfo/client_test.go index 4bbe34278..e5b75ca25 100644 --- a/pkg/registry/common/clientinfo/client_test.go +++ b/pkg/registry/common/clientinfo/client_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022 Cisco and/or its affiliates. +// Copyright (c) 2022-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -33,7 +33,6 @@ func TestLabelsClient(t *testing.T) { t.Cleanup(func() { goleak.VerifyNone(t) }) for _, tc := range testCases { - // nolint:scopelint t.Run(tc.name, func(t *testing.T) { testLabelsClient(t, tc.envs, tc.expected, tc.input) }) diff --git a/pkg/registry/common/clientinfo/server_test.go b/pkg/registry/common/clientinfo/server_test.go index 13b3bba75..c6e257442 100644 --- a/pkg/registry/common/clientinfo/server_test.go +++ b/pkg/registry/common/clientinfo/server_test.go @@ -1,6 +1,6 @@ // Copyright (c) 2020-2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2022 Cisco and/or its affiliates. +// Copyright (c) 2022-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -111,7 +111,6 @@ func TestLabelsServer(t *testing.T) { t.Cleanup(func() { goleak.VerifyNone(t) }) for _, tc := range testCases { - // nolint:scopelint t.Run(tc.name, func(t *testing.T) { testLabelsServer(t, tc.envs, tc.expected, tc.input) }) diff --git a/pkg/registry/common/dnsresolve/ns_server.go b/pkg/registry/common/dnsresolve/ns_server.go index fe819b8dd..45ec5e39a 100644 --- a/pkg/registry/common/dnsresolve/ns_server.go +++ b/pkg/registry/common/dnsresolve/ns_server.go @@ -1,6 +1,6 @@ // Copyright (c) 2020-2022 Doc.ai and/or its affiliates. // -// Copyright (c) 2023 Cisco Systems, Inc. +// Copyright (c) 2023-2024 Cisco Systems, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -116,13 +116,3 @@ func (d *dnsNSResolveServer) Unregister(ctx context.Context, ns *registry.Networ }() return next.NetworkServiceRegistryServer(ctx).Unregister(ctx, ns) } - -func (d *dnsNSResolveServer) setResolver(r Resolver) { - d.resolver = r -} - -func (d *dnsNSResolveServer) setRegistryService(service string) { - d.registryService = service -} - -func (d *dnsNSResolveServer) setNSMgrProxyService(_ string) {} diff --git a/pkg/registry/common/dnsresolve/nse_server.go b/pkg/registry/common/dnsresolve/nse_server.go index 70de67175..8a0069f39 100644 --- a/pkg/registry/common/dnsresolve/nse_server.go +++ b/pkg/registry/common/dnsresolve/nse_server.go @@ -1,6 +1,6 @@ // Copyright (c) 2020-2022 Doc.ai and/or its affiliates. // -// Copyright (c) 2022-2023 Cisco Systems, Inc. +// Copyright (c) 2022-2024 Cisco Systems, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -181,15 +181,3 @@ func (d *dnsNSEResolveServer) Unregister(ctx context.Context, nse *registry.Netw return next.NetworkServiceEndpointRegistryServer(ctx).Unregister(ctx, nse) } - -func (d *dnsNSEResolveServer) setResolver(r Resolver) { - d.resolver = r -} - -func (d *dnsNSEResolveServer) setNSMgrProxyService(service string) { - d.nsmgrProxyService = service -} - -func (d *dnsNSEResolveServer) setRegistryService(service string) { - d.registryService = service -} diff --git a/pkg/registry/common/recvfd/server_notlinux.go b/pkg/registry/common/recvfd/server_notlinux.go index a6495743b..06aa17517 100644 --- a/pkg/registry/common/recvfd/server_notlinux.go +++ b/pkg/registry/common/recvfd/server_notlinux.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Cisco and/or its affiliates. +// Copyright (c) 2021-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -17,6 +17,9 @@ //go:build !linux // +build !linux +// Package recvfd provides an NSE registry server chain element that: +// 1. Receives and fd over a unix file socket if the nse.URL is an inode://${dev}/${inode} url +// 2. Rewrites the nse.URL to unix:///proc/${pid}/fd/${fd} so it can be used by a normal dialer package recvfd import ( diff --git a/pkg/registry/common/updatepath/common.go b/pkg/registry/common/updatepath/common.go index b599aad59..294f31380 100644 --- a/pkg/registry/common/updatepath/common.go +++ b/pkg/registry/common/updatepath/common.go @@ -1,6 +1,6 @@ // Copyright (c) 2020-2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2022 Cisco Systems, Inc. +// Copyright (c) 2022-2024 Cisco Systems, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -108,12 +108,12 @@ func getIDFromToken(tokenString string) (spiffeid.ID, error) { return spiffeid.FromString(subString) } -func updatePathIds(pathIds []string, index int, id string) []string { - if index >= len(pathIds) { - pathIds = append(pathIds, id) +func updatePathIDs(pathIDs []string, index int, id string) []string { + if index >= len(pathIDs) { + pathIDs = append(pathIDs, id) } else { - pathIds[index] = id + pathIDs[index] = id } - return pathIds + return pathIDs } diff --git a/pkg/registry/common/updatepath/ns_server.go b/pkg/registry/common/updatepath/ns_server.go index 6ad7d2c63..af6c1ec62 100644 --- a/pkg/registry/common/updatepath/ns_server.go +++ b/pkg/registry/common/updatepath/ns_server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022-2023 Cisco and/or its affiliates. +// Copyright (c) 2022-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -68,8 +68,8 @@ func (s *updatePathNSServer) Register(ctx context.Context, ns *registry.NetworkS if idErr != nil { return nil, idErr } - ns.PathIds = updatePathIds(ns.PathIds, int(path.Index-1), peerID.String()) - ns.PathIds = updatePathIds(ns.PathIds, int(path.Index), id.String()) + ns.PathIds = updatePathIDs(ns.PathIds, int(path.Index-1), peerID.String()) + ns.PathIds = updatePathIDs(ns.PathIds, int(path.Index), id.String()) ns, err = next.NetworkServiceRegistryServer(ctx).Register(ctx, ns) if err != nil { @@ -109,8 +109,8 @@ func (s *updatePathNSServer) Unregister(ctx context.Context, ns *registry.Networ if idErr != nil { return nil, idErr } - ns.PathIds = updatePathIds(ns.PathIds, int(path.Index-1), peerID.String()) - ns.PathIds = updatePathIds(ns.PathIds, int(path.Index), id.String()) + ns.PathIds = updatePathIDs(ns.PathIds, int(path.Index-1), peerID.String()) + ns.PathIds = updatePathIDs(ns.PathIds, int(path.Index), id.String()) resp, err := next.NetworkServiceRegistryServer(ctx).Unregister(ctx, ns) path.Index = index diff --git a/pkg/registry/common/updatepath/nse_server.go b/pkg/registry/common/updatepath/nse_server.go index 86e182f55..c1ca7612b 100644 --- a/pkg/registry/common/updatepath/nse_server.go +++ b/pkg/registry/common/updatepath/nse_server.go @@ -67,8 +67,8 @@ func (s *updatePathNSEServer) Register(ctx context.Context, nse *registry.Networ if idErr != nil { return nil, idErr } - nse.PathIds = updatePathIds(nse.PathIds, int(path.Index-1), peerID.String()) - nse.PathIds = updatePathIds(nse.PathIds, int(path.Index), id.String()) + nse.PathIds = updatePathIDs(nse.PathIds, int(path.Index-1), peerID.String()) + nse.PathIds = updatePathIDs(nse.PathIds, int(path.Index), id.String()) ctx = withExpirationTime(ctx, &expirationTime) @@ -110,8 +110,8 @@ func (s *updatePathNSEServer) Unregister(ctx context.Context, nse *registry.Netw if idErr != nil { return nil, idErr } - nse.PathIds = updatePathIds(nse.PathIds, int(path.Index-1), peerID.String()) - nse.PathIds = updatePathIds(nse.PathIds, int(path.Index), id.String()) + nse.PathIds = updatePathIDs(nse.PathIds, int(path.Index-1), peerID.String()) + nse.PathIds = updatePathIDs(nse.PathIds, int(path.Index), id.String()) resp, err := next.NetworkServiceEndpointRegistryServer(ctx).Unregister(ctx, nse) path.Index = index diff --git a/pkg/tools/clockmock/mock_test.go b/pkg/tools/clockmock/mock_test.go index 073943b00..f148e2659 100644 --- a/pkg/tools/clockmock/mock_test.go +++ b/pkg/tools/clockmock/mock_test.go @@ -1,5 +1,7 @@ // Copyright (c) 2021 Doc.ai and/or its affiliates. // +// Copyright (c) 2024 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -95,10 +97,8 @@ func TestMock_SetSpeed(t *testing.T) { } for _, sample := range samples { - // nolint:scopelint t.Run(sample.name, func(t *testing.T) { for _, speed := range speeds { - // nolint:scopelint t.Run(speed.name, func(t *testing.T) { testMockSetSpeed(t, sample.firstSpeed*speed.multiplier, sample.secondSpeed*speed.multiplier) }) diff --git a/pkg/tools/debug/self.go b/pkg/tools/debug/self.go index 0d5515501..70001fd66 100644 --- a/pkg/tools/debug/self.go +++ b/pkg/tools/debug/self.go @@ -1,6 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. -// -// Copyright (c) 2022-2023 Cisco and/or its affiliates. +// Copyright (c) 2020-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -69,7 +67,7 @@ func Self(envVariableParts ...string) error { // Do we have that env variable? listen, exists := os.LookupEnv(dlvPortEnvVariable) if !exists { - return errors.Errorf("Setting env variable %s to a valid dlv '--listen' value will cause the dlv debugger to execute this binary and listen as directed.", dlvPortEnvVariable) + return errors.Errorf("Setting env variable %s to a valid dlv '--listen' value will cause the dlv debugger to execute this binary and listen as directed", dlvPortEnvVariable) } // Is it a valid listen? diff --git a/pkg/tools/log/logruslogger/logruslogger.go b/pkg/tools/log/logruslogger/logruslogger.go index d7f1c5b88..41d9b3bc2 100644 --- a/pkg/tools/log/logruslogger/logruslogger.go +++ b/pkg/tools/log/logruslogger/logruslogger.go @@ -1,6 +1,6 @@ // Copyright (c) 2021-2022 Doc.ai and/or its affiliates. // -// Copyright (c) 2023 Cisco and/or its affiliates. +// Copyright (c) 2023-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -257,7 +257,7 @@ func fromContext(ctx context.Context) *traceCtxInfo { func (s *traceLogger) getSpan() string { if s.span != nil { spanStr := s.span.ToString() - if len(spanStr) > 0 && spanStr != "{}" { + if spanStr != "" && spanStr != "{}" { return fmt.Sprintf(" span=%v", spanStr) } } diff --git a/pkg/tools/matchutils/utils_test.go b/pkg/tools/matchutils/utils_test.go index c05e1154e..77e6121b5 100644 --- a/pkg/tools/matchutils/utils_test.go +++ b/pkg/tools/matchutils/utils_test.go @@ -1,6 +1,6 @@ // Copyright (c) 2020-2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2023 Cisco Systems, Inc. +// Copyright (c) 2023-2024 Cisco Systems, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -124,7 +124,6 @@ func TestNSMatch(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { got := matchutils.MatchNetworkServices(tc.svc, referenceService) if tc.want != got { @@ -276,7 +275,6 @@ func TestNSEMatch(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { got := matchutils.MatchNetworkServiceEndpoints(tc.endpoint, referenceEndpoint) if tc.want != got { @@ -389,7 +387,6 @@ func TestLabelsContains(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { left := ®istry.NetworkServiceEndpoint{ NetworkServiceLabels: tc.labels, diff --git a/pkg/tools/monitorconnection/authorize/server.go b/pkg/tools/monitorconnection/authorize/server.go index 6c053dcc5..dbf3c65f7 100644 --- a/pkg/tools/monitorconnection/authorize/server.go +++ b/pkg/tools/monitorconnection/authorize/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022-2023 Cisco and/or its affiliates. +// Copyright (c) 2022-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -50,7 +50,7 @@ func NewMonitorConnectionServer(opts ...Option) networkservice.MonitorConnection // MonitorOpaInput - used to pass complex structure to monitor policies type MonitorOpaInput struct { SpiffeIDConnectionMap map[string][]string `json:"spiffe_id_connection_map"` - SelectorConnectionIds []string `json:"selector_connection_ids"` + SelectorConnectionIDs []string `json:"selector_connection_ids"` ServiceSpiffeID string `json:"service_spiffe_id"` } @@ -80,7 +80,7 @@ func (a *authorizeMonitorConnectionsServer) MonitorConnections(in *networkservic err := a.policies.check(ctx, MonitorOpaInput{ ServiceSpiffeID: spiffeID.String(), SpiffeIDConnectionMap: simpleMap, - SelectorConnectionIds: connIDs, + SelectorConnectionIDs: connIDs, }) if err != nil { return err diff --git a/pkg/tools/monitorconnection/authorize/server_test.go b/pkg/tools/monitorconnection/authorize/server_test.go index 329e627f2..5bdf9623e 100644 --- a/pkg/tools/monitorconnection/authorize/server_test.go +++ b/pkg/tools/monitorconnection/authorize/server_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022-2023 Cisco and/or its affiliates. +// Copyright (c) 2022-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -188,9 +188,9 @@ func TestAuthzEndpoint(t *testing.T) { require.NoError(t, err) } var spiffeIDConnectionMap genericsync.Map[spiffeid.ID, *genericsync.Map[string, struct{}]] - for spiffeIDstr, connIds := range s.spiffeIDConnMap { + for spiffeIDstr, connIDs := range s.spiffeIDConnMap { connIDMap := genericsync.Map[string, struct{}]{} - for _, connID := range connIds { + for _, connID := range connIDs { connIDMap.Store(connID, struct{}{}) } var spiffeID spiffeid.ID diff --git a/pkg/tools/nanoid/generator_test.go b/pkg/tools/nanoid/generator_test.go index bc7d70dea..1ee08a5b3 100644 --- a/pkg/tools/nanoid/generator_test.go +++ b/pkg/tools/nanoid/generator_test.go @@ -54,19 +54,19 @@ func TestFlatDistribution(t *testing.T) { require.Equal(t, len(chars), len(nanoid.DefaultAlphabet), "Unexpected number of unique characters") - max := 0.0 - min := math.MaxFloat64 + maxValue := 0.0 + minValue := math.MaxFloat64 for _, count := range chars { distribution := float64(count*len(nanoid.DefaultAlphabet)) / float64(count*idLen) - if distribution > max { - max = distribution + if distribution > maxValue { + maxValue = distribution } - if distribution < min { - min = distribution + if distribution < minValue { + minValue = distribution } } - require.True(t, max-min <= 0.05, "Distribution is not flat") + require.True(t, maxValue-minValue <= 0.05, "Distribution is not flat") } func TestCustomAlphabet(t *testing.T) { diff --git a/pkg/tools/opa/registry_client_allowed_test.go b/pkg/tools/opa/registry_client_allowed_test.go index 9a6df887a..a9b0b5b0e 100644 --- a/pkg/tools/opa/registry_client_allowed_test.go +++ b/pkg/tools/opa/registry_client_allowed_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022 Cisco and/or its affiliates. +// Copyright (c) 2022-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -29,7 +29,7 @@ import ( type testInput struct { ResourceID string `json:"resource_id"` ResourceName string `json:"resource_name"` - ResourcePathIdsMap map[string][]string `json:"resource_path_ids_map"` + ResourcePathIDsMap map[string][]string `json:"resource_path_ids_map"` PathSegments []*grpcmetadata.PathSegment `json:"path_segments"` Index uint32 `json:"index"` } @@ -38,7 +38,7 @@ func TestRegistryClientAllowedPolicy(t *testing.T) { p, err := opa.PolicyFromFile("etc/nsm/opa/registry/client_allowed.rego") require.NoError(t, err) - resourcePathIdsMap := map[string][]string{ + resourcePathIDsMap := map[string][]string{ "nse1": {"id1", "id2"}, } @@ -56,7 +56,7 @@ func TestRegistryClientAllowedPolicy(t *testing.T) { for _, sample := range samples { var input = testInput{ - ResourcePathIdsMap: resourcePathIdsMap, + ResourcePathIDsMap: resourcePathIDsMap, ResourceName: sample.name, ResourceID: sample.id, } diff --git a/pkg/tools/opa/service_connection_policy_test.go b/pkg/tools/opa/service_connection_policy_test.go index bc4e2c084..a308f4d8d 100644 --- a/pkg/tools/opa/service_connection_policy_test.go +++ b/pkg/tools/opa/service_connection_policy_test.go @@ -1,5 +1,7 @@ // Copyright (c) 2022 Doc.ai and/or its affiliates. // +// Copyright (c) 2024 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,14 +33,14 @@ func TestWithServiceConnectionPolicy(t *testing.T) { require.NoError(t, err) var input = authorize.MonitorOpaInput{ - SelectorConnectionIds: []string{"conn1"}, + SelectorConnectionIDs: []string{"conn1"}, SpiffeIDConnectionMap: map[string][]string{ spiffeID: {"conn1"}, }, ServiceSpiffeID: spiffeID, } var invalidInput = authorize.MonitorOpaInput{ - SelectorConnectionIds: []string{"conn1"}, + SelectorConnectionIDs: []string{"conn1"}, SpiffeIDConnectionMap: map[string][]string{ spiffeID: {"conn2"}, },