-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
278 lines (250 loc) · 10.9 KB
/
Copy pathMakefile
File metadata and controls
278 lines (250 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
.PHONY: help build install clean test fmt vet lint deps
.PHONY: search-github scan-github fix-github scan-local fix-local
.PHONY: scan-json fix-auto check dev ci build-all
# Configuration
BINARY_NAME := code-remediate
ORG ?=
LOCAL_REPOS_PATH ?=
GITHUB_REPOS_DIR ?=
DEBUG_FLAG := $(if $(DEBUG),--debug,)
# Default target
help:
@echo "════════════════════════════════════════════════════════════════"
@echo "AWS Advanced Wrapper Vulnerability Scanner - Makefile"
@echo "════════════════════════════════════════════════════════════════"
@echo ""
@echo "📦 BUILD TARGETS:"
@echo " build - Build the binary"
@echo " install - Install to GOPATH/bin"
@echo " build-all - Build for all platforms (Linux, macOS, Windows)"
@echo " clean - Remove build artifacts"
@echo ""
@echo "🧪 TESTING & QUALITY:"
@echo " test - Run all tests"
@echo " test-cover - Run tests with coverage report"
@echo " fmt - Format code"
@echo " vet - Run go vet"
@echo " lint - Run golangci-lint (if installed)"
@echo " check - Quick validation (build + vet + test)"
@echo " dev - Development workflow (fmt + vet + test + build)"
@echo " ci - CI workflow (deps + fmt + vet + test + build)"
@echo ""
@echo "🔍 GITHUB SOURCE OPERATIONS:"
@echo " search-github - Search GitHub org for packages"
@echo " scan-github - Scan GitHub org for vulnerabilities"
@echo " scan-json - Scan GitHub org and output JSON"
@echo " fix-github - Fix vulnerabilities in GitHub repos (with local dir)"
@echo " fix-auto - Fully automated fix (auto-clone + branch + commit)"
@echo ""
@echo "📁 LOCAL SOURCE OPERATIONS:"
@echo " scan-local - Scan local directory for vulnerabilities"
@echo " fix-local - Fix vulnerabilities in local directory"
@echo ""
@echo "📝 REQUIRED VARIABLES:"
@echo " ORG - GitHub organization name (for GitHub operations)"
@echo " LOCAL_REPOS_PATH - Path to local repositories (for scan-local, fix-local)"
@echo ""
@echo "🎛️ OPTIONAL VARIABLES:"
@echo " DEBUG=1 - Enable debug logging"
@echo " GITHUB_REPOS_DIR - Directory with cloned GitHub repos (for fix-github)"
@echo ""
@echo "💡 EXAMPLES:"
@echo " # Using Makefile targets:"
@echo " make search-github ORG=MyOrg"
@echo " make scan-github ORG=MyOrg"
@echo " make scan-json ORG=MyOrg > results.json"
@echo " make fix-github ORG=MyOrg GITHUB_REPOS_DIR=~/projects"
@echo " make fix-auto ORG=MyOrg"
@echo " make scan-local LOCAL_REPOS_PATH=/path/to/repos"
@echo " make fix-local LOCAL_REPOS_PATH=/path/to/repos"
@echo ""
@echo " # Direct binary usage:"
@echo " ./code-remediate --source=github --org=MyOrg search"
@echo " ./code-remediate --source=github --org=MyOrg scan"
@echo " ./code-remediate --source=github --org=MyOrg scan -f json > output.json"
@echo " ./code-remediate --source=local --path=/repos scan"
@echo " ./code-remediate --source=github --org=MyOrg fix --auto-clone --auto-commit"
@echo ""
@echo "════════════════════════════════════════════════════════════════"
# Build the binary
build:
@echo "🔨 Building $(BINARY_NAME)..."
@go build -o $(BINARY_NAME) .
@echo "✅ Build complete: ./$(BINARY_NAME)"
# Install to GOPATH/bin
install:
@echo "📦 Installing $(BINARY_NAME)..."
@go install .
@echo "✅ Installed to GOPATH/bin"
# Clean build artifacts
clean:
@echo "🧹 Cleaning build artifacts..."
@rm -f $(BINARY_NAME)
@rm -f $(BINARY_NAME)-*
@rm -f *.test
@rm -f coverage.txt coverage.html
@rm -rf code-remediate-repos/
@echo "✅ Clean complete"
# Download dependencies
deps:
@echo "📦 Downloading dependencies..."
go mod download
go mod tidy
@echo "✅ Dependencies ready"
#═══════════════════════════════════════════════════════════════
# GITHUB SOURCE OPERATIONS
#═══════════════════════════════════════════════════════════════
# Search GitHub organization for AWS wrapper packages
search-github: build
@if [ -z "$(ORG)" ]; then \
echo "❌ Error: ORG variable required"; \
echo "Usage: make search-github ORG=MyOrganization"; \
exit 1; \
fi
@echo "🔍 Searching GitHub organization: $(ORG)"
@./$(BINARY_NAME) --source=github --org=$(ORG) search $(DEBUG_FLAG)
# Scan GitHub organization for vulnerabilities (human-readable report)
scan-github: build
@if [ -z "$(ORG)" ]; then \
echo "❌ Error: ORG variable required"; \
echo "Usage: make scan-github ORG=MyOrganization"; \
exit 1; \
fi
@echo "🔍 Scanning GitHub organization: $(ORG)"
@./$(BINARY_NAME) --source=github --org=$(ORG) scan $(DEBUG_FLAG)
# Scan GitHub organization and output JSON
scan-json: build
@if [ -z "$(ORG)" ]; then \
echo "❌ Error: ORG variable required"; \
echo "Usage: make scan-json ORG=MyOrganization > results.json"; \
exit 1; \
fi
@./$(BINARY_NAME) --source=github --org=$(ORG) scan --output=json
# Fix vulnerabilities with local repositories
fix-github: build
@if [ -z "$(ORG)" ]; then \
echo "❌ Error: ORG variable required"; \
echo "Usage: make fix-github ORG=MyOrg GITHUB_REPOS_DIR=~/projects"; \
exit 1; \
fi
@if [ -z "$(GITHUB_REPOS_DIR)" ]; then \
echo "❌ Error: GITHUB_REPOS_DIR variable required"; \
echo "Usage: make fix-github ORG=MyOrg GITHUB_REPOS_DIR=~/projects"; \
exit 1; \
fi
@echo "🔧 Fixing vulnerabilities in GitHub repos"
@echo "📁 Using local repos: $(GITHUB_REPOS_DIR)"
@./$(BINARY_NAME) --source=github --org=$(ORG) fix \
--local-repos-dir=$(GITHUB_REPOS_DIR) \
--auto-branch \
--auto-commit \
$(DEBUG_FLAG)
@echo ""
@echo "✅ Fix complete! Next steps:"
@echo " 1. Review the changes in each repository"
@echo " 2. Push branches: cd $(GITHUB_REPOS_DIR)/<repo> && git push"
@echo " 3. Create pull requests using 'gh pr create'"
# Fully automated fix (auto-clone + branch + commit)
fix-auto: build
@if [ -z "$(ORG)" ]; then \
echo "❌ Error: ORG variable required"; \
echo "Usage: make fix-auto ORG=MyOrganization"; \
exit 1; \
fi
@echo "🔧 Running fully automated fix for: $(ORG)"
@echo "⚠️ This will clone repositories automatically!"
@./$(BINARY_NAME) --source=github --org=$(ORG) fix \
--auto-clone \
--auto-branch \
--auto-commit \
$(DEBUG_FLAG)
@echo ""
@echo "✅ Automated fix complete!"
@echo " Repositories cloned to: code-remediate-repos/"
@echo " Review changes, push branches, and create PRs"
#═══════════════════════════════════════════════════════════════
# LOCAL SOURCE OPERATIONS
#═══════════════════════════════════════════════════════════════
# Scan local directory for vulnerabilities
scan-local: build
@if [ -z "$(LOCAL_REPOS_PATH)" ]; then \
echo "❌ Error: LOCAL_REPOS_PATH variable required"; \
echo "Usage: make scan-local LOCAL_REPOS_PATH=/path/to/repos"; \
exit 1; \
fi
@echo "🔍 Scanning local directory: $(LOCAL_REPOS_PATH)"
@./$(BINARY_NAME) --source=local --path=$(LOCAL_REPOS_PATH) scan $(DEBUG_FLAG)
# Fix vulnerabilities in local directory
fix-local: build
@if [ -z "$(LOCAL_REPOS_PATH)" ]; then \
echo "❌ Error: LOCAL_REPOS_PATH variable required"; \
echo "Usage: make fix-local LOCAL_REPOS_PATH=/path/to/repos"; \
exit 1; \
fi
@echo "🔧 Fixing vulnerabilities in: $(LOCAL_REPOS_PATH)"
@./$(BINARY_NAME) --source=local --path=$(LOCAL_REPOS_PATH) fix \
--auto-branch \
--auto-commit \
$(DEBUG_FLAG)
@echo ""
@echo "✅ Fix complete!"
@echo " 1. Review changes in $(LOCAL_REPOS_PATH)"
@echo " 2. Push branches and create pull requests"
#═══════════════════════════════════════════════════════════════
# BUILD TARGETS
#═══════════════════════════════════════════════════════════════
# Build for multiple platforms
build-all:
@echo "🔨 Building for multiple platforms..."
@GOOS=linux GOARCH=amd64 go build -o $(BINARY_NAME)-linux-amd64 .
@GOOS=darwin GOARCH=amd64 go build -o $(BINARY_NAME)-darwin-amd64 .
@GOOS=darwin GOARCH=arm64 go build -o $(BINARY_NAME)-darwin-arm64 .
@GOOS=windows GOARCH=amd64 go build -o $(BINARY_NAME)-windows-amd64.exe .
@echo "✅ Built for all platforms:"
@ls -lh $(BINARY_NAME)-*
#═══════════════════════════════════════════════════════════════
# TESTING & QUALITY
#═══════════════════════════════════════════════════════════════
# Run tests
test:
@echo "🧪 Running tests..."
@go test -v ./...
# Run tests with coverage
test-cover:
@echo "🧪 Running tests with coverage..."
@go test -coverprofile=coverage.txt -covermode=atomic ./...
@go tool cover -html=coverage.txt -o coverage.html
@echo "✅ Coverage report: coverage.html"
@go tool cover -func=coverage.txt | grep total
# Format code
fmt:
@echo "✨ Formatting code..."
@go fmt ./...
@echo "✅ Code formatted"
# Run go vet
vet:
@echo "🔍 Running go vet..."
@go vet ./...
@echo "✅ Vet complete"
# Run linter (requires golangci-lint)
lint:
@echo "🔍 Running golangci-lint..."
@if command -v golangci-lint > /dev/null; then \
golangci-lint run; \
echo "✅ Lint complete"; \
else \
echo "⚠️ golangci-lint not installed"; \
echo " Install: https://golangci-lint.run/"; \
fi
#═══════════════════════════════════════════════════════════════
# WORKFLOW TARGETS
#═══════════════════════════════════════════════════════════════
# Quick check (build, vet, test)
check: build vet test
@echo "✅ All checks passed"
# Development workflow
dev: fmt vet test build
@echo "✅ Development build complete"
# CI workflow
ci: deps fmt vet test-cover build
@echo "✅ CI build complete"