Skip to content

Commit cf7d79b

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 7e9764b + 4fddf01 commit cf7d79b

21 files changed

+576
-411
lines changed

.github/workflows/go.yaml

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
- name: Split integration tests
3535
id: test_split
36-
uses: hashicorp-forge/go-test-split-action@v1
36+
uses: hashicorp-forge/go-test-split-action@v2.0.0
3737
with:
3838
index: ${{ matrix.index }}
3939
total: ${{ matrix.parallel }}
@@ -202,7 +202,8 @@ jobs:
202202
env:
203203
GOOS: darwin
204204
GOARCH: arm64
205-
CGO_ENABLED: 0
205+
CGO_ENABLED: 0
206+
# Create azure version for linux_amd64
206207
- run: go build -ldflags="-X 'main.Version=${{ steps.determine_version.outputs.semVer }}'" -o functions/octolint_linux_amd64_azure cmd/azure/octolint.go
207208
env:
208209
GOOS: linux
@@ -213,7 +214,28 @@ jobs:
213214
- run: |
214215
zip -r octolint_linux_amd64_azure.zip . -x local.settings.json
215216
cp octolint_linux_amd64_azure.zip octolint_azure.${{ steps.determine_version.outputs.semVer }}.zip
216-
working-directory: functions
217+
working-directory: functions
218+
# Create azure version for macOS (amd64 and arm64)
219+
- run: go build -ldflags="-X 'entry.Version=${{ steps.determine_version.outputs.semVer }}'" -o functions/octolint_macos_amd64_azure cmd/azure/octolint.go
220+
env:
221+
GOOS: darwin
222+
GOARCH: amd64
223+
CGO_ENABLED: 0
224+
- run: go build -ldflags="-X 'entry.Version=${{ steps.determine_version.outputs.semVer }}'" -o functions/octolint_macos_arm64_azure cmd/azure/octolint.go
225+
env:
226+
GOOS: darwin
227+
GOARCH: arm64
228+
CGO_ENABLED: 0
229+
- run: go build -ldflags="-X 'entry.Version=${{ steps.determine_version.outputs.semVer }}'" -o functions/octolint_windows_amd64_azure.exe cmd/azure/octolint.go
230+
env:
231+
GOOS: windows
232+
GOARCH: amd64
233+
CGO_ENABLED: 0
234+
# Create macOS azure version zips
235+
- run: |
236+
zip -r octolint_macos_arm64_azure.zip . -x local.settings.json -x octolint_linux_amd64_azure -x octolint_linux_amd64_azure.zip -x octolint_windows_amd64_azure.exe -x octolint_macos_amd64_azure
237+
zip -r octolint_macos_amd64_azure.zip . -x local.settings.json -x octolint_linux_amd64_azure -x octolint_linux_amd64_azure.zip -x octolint_windows_amd64_azure.exe -x octolint_macos_arm64_azure -x octolint_macos_arm64_azure.zip
238+
working-directory: functions
217239
- id: create_release
218240
uses: "marvinpinto/action-automatic-releases@latest"
219241
with:
@@ -249,7 +271,7 @@ jobs:
249271
asset_path: octolint_macos_arm64
250272
asset_name: octolint_macos_arm64
251273
asset_content_type: application/octet-stream
252-
- name: Upload Azure Functions Release Asset
274+
- name: Upload linux amd64 Azure Functions Release Asset
253275
uses: actions/upload-release-asset@v1
254276
env:
255277
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -258,6 +280,33 @@ jobs:
258280
asset_path: functions/octolint_linux_amd64_azure.zip
259281
asset_name: octolint_linux_amd64_azure.zip
260282
asset_content_type: application/octet-stream
283+
- name: Upload macOS amd64 Azure Functions Release Asset
284+
uses: actions/upload-release-asset@v1
285+
env:
286+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
287+
with:
288+
upload_url: ${{ steps.create_release.outputs.upload_url }}
289+
asset_path: functions/octolint_macos_amd64_azure.zip
290+
asset_name: octolint_macos_amd64_azure.zip
291+
asset_content_type: application/octet-stream
292+
- name: Upload macOS arm64 Azure Functions Release Asset
293+
uses: actions/upload-release-asset@v1
294+
env:
295+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
296+
with:
297+
upload_url: ${{ steps.create_release.outputs.upload_url }}
298+
asset_path: functions/octolint_macos_arm64_azure.zip
299+
asset_name: octolint_macos_arm64_azure.zip
300+
asset_content_type: application/octet-stream
301+
- name: Upload windows amd64 Azure Functions Release Asset
302+
uses: actions/upload-release-asset@v1
303+
env:
304+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
305+
with:
306+
upload_url: ${{ steps.create_release.outputs.upload_url }}
307+
asset_path: functions/octolint_windows_amd64_azure.exe
308+
asset_name: octolint_windows_amd64_azure.exe
309+
asset_content_type: application/octet-stream
261310
- name: Push packages to Octopus Deploy
262311
if: ${{ steps.branch-name.outputs.current_branch == 'main' }}
263312
uses: OctopusDeploy/push-package-action@v3

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# syntax=docker/dockerfile:1
22

3-
FROM golang:1.22 as build
3+
FROM golang:1.23 AS build
44

55
ARG Version=development
66

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This CLI tool scans an Octopus instance to find potential issues in the configur
1111
Feel free to report
1212
an [issue](https://github.com/OctopusSalesEngineering/OctopusRecommendationEngine/issues).
1313

14-
This tool is not officially supported by Octopus. Please do not contact the Octopus support channels regarding octolint.
14+
Alternatively, contact [Octopus Support](https://octopus.com/support).
1515

1616
## Usage
1717

cmd/azure/octolint.go

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ import (
55
"github.com/OctopusSolutionsEngineering/OctopusRecommendationEngine/internal/args"
66
"github.com/OctopusSolutionsEngineering/OctopusRecommendationEngine/internal/checks"
77
"github.com/OctopusSolutionsEngineering/OctopusRecommendationEngine/internal/entry"
8+
"github.com/OctopusSolutionsEngineering/OctopusRecommendationEngine/internal/environment"
89
"github.com/OctopusSolutionsEngineering/OctopusRecommendationEngine/internal/reporters"
910
"go.uber.org/zap"
1011
"io"
1112
"log"
1213
"net/http"
14+
"net/url"
1315
"os"
1416
"path/filepath"
17+
"strconv"
18+
"strings"
1519
)
1620

1721
type AzureFunctionRequestDataReq struct {
@@ -29,7 +33,20 @@ type AzureFunctionRequest struct {
2933
func octoterraHandler(w http.ResponseWriter, r *http.Request) {
3034
// Allow the more sensitive values to be passed as headers
3135
apiKey := r.Header.Get("X-Octopus-ApiKey")
36+
accessToken := r.Header.Get("X-Octopus-AccessToken")
3237
url := r.Header.Get("X-Octopus-Url")
38+
redirectorRedirections := r.Header.Get("X_REDIRECTION_REDIRECTIONS")
39+
redirectorApiKey := r.Header.Get("X_REDIRECTION_API_KEY")
40+
redirectorServiceApiKey, _ := os.LookupEnv("REDIRECTION_SERVICE_API_KEY")
41+
redirectorHost, _ := os.LookupEnv("REDIRECTION_HOST")
42+
disableRedirector, _ := os.LookupEnv("DISABLE_REDIRECTION")
43+
44+
enableRedirector, err := useRedirector(url, disableRedirector, redirectorServiceApiKey, redirectorHost, redirectorRedirections, redirectorApiKey)
45+
46+
if err != nil {
47+
handleError(err, w)
48+
return
49+
}
3350

3451
respBytes, err := io.ReadAll(r.Body)
3552

@@ -81,12 +98,22 @@ func octoterraHandler(w http.ResponseWriter, r *http.Request) {
8198

8299
if apiKey != "" {
83100
commandLineArgs = append(commandLineArgs, "-apiKey", apiKey)
101+
} else if accessToken != "" {
102+
commandLineArgs = append(commandLineArgs, "-accessToken", accessToken)
84103
}
85104

86105
if url != "" {
87106
commandLineArgs = append(commandLineArgs, "-url", url)
88107
}
89108

109+
if enableRedirector {
110+
commandLineArgs = append(commandLineArgs, "-useRedirector")
111+
commandLineArgs = append(commandLineArgs, "-redirectorHost", redirectorHost)
112+
commandLineArgs = append(commandLineArgs, "-redirectorServiceApiKey", redirectorServiceApiKey)
113+
commandLineArgs = append(commandLineArgs, "-redirecrtorApiKey", redirectorApiKey)
114+
commandLineArgs = append(commandLineArgs, "-redirectorRedirections", redirectorRedirections)
115+
}
116+
90117
webArgs, err := args.ParseArgs(commandLineArgs)
91118

92119
if err != nil {
@@ -116,6 +143,31 @@ func octoterraHandler(w http.ResponseWriter, r *http.Request) {
116143
}
117144
}
118145

146+
func useRedirector(octopusUrl string, disableRedirector string, redirectorServiceApiKey string, redirectorHost string, redirections string, redirectorApiKey string) (bool, error) {
147+
parsedUrl, err := url.Parse(octopusUrl)
148+
149+
if err != nil {
150+
return false, err
151+
}
152+
153+
disableRedirectorParsed, err := strconv.ParseBool(disableRedirector)
154+
155+
if err != nil {
156+
disableRedirectorParsed = false
157+
}
158+
159+
return !disableRedirectorParsed && redirectorServiceApiKey != "" && redirectorHost != "" &&
160+
(!hostIsCloudOrLocal(parsedUrl.Hostname()) ||
161+
(redirections != "" && redirectorApiKey != "")), nil
162+
}
163+
164+
func hostIsCloudOrLocal(host string) bool {
165+
return strings.HasSuffix(host, ".octopus.app") ||
166+
strings.HasSuffix(host, ".testoctopus.com") ||
167+
host == "localhost" ||
168+
host == "127.0.0.1"
169+
}
170+
119171
// sanitizeConfig removes sensitive information from the config so it is not
120172
// persisted to the disk.
121173
func sanitizeConfig(rawConfig []byte) ([]byte, error) {
@@ -129,6 +181,11 @@ func sanitizeConfig(rawConfig []byte) ([]byte, error) {
129181
}
130182
delete(config, "apiKey")
131183
delete(config, "url")
184+
delete(config, "redirectorServiceApiKey")
185+
delete(config, "redirecrtorApiKey")
186+
delete(config, "redirectorHost")
187+
delete(config, "useRedirector")
188+
delete(config, "redirectorRedirections")
132189
return json.Marshal(config)
133190
}
134191

@@ -141,10 +198,7 @@ func handleError(err error, w http.ResponseWriter) {
141198
}
142199

143200
func main() {
144-
listenAddr := ":8080"
145-
if val, ok := os.LookupEnv("FUNCTIONS_CUSTOMHANDLER_PORT"); ok {
146-
listenAddr = ":" + val
147-
}
201+
listenAddr := ":" + environment.GetPort()
148202
http.HandleFunc("/api/octolint", func(writer http.ResponseWriter, request *http.Request) {
149203
switch request.Method {
150204
case http.MethodPost:

go.mod

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,107 @@
11
module github.com/OctopusSolutionsEngineering/OctopusRecommendationEngine
22

3-
go 1.21
3+
go 1.23.0
44

5-
toolchain go1.22.1
5+
toolchain go1.23.7
66

77
require (
8-
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.51.1
9-
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240820223218-e33b5c4d2771
10-
github.com/avast/retry-go/v4 v4.5.1
11-
github.com/briandowns/spinner v1.23.0
12-
github.com/samber/lo v1.39.0
13-
github.com/spf13/pflag v1.0.5
14-
github.com/spf13/viper v1.18.2
8+
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.65.5
9+
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v1.0.0
10+
github.com/avast/retry-go/v4 v4.6.1
11+
github.com/briandowns/spinner v1.23.2
12+
github.com/hayageek/threadsafe v1.0.1
13+
github.com/samber/lo v1.49.1
14+
github.com/spf13/viper v1.20.1
1515
go.uber.org/zap v1.27.0
16-
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
17-
golang.org/x/sync v0.8.0
16+
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394
17+
golang.org/x/sync v0.12.0
1818
)
1919

2020
require (
2121
dario.cat/mergo v1.0.1 // indirect
22-
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
22+
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
2323
github.com/Microsoft/go-winio v0.6.2 // indirect
24-
github.com/Microsoft/hcsshim v0.11.7 // indirect
2524
github.com/OctopusDeploy/go-octodiff v1.0.0 // indirect
2625
github.com/bahlo/generic-list-go v0.2.0 // indirect
2726
github.com/buger/jsonparser v1.1.1 // indirect
2827
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
29-
github.com/containerd/containerd v1.7.20 // indirect
3028
github.com/containerd/log v0.1.0 // indirect
3129
github.com/containerd/platforms v0.2.1 // indirect
32-
github.com/cpuguy83/dockercfg v0.3.1 // indirect
30+
github.com/cpuguy83/dockercfg v0.3.2 // indirect
3331
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3432
github.com/dghubble/sling v1.4.1 // indirect
3533
github.com/distribution/reference v0.6.0 // indirect
36-
github.com/docker/distribution v2.8.2+incompatible // indirect
37-
github.com/docker/docker v27.1.2+incompatible // indirect
34+
github.com/docker/docker v27.5.1+incompatible // indirect
3835
github.com/docker/go-connections v0.5.0 // indirect
3936
github.com/docker/go-units v0.5.0 // indirect
40-
github.com/fatih/color v1.14.1 // indirect
37+
github.com/fatih/color v1.18.0 // indirect
4138
github.com/felixge/httpsnoop v1.0.4 // indirect
42-
github.com/fsnotify/fsnotify v1.7.0 // indirect
43-
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
39+
github.com/fsnotify/fsnotify v1.8.0 // indirect
40+
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
4441
github.com/go-logr/logr v1.4.2 // indirect
4542
github.com/go-logr/stdr v1.2.2 // indirect
4643
github.com/go-ole/go-ole v1.3.0 // indirect
4744
github.com/go-playground/locales v0.14.1 // indirect
4845
github.com/go-playground/universal-translator v0.18.1 // indirect
49-
github.com/go-playground/validator/v10 v10.22.0 // indirect
46+
github.com/go-playground/validator/v10 v10.25.0 // indirect
47+
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
5048
github.com/gogo/protobuf v1.3.2 // indirect
5149
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 // indirect
52-
github.com/golang/protobuf v1.5.4 // indirect
5350
github.com/google/go-querystring v1.1.0 // indirect
5451
github.com/google/uuid v1.6.0 // indirect
55-
github.com/hashicorp/hcl v1.0.0 // indirect
56-
github.com/hayageek/threadsafe v1.0.1 // indirect
57-
github.com/klauspost/compress v1.17.9 // indirect
52+
github.com/klauspost/compress v1.17.11 // indirect
5853
github.com/leodido/go-urn v1.4.0 // indirect
59-
github.com/lufia/plan9stats v0.0.0-20240819163618-b1d8f4d146e7 // indirect
60-
github.com/magiconair/properties v1.8.7 // indirect
54+
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
55+
github.com/magiconair/properties v1.8.9 // indirect
6156
github.com/mailru/easyjson v0.7.7 // indirect
62-
github.com/mattn/go-colorable v0.1.13 // indirect
63-
github.com/mattn/go-isatty v0.0.17 // indirect
64-
github.com/mitchellh/mapstructure v1.5.0 // indirect
57+
github.com/mattn/go-colorable v0.1.14 // indirect
58+
github.com/mattn/go-isatty v0.0.20 // indirect
6559
github.com/moby/docker-image-spec v1.3.1 // indirect
6660
github.com/moby/patternmatcher v0.6.0 // indirect
6761
github.com/moby/sys/sequential v0.6.0 // indirect
6862
github.com/moby/sys/user v0.3.0 // indirect
6963
github.com/moby/sys/userns v0.1.0 // indirect
70-
github.com/moby/term v0.5.0 // indirect
64+
github.com/moby/term v0.5.2 // indirect
7165
github.com/morikuni/aec v1.0.0 // indirect
7266
github.com/opencontainers/go-digest v1.0.0 // indirect
7367
github.com/opencontainers/image-spec v1.1.0 // indirect
74-
github.com/opencontainers/runc v1.1.5 // indirect
7568
github.com/otiai10/copy v1.14.0 // indirect
76-
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
69+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
7770
github.com/pkg/errors v0.9.1 // indirect
7871
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
7972
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
80-
github.com/sagikazarmark/locafero v0.4.0 // indirect
81-
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
73+
github.com/sagikazarmark/locafero v0.9.0 // indirect
8274
github.com/shirou/gopsutil/v3 v3.24.5 // indirect
8375
github.com/shoenig/go-m1cpu v0.1.6 // indirect
8476
github.com/sirupsen/logrus v1.9.3 // indirect
8577
github.com/sourcegraph/conc v0.3.0 // indirect
86-
github.com/spf13/afero v1.11.0 // indirect
87-
github.com/spf13/cast v1.6.0 // indirect
88-
github.com/stretchr/testify v1.9.0 // indirect
78+
github.com/spf13/afero v1.14.0 // indirect
79+
github.com/spf13/cast v1.7.1 // indirect
80+
github.com/spf13/pflag v1.0.6 // indirect
81+
github.com/stretchr/testify v1.10.0 // indirect
8982
github.com/subosito/gotenv v1.6.0 // indirect
90-
github.com/testcontainers/testcontainers-go v0.33.0 // indirect
83+
github.com/testcontainers/testcontainers-go v0.35.0 // indirect
9184
github.com/tklauser/go-sysconf v0.3.14 // indirect
92-
github.com/tklauser/numcpus v0.8.0 // indirect
85+
github.com/tklauser/numcpus v0.9.0 // indirect
9386
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
9487
github.com/yusufpapurcu/wmi v1.2.4 // indirect
95-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
96-
go.opentelemetry.io/otel v1.28.0 // indirect
97-
go.opentelemetry.io/otel/metric v1.28.0 // indirect
98-
go.opentelemetry.io/otel/trace v1.28.0 // indirect
99-
go.uber.org/atomic v1.9.0 // indirect
88+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
89+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
90+
go.opentelemetry.io/otel v1.34.0 // indirect
91+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
92+
go.opentelemetry.io/otel/metric v1.34.0 // indirect
93+
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
94+
go.opentelemetry.io/otel/trace v1.34.0 // indirect
95+
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
10096
go.uber.org/multierr v1.11.0 // indirect
101-
golang.org/x/crypto v0.26.0 // indirect
102-
golang.org/x/mod v0.17.0 // indirect
103-
golang.org/x/net v0.27.0 // indirect
104-
golang.org/x/sys v0.24.0 // indirect
105-
golang.org/x/term v0.23.0 // indirect
106-
golang.org/x/text v0.17.0 // indirect
107-
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
108-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
109-
google.golang.org/grpc v1.64.1 // indirect
110-
google.golang.org/protobuf v1.33.0 // indirect
111-
gopkg.in/ini.v1 v1.67.0 // indirect
97+
golang.org/x/crypto v0.32.0 // indirect
98+
golang.org/x/net v0.34.0 // indirect
99+
golang.org/x/sys v0.31.0 // indirect
100+
golang.org/x/term v0.30.0 // indirect
101+
golang.org/x/text v0.23.0 // indirect
102+
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
103+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 // indirect
104+
google.golang.org/grpc v1.67.1 // indirect
105+
google.golang.org/protobuf v1.35.2 // indirect
112106
gopkg.in/yaml.v3 v3.0.1 // indirect
113107
)

0 commit comments

Comments
 (0)