You've already forked tarr
							
							Compare commits
	
		
			30 Commits
		
	
	
		
			v0.2.0
			...
			06b0cf748d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 06b0cf748d | |||
| 83c9a3cee0 | |||
| a73c87d837 | |||
| 3aa9f9f184 | |||
| 676422257a | |||
| 591ccb6672 | |||
| cc74ef037a | |||
| a836628dbc | |||
| 865f2f1192 | |||
| df40258f2d | |||
| 253f53198e | |||
| 1a44e48367 | |||
| 1cdc101cec | |||
| 681e6726b1 | |||
| 72422e032d | |||
| 2f17abedb9 | |||
| d2cf678b97 | |||
| 87918c2339 | |||
| 7253c2ed5b | |||
| 8708af6a5a | |||
| b525c82ccb | |||
| d39989d224 | |||
| dfe4fd60cf | |||
| d1e111fe0d | |||
| f40cb5f965 | |||
| 02d980440f | |||
| 7baa16a257 | |||
| df3192ab75 | |||
| b316124df4 | |||
| fe9a5278f7 | 
							
								
								
									
										29
									
								
								.gitea/workflows/golang-linters.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								.gitea/workflows/golang-linters.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| name: "Lint Golang files" | ||||
|  | ||||
| on: | ||||
|   pull_request: | ||||
|     types: [ "opened", "reopened", "synchronize" ] | ||||
|   push: | ||||
|     branches: [ '**' ] | ||||
|     tags-ignore: [ '**' ] | ||||
|   workflow_dispatch: {} | ||||
|  | ||||
| permissions: | ||||
|   contents: read | ||||
|  | ||||
| jobs: | ||||
|   golangci: | ||||
|     name: "Run golang CI linter" | ||||
|     runs-on: ${{ matrix.os }} | ||||
|     strategy: | ||||
|       matrix: | ||||
|         go: [ stable ] | ||||
|         os: [ ubuntu-latest-amd64, ubuntu-latest-arm64 ] | ||||
|     steps: | ||||
|     - uses: actions/checkout@v4.3.0 | ||||
|     - uses: actions/setup-go@v5.5.0 | ||||
|       with: | ||||
|         go-version: ${{ matrix.go }} | ||||
|     - uses: golangci/golangci-lint-action@v8.0.0 | ||||
|       with: | ||||
|         version: v2.4.0 # renovate: datasource=github-releases depName=golangci/golangci-lint | ||||
| @@ -1,4 +1,4 @@ | ||||
| # name: Golang Tests | ||||
| # name: "Run Golang tests" | ||||
|  | ||||
| # on: | ||||
| #   pull_request: | ||||
| @@ -6,16 +6,37 @@ | ||||
| #   push: | ||||
| #     branches: [ '**' ] | ||||
| #     tags-ignore: [ '**' ] | ||||
| #   workflow_dispatch: {} | ||||
|  | ||||
| # jobs: | ||||
| #   unittest: | ||||
| #     runs-on: | ||||
| #     - ubuntu-latest | ||||
| #   integration-test: | ||||
| #     name: "Run integration tests" | ||||
| #     runs-on: ${{ matrix.os }} | ||||
| #     strategy: | ||||
| #       matrix: | ||||
| #         go: [ stable ] | ||||
| #         os: [ ubuntu-latest-amd64, ubuntu-latest-arm64 ] | ||||
| #     steps: | ||||
| #     - uses: actions/checkout@v4.2.2 | ||||
| #     - uses: actions/checkout@v4.3.0 | ||||
| #     - uses: actions/setup-go@v5.5.0 | ||||
| #       with: | ||||
| #         go-version: stable | ||||
| #         go-version: ${{ matrix.go }} | ||||
| #     - env: | ||||
| #         GOPROXY: ${{ vars.GOPROXY }} | ||||
| #       run: make test/integration | ||||
|  | ||||
| #   unit-test: | ||||
| #     name: "Run unit tests" | ||||
| #     runs-on: ${{ matrix.os }} | ||||
| #     strategy: | ||||
| #       matrix: | ||||
| #         go: [ stable ] | ||||
| #         os: [ ubuntu-latest-amd64, ubuntu-latest-arm64 ] | ||||
| #     steps: | ||||
| #     - uses: actions/checkout@v4.3.0 | ||||
| #     - uses: actions/setup-go@v5.5.0 | ||||
| #       with: | ||||
| #         go-version: ${{ matrix.go }} | ||||
| #     - env: | ||||
| #         GOPROXY: ${{ vars.GOPROXY }} | ||||
| #       run: make test/unit | ||||
|   | ||||
| @@ -1,20 +1,19 @@ | ||||
| name: Markdown linter | ||||
| name: "Lint Markdown files" | ||||
|  | ||||
| on: | ||||
|   pull_request: | ||||
|     types: [ "opened", "reopened", "synchronize" ] | ||||
|   push: | ||||
|     branches: [ '**' ] | ||||
|     tags-ignore: [ '**' ] | ||||
|     branches: [ '*' ] | ||||
|     tags-ignore: [ '*' ] | ||||
|   workflow_dispatch: {} | ||||
|  | ||||
| jobs: | ||||
|   markdown-lint: | ||||
|     container: | ||||
|       image: git.cryptic.systems/volker.raschek/markdownlint:0.44.0 | ||||
|     runs-on: | ||||
|     - ubuntu-latest | ||||
|     name: "Run markdown linter" | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|     - uses: actions/checkout@v4.2.2 | ||||
|     - name: Lint Markdown files | ||||
|       run: markdownlint --config .markdownlint.yaml . | ||||
|     - uses: actions/checkout@v4.3.0 | ||||
|     - uses: DavidAnson/markdownlint-cli2-action@v20.0.0 | ||||
|       with: | ||||
|         globs: '**/*.md' | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| name: Release | ||||
| name: "Release" | ||||
|  | ||||
| on: | ||||
|   push: | ||||
| @@ -9,15 +9,15 @@ permissions: | ||||
|  | ||||
| jobs: | ||||
|   release: | ||||
|     runs-on: | ||||
|     - ubuntu-latest | ||||
|     name: "Release application" | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|     - uses: actions/checkout@v4.2.2 | ||||
|     - uses: actions/checkout@v4.3.0 | ||||
|     - uses: docker/setup-qemu-action@v3.6.0 | ||||
|     - uses: actions/setup-go@v5.5.0 | ||||
|       with: | ||||
|         go-version: stable | ||||
|     - uses: docker/login-action@v3.4.0 | ||||
|     - uses: docker/login-action@v3.5.0 | ||||
|       with: | ||||
|         registry: git.cryptic.systems | ||||
|         username: ${{ github.repository_owner }} | ||||
| @@ -26,12 +26,13 @@ jobs: | ||||
|         GITEA_TOKEN: ${{ secrets.GIT_CRYPTIC_SYSTEMS_PACKAGE_REGISTRY_TOKEN }} | ||||
|         GONOSUMDB: ${{ vars.GONOSUMDB }} | ||||
|         GOPROXY: ${{ vars.GOPROXY }} | ||||
|       uses: goreleaser/goreleaser-action@v6.3.0 | ||||
|       uses: goreleaser/goreleaser-action@v6.4.0 | ||||
|       with: | ||||
|         version: "~> v2" | ||||
|         version: v2.12.2 # renovate: datasource=github-releases depName=goreleaser/goreleaser | ||||
|         args: release --clean | ||||
|  | ||||
|   sync-to-hub-docker-io: | ||||
|     name: "Upload Images to docker.io" | ||||
|     needs: | ||||
|     - release | ||||
|     runs-on: ubuntu-latest | ||||
|   | ||||
| @@ -4,16 +4,17 @@ on: | ||||
|   push: | ||||
|     branches: [ 'master' ] | ||||
|     paths: [ 'README.md' ] | ||||
|   workflow_dispatch: {} | ||||
|  | ||||
| jobs: | ||||
|   update-description-on-hub-docker-io: | ||||
|     runs-on: | ||||
|     - ubuntu-latest | ||||
|     steps: | ||||
|     - uses: actions/checkout@v4.2.2 | ||||
|     - uses: actions/checkout@v4.3.0 | ||||
|     - uses: peter-evans/dockerhub-description@v4.0.2 | ||||
|       with: | ||||
|         username: ${{ secrets.DOCKER_IO_USERNAME }} | ||||
|         password: ${{ secrets.DOCKER_IO_PASSWORD }} | ||||
|         repository: volkerraschek/tarr | ||||
|         readme-filepath: README.md | ||||
|         readme-filepath: README.md | ||||
|   | ||||
							
								
								
									
										13
									
								
								.golangci.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								.golangci.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| version: "2" | ||||
| linters: | ||||
|   default: standard | ||||
|   enable: | ||||
|   - errname | ||||
|   - gosec | ||||
|  | ||||
|   exclusions: | ||||
|     rules: [] | ||||
|     warn-unused: true | ||||
|  | ||||
| run: | ||||
|   tests: true | ||||
| @@ -34,6 +34,7 @@ builds: | ||||
|   - amd64 | ||||
|   - arm | ||||
|   - arm64 | ||||
|   - riscv64 | ||||
|   goarm: | ||||
|   - "6" | ||||
|   - "7" | ||||
| @@ -171,6 +172,25 @@ dockers: | ||||
|   skip_push: false | ||||
|   use: buildx | ||||
|  | ||||
| - build_flag_templates: | ||||
|   - --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} | ||||
|   - --label=org.opencontainers.image.description={{ .ProjectName }} | ||||
|   - --label=org.opencontainers.image.documentation={{ .ProjectName }} | ||||
|   - --label=org.opencontainers.image.revision={{ .FullCommit }} | ||||
|   - --label=org.opencontainers.image.source={{ .GitURL }} | ||||
|   - --label=org.opencontainers.image.title={{ .ProjectName }} | ||||
|   - --label=org.opencontainers.image.url=https://git.cryptic.systems/volker.raschek/{{ .ProjectName }} | ||||
|   - --label=org.opencontainers.image.version={{ trimprefix .Tag "v" }} | ||||
|   - --platform=linux/riscv64 | ||||
|   - --pull | ||||
|   dockerfile: Dockerfile | ||||
|   goarch: riscv64 | ||||
|   goos: linux | ||||
|   image_templates: | ||||
|   - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-riscv64' | ||||
|   skip_push: false | ||||
|   use: buildx | ||||
|  | ||||
| docker_manifests: | ||||
| - name_template: 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}' | ||||
|   image_templates: | ||||
| @@ -178,6 +198,7 @@ docker_manifests: | ||||
|   - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-arm-v6' | ||||
|   - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-arm-v7' | ||||
|   - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-arm64' | ||||
|   - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-riscv64' | ||||
|  | ||||
| gitea_urls: | ||||
|   api: https://git.cryptic.systems/api/v1 | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package main | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"time" | ||||
| @@ -26,7 +27,9 @@ autharr /etc/lidarr/config.xml`, | ||||
| 	} | ||||
| 	rootCmd.Flags().Bool("watch", false, "Listens for changes to the configuration and writes the token continuously to the output") | ||||
|  | ||||
| 	rootCmd.Execute() | ||||
| 	if err := rootCmd.Execute(); err != nil { | ||||
| 		log.Fatalln(err) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func runE(cmd *cobra.Command, args []string) error { | ||||
| @@ -84,10 +87,16 @@ func runWatch(cmd *cobra.Command, args []string) error { | ||||
| 		select { | ||||
| 		case <-cmd.Context().Done(): | ||||
| 			return nil | ||||
| 		case err := <-errorChannel: | ||||
| 			logrus.WithError(err).Errorln("Received from config watcher") | ||||
| 		case err, open := <-errorChannel: | ||||
| 			if !open { | ||||
| 				return fmt.Errorf("error channel has been closed") | ||||
| 			} | ||||
| 			logrus.WithError(err).Errorln("received from config watcher") | ||||
| 		case <-timer.C: | ||||
| 			writeConfig(cachedConfig, dest) | ||||
| 			err = writeConfig(cachedConfig, dest) | ||||
| 			if err != nil { | ||||
| 				logrus.WithError(err).Errorln("failed to write config") | ||||
| 			} | ||||
| 		case config := <-configChannel: | ||||
| 			cachedConfig = config | ||||
| 			timer.Reset(waitFor) | ||||
| @@ -105,18 +114,23 @@ func writeConfig(config *domain.Config, dest string) error { | ||||
| 	case len(dest) > 0: | ||||
| 		dirname := filepath.Dir(dest) | ||||
|  | ||||
| 		// #nosec G301 | ||||
| 		err := os.MkdirAll(dirname, 0755) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
|  | ||||
| 		// #nosec G304 | ||||
| 		f, err := os.Create(dest) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		defer func() { _ = f.Close() }() | ||||
|  | ||||
| 		f.WriteString(config.API.Token) | ||||
| 		_, err = f.WriteString(config.API.Token) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
|   | ||||
| @@ -3,6 +3,7 @@ package main | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"time" | ||||
|  | ||||
| 	"git.cryptic.systems/volker.raschek/tarr/pkg/config" | ||||
| @@ -95,7 +96,10 @@ healarr sonarr https://sonarr.example.com:8443 --api-token my-token`, | ||||
| 	rootCmd.PersistentFlags().Bool("insecure", false, "Trust insecure TLS certificates") | ||||
| 	rootCmd.PersistentFlags().Duration("timeout", time.Minute, "Timeout") | ||||
|  | ||||
| 	rootCmd.Execute() | ||||
| 	err := rootCmd.Execute() | ||||
| 	if err != nil { | ||||
| 		log.Fatalln(err) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func runBazarrE(cmd *cobra.Command, args []string) error { | ||||
| @@ -152,7 +156,7 @@ func runE(cmd *cobra.Command, args []string, queryKey string) error { | ||||
|  | ||||
| 	switch { | ||||
| 	case len(apiToken) <= 0 && len(configPath) <= 0: | ||||
| 		return fmt.Errorf("At least --api-token oder --config must be defined") | ||||
| 		return fmt.Errorf("at least --api-token oder --config must be defined") | ||||
| 	case len(apiToken) > 0 && len(configPath) <= 0: | ||||
| 		err = health.NewReadinessProbe(args[0]). | ||||
| 			QueryAdd(queryKey, apiToken). | ||||
| @@ -175,7 +179,7 @@ func runE(cmd *cobra.Command, args []string, queryKey string) error { | ||||
| 			return err | ||||
| 		} | ||||
| 	default: | ||||
| 		return fmt.Errorf("Neither --api-token nor --config can be used at the same time.") | ||||
| 		return fmt.Errorf("neither --api-token nor --config can be used at the same time") | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
|   | ||||
							
								
								
									
										8
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								go.mod
									
									
									
									
									
								
							| @@ -3,10 +3,10 @@ module git.cryptic.systems/volker.raschek/tarr | ||||
| go 1.22.6 | ||||
|  | ||||
| require ( | ||||
| 	github.com/fsnotify/fsnotify v1.8.0 | ||||
| 	github.com/fsnotify/fsnotify v1.9.0 | ||||
| 	github.com/sirupsen/logrus v1.9.3 | ||||
| 	github.com/spf13/cobra v1.9.1 | ||||
| 	github.com/stretchr/testify v1.10.0 | ||||
| 	github.com/spf13/cobra v1.10.1 | ||||
| 	github.com/stretchr/testify v1.11.1 | ||||
| 	gopkg.in/yaml.v3 v3.0.1 | ||||
| ) | ||||
|  | ||||
| @@ -14,6 +14,6 @@ require ( | ||||
| 	github.com/davecgh/go-spew v1.1.1 // indirect | ||||
| 	github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||||
| 	github.com/pmezard/go-difflib v1.0.0 // indirect | ||||
| 	github.com/spf13/pflag v1.0.6 // indirect | ||||
| 	github.com/spf13/pflag v1.0.9 // indirect | ||||
| 	golang.org/x/sys v0.13.0 // indirect | ||||
| ) | ||||
|   | ||||
							
								
								
									
										16
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								go.sum
									
									
									
									
									
								
							| @@ -2,8 +2,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6N | ||||
| 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/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= | ||||
| github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= | ||||
| github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= | ||||
| github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= | ||||
| github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= | ||||
| github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||||
| @@ -11,14 +11,14 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN | ||||
| github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||||
| github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= | ||||
| github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= | ||||
| github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= | ||||
| github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= | ||||
| github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= | ||||
| github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||||
| github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s= | ||||
| github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0= | ||||
| github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= | ||||
| github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||||
| github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||||
| github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= | ||||
| github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||||
| github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= | ||||
| github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= | ||||
| golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= | ||||
| golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
|   | ||||
| @@ -46,11 +46,12 @@ type YAMLConfig struct { | ||||
| // Read reads the config struct from a file. The decoding format will be determined by the file extension like | ||||
| // `xml` or `yaml`. | ||||
| func ReadConfig(name string) (*domain.Config, error) { | ||||
| 	// #nosec G304 | ||||
| 	f, err := os.Open(name) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	defer f.Close() | ||||
| 	defer func() { _ = f.Close() }() | ||||
|  | ||||
| 	switch { | ||||
| 	case strings.HasSuffix(name, "xml"): | ||||
| @@ -58,7 +59,7 @@ func ReadConfig(name string) (*domain.Config, error) { | ||||
| 	case strings.HasSuffix(name, "yml") || strings.HasSuffix(name, "yaml"): | ||||
| 		return readYAMLConfig(f) | ||||
| 	default: | ||||
| 		return nil, fmt.Errorf("Unsupported file extension") | ||||
| 		return nil, fmt.Errorf("unsupported file extension") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -97,8 +98,8 @@ func readYAMLConfig(r io.Reader) (*domain.Config, error) { | ||||
| } | ||||
|  | ||||
| func WatchConfig(ctx context.Context, name string) (<-chan *domain.Config, <-chan error) { | ||||
| 	configChannel := make(chan *domain.Config, 0) | ||||
| 	errorChannel := make(chan error, 0) | ||||
| 	configChannel := make(chan *domain.Config) | ||||
| 	errorChannel := make(chan error) | ||||
|  | ||||
| 	go func() { | ||||
| 		wait := time.Second * 3 | ||||
| @@ -110,14 +111,18 @@ func WatchConfig(ctx context.Context, name string) (<-chan *domain.Config, <-cha | ||||
| 			errorChannel <- err | ||||
| 			return | ||||
| 		} | ||||
| 		watcher.Add(name) | ||||
| 		err = watcher.Add(name) | ||||
| 		if err != nil { | ||||
| 			errorChannel <- err | ||||
| 			return | ||||
| 		} | ||||
|  | ||||
| 		for { | ||||
| 			select { | ||||
| 			case <-ctx.Done(): | ||||
| 				close(configChannel) | ||||
| 				close(errorChannel) | ||||
| 				break | ||||
| 				return | ||||
| 			case event, open := <-watcher.Events: | ||||
| 				if !open { | ||||
| 					errorChannel <- fmt.Errorf("FSWatcher closed channel: %w", err) | ||||
| @@ -145,11 +150,12 @@ func WatchConfig(ctx context.Context, name string) (<-chan *domain.Config, <-cha | ||||
| // WriteConfig writes the config struct into the file. The encoding format will be determined by the file extension like | ||||
| // `xml` or `yaml`. | ||||
| func WriteConfig(name string, config *domain.Config) error { | ||||
| 	// #nosec G304 | ||||
| 	f, err := os.Create(name) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	defer f.Close() | ||||
| 	defer func() { _ = f.Close() }() | ||||
|  | ||||
| 	switch { | ||||
| 	case strings.HasSuffix(name, "xml"): | ||||
| @@ -157,13 +163,13 @@ func WriteConfig(name string, config *domain.Config) error { | ||||
| 	case strings.HasSuffix(name, "yml") || strings.HasSuffix(name, "yaml"): | ||||
| 		return writeYAMLConfig(f, config) | ||||
| 	default: | ||||
| 		return fmt.Errorf("Unsupported file extension") | ||||
| 		return fmt.Errorf("unsupported file extension") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func writeXMLConfig(w io.Writer, config *domain.Config) error { | ||||
| 	xmlEncoder := xml.NewEncoder(w) | ||||
| 	defer xmlEncoder.Close() | ||||
| 	defer func() { _ = xmlEncoder.Close() }() | ||||
|  | ||||
| 	xmlConfig := &XMLConfig{ | ||||
| 		APIToken: config.API.Token, | ||||
| @@ -180,7 +186,7 @@ func writeXMLConfig(w io.Writer, config *domain.Config) error { | ||||
|  | ||||
| func writeYAMLConfig(w io.Writer, config *domain.Config) error { | ||||
| 	yamlEncoder := yaml.NewEncoder(w) | ||||
| 	defer yamlEncoder.Close() | ||||
| 	defer func() { _ = yamlEncoder.Close() }() | ||||
|  | ||||
| 	yamlConfig := &YAMLConfig{ | ||||
| 		Auth: YAMLConfigAuth{ | ||||
|   | ||||
| @@ -24,6 +24,7 @@ func TestReadWriteConfig_XML(t *testing.T) { | ||||
| 	t.Cleanup(func() { _ = os.RemoveAll(tmpDir) }) | ||||
|  | ||||
| 	expectedXMLConfigName := filepath.Join(tmpDir, "expected_config.xml") | ||||
| 	// #nosec G304 | ||||
| 	f, err := os.Create(expectedXMLConfigName) | ||||
| 	require.NoError(err) | ||||
|  | ||||
| @@ -38,6 +39,7 @@ func TestReadWriteConfig_XML(t *testing.T) { | ||||
| 	err = config.WriteConfig(actualXMLConfigName, actualConfig) | ||||
| 	require.NoError(err) | ||||
|  | ||||
| 	// #nosec G304 | ||||
| 	b, err := os.ReadFile(actualXMLConfigName) | ||||
| 	require.NoError(err) | ||||
| 	require.Equal(expectedXMLConfig, string(b)) | ||||
| @@ -51,6 +53,7 @@ func TestReadWriteConfig_YAML(t *testing.T) { | ||||
| 	t.Cleanup(func() { _ = os.RemoveAll(tmpDir) }) | ||||
|  | ||||
| 	expectedYAMLConfigName := filepath.Join(tmpDir, "expected_config.yaml") | ||||
| 	// #nosec G304 | ||||
| 	f, err := os.Create(expectedYAMLConfigName) | ||||
| 	require.NoError(err) | ||||
|  | ||||
| @@ -65,6 +68,7 @@ func TestReadWriteConfig_YAML(t *testing.T) { | ||||
| 	err = config.WriteConfig(actualYAMLConfigName, actualConfig) | ||||
| 	require.NoError(err) | ||||
|  | ||||
| 	// #nosec G304 | ||||
| 	b, err := os.ReadFile(actualYAMLConfigName) | ||||
| 	require.NoError(err) | ||||
| 	require.Equal(expectedYAMLConfig, string(b)) | ||||
|   | ||||
| @@ -9,8 +9,8 @@ import ( | ||||
| 	"net/url" | ||||
| ) | ||||
|  | ||||
| var ErrNoAPIToken error = errors.New("No API token defined") | ||||
| var ErrNoURL error = errors.New("No API token defined") | ||||
| var ErrNoAPIToken error = errors.New("no API token defined") | ||||
| var ErrNoURL error = errors.New("no API token defined") | ||||
|  | ||||
| type ReadinessProbe struct { | ||||
| 	additionalQueryValues url.Values | ||||
| @@ -40,6 +40,7 @@ func (rp *ReadinessProbe) Run(ctx context.Context) error { | ||||
| 	httpClient := &http.Client{ | ||||
| 		Transport: &http.Transport{ | ||||
| 			TLSClientConfig: &tls.Config{ | ||||
| 				// #nosec G402 | ||||
| 				InsecureSkipVerify: rp.insecure, | ||||
| 			}, | ||||
| 		}, | ||||
| @@ -64,7 +65,7 @@ func (rp *ReadinessProbe) Run(ctx context.Context) error { | ||||
| 	} | ||||
|  | ||||
| 	if resp.StatusCode != http.StatusOK { | ||||
| 		return fmt.Errorf("Received unexpected HTTP status code %v", resp.StatusCode) | ||||
| 		return fmt.Errorf("received unexpected HTTP status code %v", resp.StatusCode) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
|   | ||||
		Reference in New Issue
	
	Block a user