From 27a6bfbd803523c09c2fd0262a9890f5bbbe2935 Mon Sep 17 00:00:00 2001 From: Jake Schuurmans Date: Thu, 25 Jan 2024 13:46:34 -0500 Subject: [PATCH] FS-1101; Git hub Actions, test task, and linting applied --- .dockerignore | 5 + .github/ISSUE_TEMPLATE/default.md | 5 + .github/PULL_REQUEST_TEMPLATE.md | 2 + .github/workflows/codeql-analysis.yml | 72 +++++++ .github/workflows/push-pr-lint.yaml | 68 ++++++ .github/workflows/release.yml | 47 +++++ .golangci.yml | 116 +++++++++++ .goreleaser.yaml | 86 ++++++++ cmd/inventory.go | 32 +-- cmd/root.go | 6 +- cmd/test.go | 71 +++++++ config.yaml | 8 +- go.mod | 10 +- go.sum | 13 -- internal/app/app.go | 8 +- internal/app/config.go | 14 +- internal/client/auth.go | 287 -------------------------- internal/client/clients.go | 14 +- internal/client/errors.go | 2 +- internal/client/fleetdb.go | 46 ++--- internal/client/tasks.go | 6 +- 21 files changed, 541 insertions(+), 377 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/ISSUE_TEMPLATE/default.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/push-pr-lint.yaml create mode 100644 .github/workflows/release.yml create mode 100644 .golangci.yml create mode 100644 .goreleaser.yaml create mode 100644 cmd/test.go delete mode 100644 internal/client/auth.go diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5dc5507 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +* +.git +!**.go +!go.* +!fleet-scheduler diff --git a/.github/ISSUE_TEMPLATE/default.md b/.github/ISSUE_TEMPLATE/default.md new file mode 100644 index 0000000..286916c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/default.md @@ -0,0 +1,5 @@ +Please don't forget to include the following information in your issue: + +- What version of Fleet Scheduler exhibits this behavior (if applicable) + +- Detailed steps to verify the issue(s) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..69467dd --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,2 @@ +#### What does this PR do + diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..e3691f6 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,72 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ main ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ main ] + schedule: + - cron: '34 3 * * 0' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/push-pr-lint.yaml b/.github/workflows/push-pr-lint.yaml new file mode 100644 index 0000000..52433c0 --- /dev/null +++ b/.github/workflows/push-pr-lint.yaml @@ -0,0 +1,68 @@ +name: lint, test and build image +on: [pull_request, push] + +jobs: + lint-test: + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + - name: Checkout code + uses: actions/checkout@v4 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + args: --config .golangci.yml --timeout 2m + version: v1.52.2 + - name: Test + run: go test ./... + build: + runs-on: ubuntu-latest + needs: [lint-test] + steps: + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: Checkout code + uses: actions/checkout@v4 + + - name: build binary + run: make build-linux + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Fleet Scheduler Docker image - no push + id: dockerbuild-fleet-scheduler + uses: docker/build-push-action@v5 + with: + context: . + push: false + tags: ghcr.io/metal-toolbox/fleet-scheduler:latest + file: Dockerfile + + - name: Scan image - Fleet Scheduler + id: scan-fleet-scheduler-image + uses: anchore/scan-action@v3 + with: + image: ghcr.io/metal-toolbox/fleet-scheduler:latest + acs-report-enable: true + # TODO(joel): Fail build once we migrate off CentOS. + fail-build: false + + # TODO(joel): Uncomment once we migrate off CentOS. + # - name: upload Anchore scan SARIF report + # uses: github/codeql-action/upload-sarif@v2 + # with: + # sarif_file: ${{ steps.scan.outputs.sarif }} + # # This should run even if we fail the container scan + # if: always() + + - name: Inspect action SARIF report + run: cat ${{ steps.scan.outputs.sarif }} + # This should run even if we fail the container scan + if: always() diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3bc2850 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,47 @@ +name: release + +on: + push: + tags: + - 'v*.*.*' + +jobs: + goreleaser: + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + packages: write + steps: + - + name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.20" + - + name: install cosign + uses: sigstore/cosign-installer@main + - + uses: anchore/sbom-action/download-syft@v0.14.3 + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COSIGN_EXPERIMENTAL: 1 + GOVERSION: "1.20" diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..37e5040 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,116 @@ +# golangci.com configuration +# https://github.com/golangci/golangci/wiki/Configuration +service: + golangci-lint-version: 1.50.0 # use the fixed version to not introduce new linters unexpectedly + +linters-settings: + govet: + auto-fix: true + check-shadowing: true + settings: + printf: + funcs: + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + revive: + min-confidence: 0 + gocyclo: + min-complexity: 15 + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 2 + depguard: + list-type: blacklist + packages: + # logging is allowed only by logutils.Log, logrus + # is allowed to use only in logutils package + - github.com/sirupsen/logrus + misspell: + locale: US + auto-fix: true + lll: + line-length: 140 + goimports: + local-prefixes: github.com/golangci/golangci-lint + gocritic: + enabled-tags: + - performance + - style + - experimental + disabled-checks: + - wrapperFunc + gofumpt: + extra-rules: true + wsl: + auto-fix: true + +linters: + enable: + - errcheck + - gosimple + - govet + - gofmt + - gocyclo + - ineffassign + - stylecheck + - misspell + - staticcheck + - unused + - prealloc + - typecheck + # additional linters + - bodyclose + - gocritic + - goerr113 + - goimports + - revive + - misspell + - noctx + - stylecheck + - gosec + enable-all: false + disable-all: true + +run: + # build-tags: + skip-dirs: + - internal/fixtures + skip-files: + - "(.*/)*.*_test.go" + +issues: + exclude-rules: + - linters: + - gosec + text: "weak cryptographic primitive" + + - linters: + - stylecheck + text: "ST1016" + exclude: + # Default excludes from `golangci-lint run --help` with EXC0002 removed + # EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok + - Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked + # EXC0002 golint: Annoying issue about not having a comment. The rare codebase has such comments + # - (comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form) + # EXC0003 golint: False positive when tests are defined in package 'test' + - func name will be used as test\.Test.* by other packages, and that stutters; consider calling this + # EXC0004 govet: Common false positives + - (possible misuse of unsafe.Pointer|should have signature) + # EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore + - ineffective break statement. Did you mean to break out of the outer loop + # EXC0006 gosec: Too many false-positives on 'unsafe' usage + - Use of unsafe calls should be audited + # EXC0007 gosec: Too many false-positives for parametrized shell calls + - Subprocess launch(ed with variable|ing should be audited) + # EXC0008 gosec: Duplicated errcheck checks + - (G104|G307) + # EXC0009 gosec: Too many issues in popular repos + - (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less) + # EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)' + - Potential file inclusion via variable +exclude-use-default: false diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..d53ee36 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,86 @@ +project_name: fleet-scheduler +before: + hooks: + - go mod tidy + +builds: + - id: go + env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + ldflags: + - -X "github.com/metal-toolbox/fleet-scheduler/internal/version.AppVersion={{ .Version }}" + -X "github.com/metal-toolbox/fleet-scheduler/internal/version.GoVersion={{ .Env.GOVERSION }}" + -X "github.com/metal-toolbox/fleet-scheduler/internal/version.GitCommit={{ .Commit }}" + -X "github.com/metal-toolbox/fleet-scheduler/internal/version.GitBranch={{ .Branch }}" + -X "github.com/metal-toolbox/fleet-scheduler/internal/version.BuildDate={{ .Date }}" + +archives: + - id: go + format: tar.gz + name_template: >- + {{ .ProjectName }}_ + {{ .Version }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}64bit + {{- else if eq .Arch "386" }}32bit + {{- else if eq .Arch "arm" }}ARM + {{- else if eq .Arch "arm64" }}ARM64 + {{- else }}{{ .Arch }}{{ end }} + files: + - README.md + +checksum: + name_template: "checksums.txt" + +snapshot: + name_template: "{{ .Tag }}-next" + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +dockers: + - image_templates: + - "ghcr.io/metal-toolbox/{{.ProjectName}}:{{ .Tag }}" + - "ghcr.io/metal-toolbox/{{.ProjectName}}:latest" + dockerfile: Dockerfile + build_flag_templates: + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + +sboms: + - artifacts: archive + - id: source + artifacts: source + +signs: + - cmd: cosign + signature: "${artifact}.sig" + certificate: "${artifact}.pem" + args: + - "sign-blob" + - "--oidc-issuer=https://token.actions.githubusercontent.com" + - "--output-certificate=${certificate}" + - "--output-signature=${signature}" + - "${artifact}" + - "--yes" # required on cosign 2.0.0+ + artifacts: all + output: true + +docker_signs: + - cmd: cosign + args: + - "sign" + - "--oidc-issuer=https://token.actions.githubusercontent.com" + - "${artifact}" + - "--yes" # required on cosign 2.0.0+ + artifacts: all + output: true diff --git a/cmd/inventory.go b/cmd/inventory.go index 91c3b4a..7dd727c 100644 --- a/cmd/inventory.go +++ b/cmd/inventory.go @@ -15,7 +15,10 @@ var cmdInventory = &cobra.Command{ Use: "inventory", Short: "gather all servers and create invetory for them", Run: func(cmd *cobra.Command, args []string) { - inventory(cmd.Context()) + err := inventory(cmd.Context()) + if err != nil { + log.Fatal(err) + } }, } @@ -23,33 +26,32 @@ func init() { rootCmd.AddCommand(cmdInventory) } -func inventory(ctx context.Context) { +func inventory(ctx context.Context) error { otelCtx, otelShutdown := otelinit.InitOpenTelemetry(ctx, "fleet-scheduler") defer otelShutdown(ctx) otelCtxWithCancel, cancelFunc := context.WithCancel(otelCtx) defer cancelFunc() - app, err := app.New(otelCtxWithCancel, cfgFile) + newApp, err := app.New(otelCtxWithCancel, cfgFile) if err != nil { - log.Fatal(err) - return + return err } - loggerEntry := app.Logger.WithFields(logrus.Fields{"component": "store.serverservice"}) - loggerEntry.Level = app.Logger.Level + loggerEntry := newApp.Logger.WithFields(logrus.Fields{"component": "store.serverservice"}) + loggerEntry.Level = newApp.Logger.Level - client, err := client.New(app.Ctx, app.Cfg, loggerEntry) + newClient, err := client.New(newApp.Ctx, newApp.Cfg, loggerEntry) if err != nil { - log.Fatal(err) - return + return err } - err = client.CreateConditionInventoryForAllServers() + err = newClient.CreateConditionInventoryForAllServers() if err != nil { - log.Fatal(err) - return + return err } - app.Logger.Info("Task: 'CreateConditionInventoryForAllServers' complete") -} \ No newline at end of file + newApp.Logger.Info("Task: 'CreateConditionInventoryForAllServers' complete") + + return nil +} diff --git a/cmd/root.go b/cmd/root.go index 4f34736..908eb33 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,10 +7,7 @@ import ( "github.com/spf13/cobra" ) -var ( - cfgFile string - reAuth bool -) +var cfgFile string var rootCmd = &cobra.Command{ Use: "fleet-scheduler", @@ -29,5 +26,4 @@ func Execute() { func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "set config file path. Default location is in the env variable FLEET_SCHEDULER_CONFIG") - rootCmd.PersistentFlags().BoolVar(&reAuth, "reauth", false, "re-authenticate with oauth services") } diff --git a/cmd/test.go b/cmd/test.go new file mode 100644 index 0000000..918d668 --- /dev/null +++ b/cmd/test.go @@ -0,0 +1,71 @@ +package cmd + +import ( + "bytes" + "encoding/json" + "log" + + "github.com/equinix-labs/otel-init-go/otelinit" + "github.com/metal-toolbox/fleet-scheduler/internal/app" + "github.com/metal-toolbox/fleet-scheduler/internal/client" + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "golang.org/x/net/context" +) + +var cmdTest = &cobra.Command{ + Use: "test", + Short: "test", + Run: func(cmd *cobra.Command, args []string) { + err := test(cmd.Context()) + if err != nil { + log.Fatal(err) + } + }, +} + +func init() { + rootCmd.AddCommand(cmdTest) +} + +// This test command will be purged once I verify everything is functional +func test(ctx context.Context) error { + otelCtx, otelShutdown := otelinit.InitOpenTelemetry(ctx, "fleet-scheduler") + defer otelShutdown(ctx) + + otelCtxWithCancel, cancelFunc := context.WithCancel(otelCtx) + defer cancelFunc() + + newApp, err := app.New(otelCtxWithCancel, cfgFile) + if err != nil { + return err + } + + loggerEntry := newApp.Logger.WithFields(logrus.Fields{"component": "store.serverservice"}) + loggerEntry.Level = newApp.Logger.Level + + // Just used to verify fleet-scheduler can authenticate + _, err = client.New(newApp.Ctx, newApp.Cfg, loggerEntry) + if err != nil { + return err + } + + // purge secrets from config before printing the config (for debug purposes) + newApp.Cfg.FdbCfg.ClientSecret = "" + newApp.Cfg.CoCfg.ClientSecret = "" + + var prettyJSON bytes.Buffer + myJSON, err := json.Marshal(newApp.Cfg) + if err != nil { + return err + } + + err = json.Indent(&prettyJSON, myJSON, "", "\t") + if err != nil { + return err + } + + newApp.Logger.Info("Config: ", prettyJSON.String()) + + return nil +} diff --git a/config.yaml b/config.yaml index 7213a52..f4bd5a5 100644 --- a/config.yaml +++ b/config.yaml @@ -2,8 +2,8 @@ log_level: debug store_kind: fleetscheduler facility_code: sandbox fleetdb_api: - endpoint: http://192.168.1.191:8000 - disable_oauth: true + endpoint: http://localhost:8000 + disable_oauth: false conditionorc_api: - endpoint: http://192.168.1.191:9001 - disable_oauth: true \ No newline at end of file + endpoint: http://localhost:9001 + disable_oauth: false \ No newline at end of file diff --git a/go.mod b/go.mod index df3cafb..f5a7e69 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/metal-toolbox/fleet-scheduler -go 1.21.1 +go 1.21 require ( github.com/adrg/xdg v0.4.0 @@ -10,24 +10,19 @@ require ( github.com/hashicorp/go-retryablehttp v0.7.5 github.com/metal-toolbox/conditionorc v1.0.3 github.com/metal-toolbox/rivets v0.2.2 - github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.18.0 github.com/sirupsen/logrus v1.9.3 - github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.18.2 - github.com/zalando/go-keyring v0.2.3 go.hollow.sh/serverservice v0.16.2 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 golang.org/x/net v0.20.0 golang.org/x/oauth2 v0.16.0 golang.org/x/sync v0.6.0 - gopkg.in/square/go-jose.v2 v2.6.0 ) require ( - github.com/alessio/shellescape v1.4.1 // indirect github.com/banzaicloud/logrus-runtime-formatter v0.0.0-20190729070250-5ae5475bae5e // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bmc-toolbox/common v0.0.0-20230717121556-5eb9915a8a5a // indirect @@ -37,7 +32,6 @@ require ( github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect github.com/chenzhuoyu/iasm v0.9.1 // indirect github.com/cockroachdb/cockroach-go/v2 v2.3.5 // indirect - github.com/danieljoos/wincred v1.2.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect @@ -52,7 +46,6 @@ require ( github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.16.0 // indirect github.com/goccy/go-json v0.10.2 // indirect - github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gofrs/uuid v4.4.0+incompatible // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/mock v1.6.0 // indirect @@ -139,5 +132,6 @@ require ( google.golang.org/grpc v1.59.0 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/square/go-jose.v2 v2.6.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 8206878..e7488ee 100644 --- a/go.sum +++ b/go.sum @@ -85,8 +85,6 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= -github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apmckinlay/gsuneido v0.0.0-20190404155041-0b6cd442a18f/go.mod h1:JU2DOj5Fc6rol0yaT79Csr47QR0vONGwJtBNGRD7jmc= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= @@ -150,8 +148,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE= -github.com/danieljoos/wincred v1.2.0/go.mod h1:FzQLLMKBFdvu+osBrnFODiv32YGwCfx0SkRa/eYHgec= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= @@ -239,8 +235,6 @@ github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3a github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= -github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= @@ -583,8 +577,6 @@ github.com/nats-io/nkeys v0.4.6 h1:IzVe95ru2CT6ta874rt9saQRkWfe2nFj1NtvYSLqMzY= github.com/nats-io/nkeys v0.4.6/go.mod h1:4DxZNzenSVd1cYQoAa8948QY3QDjrHfcfVADymtkpts= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c h1:4RYnE0ISVwRxm9Dfo7utw1dh0kdRDEmVYq2MFVLy5zI= -github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c/go.mod h1:DvuJJ/w1Y59rG8UTDxsMk5U+UJXJwuvUgbiJSm9yhX8= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= @@ -660,8 +652,6 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA= -github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/slack-go/slack v0.12.3 h1:92/dfFU8Q5XP6Wp5rr5/T5JHLM5c5Smtn53fhToAP88= github.com/slack-go/slack v0.12.3/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw= github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= @@ -688,7 +678,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -739,8 +728,6 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/zalando/go-keyring v0.2.3 h1:v9CUu9phlABObO4LPWycf+zwMG7nlbb3t/B5wa97yms= -github.com/zalando/go-keyring v0.2.3/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= github.com/zsais/go-gin-prometheus v0.1.0 h1:bkLv1XCdzqVgQ36ScgRi09MA2UC1t3tAB6nsfErsGO4= github.com/zsais/go-gin-prometheus v0.1.0/go.mod h1:Slirjzuz8uM8Cw0jmPNqbneoqcUtY2GGjn2bEd4NRLY= diff --git a/internal/app/app.go b/internal/app/app.go index ecc8f38..bef060f 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -19,10 +19,10 @@ func New(ctx context.Context, cfgFilePath string) (*App, error) { return nil, err } - app := App { - Cfg: cfgFileBytes, + app := App{ + Cfg: cfgFileBytes, Logger: logrus.New(), - Ctx: ctx, + Ctx: ctx, } switch app.Cfg.LogLevel { @@ -35,4 +35,4 @@ func New(ctx context.Context, cfgFilePath string) (*App, error) { } return &app, nil -} \ No newline at end of file +} diff --git a/internal/app/config.go b/internal/app/config.go index dd79177..bd8bf4e 100644 --- a/internal/app/config.go +++ b/internal/app/config.go @@ -12,7 +12,7 @@ import ( ) const ( - config_env_variable_name = "FLEET_SCHEDULER_CONFIG" + configEnvVariableName = "FLEET_SCHEDULER_CONFIG" LogLevelInfo = "info" LogLevelDebug = "debug" @@ -104,12 +104,10 @@ func validateClientParams(cfg *Configuration) error { if cfg.LogLevel == "" { cfg.LogLevel = LogLevelInfo - } else { - if cfg.LogLevel != LogLevelInfo && - cfg.LogLevel != LogLevelDebug && - cfg.LogLevel != LogLevelTrace { - return errors.Wrap(errCfgInvalid, "LogLevel") - } + } else if cfg.LogLevel != LogLevelInfo && + cfg.LogLevel != LogLevelDebug && + cfg.LogLevel != LogLevelTrace { + return errors.Wrap(errCfgInvalid, "LogLevel") } // FleetDB (serverservice) Configuration @@ -168,7 +166,7 @@ func openConfig(path string) (*os.File, error) { if path != "" { return os.Open(path) } - path = viper.GetString(config_env_variable_name) + path = viper.GetString(configEnvVariableName) if path != "" { return os.Open(path) } diff --git a/internal/client/auth.go b/internal/client/auth.go deleted file mode 100644 index d6de858..0000000 --- a/internal/client/auth.go +++ /dev/null @@ -1,287 +0,0 @@ -package client - -import ( - "context" - "crypto/rand" - "encoding/base64" - "errors" - "fmt" - "log" - "net/http" - "time" - - "github.com/coreos/go-oidc" - "github.com/metal-toolbox/fleet-scheduler/internal/app" - "github.com/metal-toolbox/fleet-scheduler/internal/model" - "github.com/skratchdot/open-golang/open" - cv "github.com/nirasan/go-oauth-pkce-code-verifier" - "github.com/zalando/go-keyring" - "golang.org/x/oauth2" - "gopkg.in/square/go-jose.v2/jwt" -) - -const ( - keyringService = "TODO" -) - -var ( - callbackTimeout = time.Second * 6 - // ErrNoToken is returned when a token isn't returned from the auth flow - ErrNoToken = errors.New("failed to get a token") -) - -type authenticator struct { - disable bool - tokenNamePrefix string - pkceCallbackURL string - clientID string - audienceEndpoint string - issuerEndpoint string - scopes []string -} - -func newOIDCAuthenticator(apiKind model.APIKind, cfg *app.ConfigOIDC) *authenticator { - return &authenticator{ - disable: cfg.DisableOAuth, - tokenNamePrefix: string(apiKind), - pkceCallbackURL: cfg.PkceCallbackURL, - clientID: cfg.ClientID, - audienceEndpoint: cfg.AudienceEndpoint, - issuerEndpoint: cfg.IssuerEndpoint, - scopes: cfg.ClientScopes, - } -} - -// AccessToken looks up the keyring for the service access token, if none is found, it fetches a new one. -func accessToken(ctx context.Context, apiKind model.APIKind, cfg *app.ConfigOIDC, reauth bool) (string, error) { - authenticator := newOIDCAuthenticator(apiKind, cfg) - - var token *oauth2.Token - var err error - - if reauth { - token, err = authenticator.getOAuth2Token(ctx) - if err != nil { - return "", err - } - } else { - token, err = authenticator.refreshToken(ctx) - if err != nil { - token, err = authenticator.getOAuth2Token(ctx) - if err != nil { - return "", err - } - } - } - - return token.AccessToken, nil -} - -// GetOAuth2Token retrieves the OAuth2 token from the issuer and stores it in the local keyring with the given name. -func (a *authenticator) getOAuth2Token(ctx context.Context) (*oauth2.Token, error) { - oauthConfig, err := a.oauth2Config(ctx) - if err != nil { - return nil, err - } - - token, err := a.authCodePKCE(oauthConfig, a.audienceEndpoint) - if err != nil { - return nil, err - } - - if err := a.keyringStoreToken(token); err != nil { - return nil, err - } - - return token, nil -} - -func (a *authenticator) oauth2Config(ctx context.Context) (*oauth2.Config, error) { - // setup oidc provider - provider, err := oidc.NewProvider(ctx, a.issuerEndpoint) - if err != nil { - return nil, err - } - - // return oauth configuration - return &oauth2.Config{ - ClientID: a.clientID, - RedirectURL: a.pkceCallbackURL, - Endpoint: provider.Endpoint(), - Scopes: a.scopes, - }, nil -} - -func (a *authenticator) keyringNameRefreshToken() string { - return fmt.Sprintf("%s_%s_refresh_token", a.clientID, a.tokenNamePrefix) -} - -func (a *authenticator) keyringNameToken() string { - return fmt.Sprintf("%s_%s_token", a.clientID, a.tokenNamePrefix) -} - -func (a *authenticator) refreshToken(ctx context.Context) (*oauth2.Token, error) { - oauthConfig, err := a.oauth2Config(ctx) - if err != nil { - return nil, err - } - - authToken, err := keyring.Get(keyringService, a.keyringNameToken()) - if err != nil { - return nil, err - } - - refToken, err := keyring.Get(keyringService, a.keyringNameRefreshToken()) - if err != nil { - return nil, err - } - - token, err := a.tokenFromRaw(authToken, refToken) - if err != nil { - return nil, err - } - - ts := oauthConfig.TokenSource(ctx, token) - - newToken, err := ts.Token() - if err != nil { - return nil, err - } - - // if the token was refreshed we need to save the new token - if newToken.AccessToken != token.AccessToken { - if err := a.keyringStoreToken(newToken); err != nil { - return nil, err - } - } - - return newToken, nil -} - -// tokenFromRaw will take a access and refresh token string and convert them into a proper token -func (a *authenticator) tokenFromRaw(rawAccess, refresh string) (*oauth2.Token, error) { - tok, err := jwt.ParseSigned(rawAccess) - if err != nil { - return nil, err - } - - cl := jwt.Claims{} - - if err := tok.UnsafeClaimsWithoutVerification(&cl); err != nil { - return nil, err - } - - return &oauth2.Token{ - AccessToken: rawAccess, - RefreshToken: refresh, - Expiry: cl.Expiry.Time(), - }, nil -} - -func (a *authenticator) keyringStoreToken(token *oauth2.Token) error { - err := keyring.Set(keyringService, a.keyringNameToken(), token.AccessToken) - if err != nil { - return err - } - - return keyring.Set(keyringService, a.keyringNameRefreshToken(), token.RefreshToken) -} - -// authCodePKCE starts a server and listens for an oauth2 callback and will -// return the API token to the caller -func (a *authenticator) authCodePKCE(oauthConfig *oauth2.Config, audience string) (*oauth2.Token, error) { - tc := make(chan *oauth2.Token) - - // nolint:gomnd // state string is limited to 20 random characters - c := &authClient{ - oauthConfig: oauthConfig, - state: randStr(20), - } - - c.codeVerifier, _ = cv.CreateCodeVerifier() - - mux := http.NewServeMux() - mux.HandleFunc("/identity/callback", func(w http.ResponseWriter, r *http.Request) { - c.handlePKCECallback(w, r, tc) - }) - - // nolint:gomnd // read header timeout is set to 30s - server := &http.Server{Addr: ":18000", ReadHeaderTimeout: time.Second * 30, Handler: mux} - - go func() { - if err := server.ListenAndServe(); err != nil { - if errors.Is(err, http.ErrServerClosed) { - return - } - - log.Printf("ERROR: %s\n", err.Error()) - tc <- nil - } - }() - - // Create code_challenge with S256 method - codeChallenge := c.codeVerifier.CodeChallengeS256() - authURL := oauthConfig.AuthCodeURL(c.state, - oauth2.SetAuthURLParam("audience", audience), - oauth2.SetAuthURLParam("key", "value"), - oauth2.SetAuthURLParam("code_challenge_method", "S256"), - oauth2.SetAuthURLParam("code_challenge", codeChallenge), - ) - - if err := open.Start(authURL); err != nil { - log.Printf("Failed to open browser automatically, please visit %s to complete auth\n\n", authURL) - } - - token := <-tc - - ctx, cancel := context.WithTimeout(context.Background(), callbackTimeout) - defer cancel() - - if err := server.Shutdown(ctx); err != nil { - return nil, err - } - - if token == nil { - return nil, ErrNoToken - } - - return token, nil -} - -func randStr(length int) string { - buff := make([]byte, length) - _, _ = rand.Read(buff) - - return base64.StdEncoding.EncodeToString(buff)[:length] -} - -type authClient struct { - oauthConfig *oauth2.Config - codeVerifier *cv.CodeVerifier - state string -} - -func (c *authClient) handlePKCECallback(w http.ResponseWriter, r *http.Request, tc chan *oauth2.Token) { - state := r.URL.Query().Get("state") - if state != c.state { - log.Printf("ERROR: oauth state doesn't match") - w.WriteHeader(http.StatusBadRequest) - tc <- nil - } - - code := r.URL.Query().Get("code") - - token, err := c.oauthConfig.Exchange(context.Background(), code, - oauth2.SetAuthURLParam("code_verifier", c.codeVerifier.String()), - ) - - if err != nil { - log.Printf("ERROR in token exchange: %s\n", err.Error()) - - w.WriteHeader(http.StatusBadRequest) - tc <- nil - } - - w.Write([]byte("Success. You can now close this window.")) //nolint - tc <- token -} diff --git a/internal/client/clients.go b/internal/client/clients.go index 3aa8125..e91df19 100644 --- a/internal/client/clients.go +++ b/internal/client/clients.go @@ -66,9 +66,10 @@ func (c *Client) newFleetDBClient() error { // retryablehttp ignores 500 and all errors above 501. So we want to make sure those are logged. // https://github.com/hashicorp/go-retryablehttp/blob/4165cf8897205a879a06b20d1ed0a2a76fbb6a17/client.go#L521C80-L521C100 if r.StatusCode == http.StatusInternalServerError || r.StatusCode > http.StatusNotImplemented { - b, err := io.ReadAll(r.Body) - if err != nil { - c.logger.Warn("fleetDB (serverservice) query returned 500 error, got error reading body: ", err.Error()) + // named newErr so the linter doesnt get mad + b, newErr := io.ReadAll(r.Body) + if newErr != nil { + c.logger.Warn("fleetDB (serverservice) query returned 500 error, got error reading body: ", newErr.Error()) return } @@ -112,9 +113,10 @@ func (c *Client) newConditionOrcClient() error { // retryablehttp ignores 500 and all errors above 501. So we want to make sure those are logged. // https://github.com/hashicorp/go-retryablehttp/blob/4165cf8897205a879a06b20d1ed0a2a76fbb6a17/client.go#L521C80-L521C100 if r.StatusCode == http.StatusInternalServerError || r.StatusCode > http.StatusNotImplemented { - b, err := io.ReadAll(r.Body) - if err != nil { - c.logger.Warn("conditionOrc query returned 500 error, got error reading body: ", err.Error()) + // named newErr so the linter doesnt get mad + b, newErr := io.ReadAll(r.Body) + if newErr != nil { + c.logger.Warn("conditionOrc query returned 500 error, got error reading body: ", newErr.Error()) return } diff --git a/internal/client/errors.go b/internal/client/errors.go index b279089..935f6c6 100644 --- a/internal/client/errors.go +++ b/internal/client/errors.go @@ -8,4 +8,4 @@ var ( ErrNoTokenInRing = errors.New("secret not found in keyring") ErrAuth = errors.New("authentication error") ErrNilConfig = errors.New("configuration was nil") -) \ No newline at end of file +) diff --git a/internal/client/fleetdb.go b/internal/client/fleetdb.go index cc6ecbd..34190ad 100644 --- a/internal/client/fleetdb.go +++ b/internal/client/fleetdb.go @@ -10,44 +10,44 @@ import ( fleetDBapi "go.hollow.sh/serverservice/pkg/api/v1" ) -func (c* Client) gatherServers(page_size int, serverCh chan fleetDBapi.Server, concLimiter *semaphore.Weighted) { - // signal to reciever that we are done +func (c *Client) gatherServers(pageSize int, serverCh chan fleetDBapi.Server, concLimiter *semaphore.Weighted) { + // signal to receiver that we are done defer close(serverCh) // First page, use the response from it to figure out how many pages we have to loop through // Dont change page size - servers, response, err := c.getServerPage(page_size, 1) + servers, response, err := c.getServerPage(pageSize, 1) if err != nil { - c.logger.WithFields(logrus.Fields { - "page_size": page_size, - "page_index": 1, + c.logger.WithFields(logrus.Fields{ + "pageSize": pageSize, + "pageIndex": 1, }).Logger.Error("Failed to get list of servers") return } - total_pages := response.TotalPages + totalPages := response.TotalPages if !concLimiter.TryAcquire(int64(response.PageSize)) { c.logger.Error("Failed to acquire semaphore! Going to attempt to continue.") } // send first page of servers to the channel - for _, server := range(servers) { - serverCh <- server + for i := range servers { + serverCh <- servers[i] } c.logger.WithFields(logrus.Fields{ "index": 1, - "iterations": total_pages, - "got" : len(servers), + "iterations": totalPages, + "got": len(servers), }).Trace("Got server page") // Start the second page, and loop through rest the pages - for i := 2; i <= total_pages; i++ { - servers, response, err = c.getServerPage(page_size, i) + for i := 2; i <= totalPages; i++ { + servers, response, err = c.getServerPage(pageSize, i) if err != nil { - c.logger.WithFields(logrus.Fields { - "page_size": page_size, - "page_index": i, + c.logger.WithFields(logrus.Fields{ + "pageSize": pageSize, + "pageIndex": i, }).Logger.Error("Failed to get page of servers") continue @@ -55,8 +55,8 @@ func (c* Client) gatherServers(page_size int, serverCh chan fleetDBapi.Server, c c.logger.WithFields(logrus.Fields{ "index": i, - "iterations": total_pages, - "got" : len(servers), + "iterations": totalPages, + "got": len(servers), }).Trace("Got server page") // throttle this loop @@ -66,13 +66,13 @@ func (c* Client) gatherServers(page_size int, serverCh chan fleetDBapi.Server, c time.Sleep(time.Second) } - for _, server := range(servers) { - serverCh <- server + for i := range servers { + serverCh <- servers[i] } } } -func (c* Client) getServerPage(page_size int, page int) ([]fleetDBapi.Server, *fleetDBapi.ServerResponse, error) { +func (c *Client) getServerPage(pageSize, page int) ([]fleetDBapi.Server, *fleetDBapi.ServerResponse, error) { params := &fleetDBapi.ServerListParams{ FacilityCode: c.cfg.FacilityCode, AttributeListParams: []fleetDBapi.AttributeListParams{ @@ -81,10 +81,10 @@ func (c* Client) getServerPage(page_size int, page int) ([]fleetDBapi.Server, *f }, }, PaginationParams: &fleetDBapi.PaginationParams{ - Limit: page_size, + Limit: pageSize, Page: page, }, } return c.fdbClient.List(c.ctx, params) -} \ No newline at end of file +} diff --git a/internal/client/tasks.go b/internal/client/tasks.go index beb0311..a1fe572 100644 --- a/internal/client/tasks.go +++ b/internal/client/tasks.go @@ -33,16 +33,16 @@ func (c *Client) CreateConditionInventoryForAllServers() error { return nil } -func (c *Client) GatherServersNonBlocking(page_size int) (chan fleetDBapi.Server, *semaphore.Weighted, error) { +func (c *Client) GatherServersNonBlocking(pageSize int) (chan fleetDBapi.Server, *semaphore.Weighted, error) { if c.fdbClient == nil { return nil, nil, ErrSsClientIsNil } serverCh := make(chan fleetDBapi.Server) - concLimiter := semaphore.NewWeighted(int64(page_size * page_size)) + concLimiter := semaphore.NewWeighted(int64(pageSize * pageSize)) go func() { - c.gatherServers(page_size, serverCh, concLimiter) + c.gatherServers(pageSize, serverCh, concLimiter) }() return serverCh, concLimiter, nil