Skip to content

Commit 091eaa6

Browse files
committed
fix(review): address anti-gravity review feedback for Issue #11
- Change AuditEvent fields to *string to fix nullable scan bug - Add --prune flag to nexus-cli to prevent accidental deletions - Remove dead code and add TrimSpace in IP extraction logic - Add GitHub Actions CI/CD workflow for nexus-cli plan/apply - Verified STATE_KEY fatal-exit guard is present in both broker and gateway
1 parent 530f365 commit 091eaa6

4 files changed

Lines changed: 59 additions & 10 deletions

File tree

.github/workflows/nexus-cli.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Nexus CLI Provider Reconciliation
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'nexus-cli/nexus-providers.yaml'
9+
pull_request:
10+
branches:
11+
- main
12+
paths:
13+
- 'nexus-cli/nexus-providers.yaml'
14+
15+
jobs:
16+
plan-or-apply:
17+
runs-on: ubuntu-latest
18+
defaults:
19+
run:
20+
working-directory: ./nexus-cli
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Go
27+
uses: actions/setup-go@v5
28+
with:
29+
go-version: '1.21'
30+
cache-dependency-path: ./nexus-cli/go.sum
31+
32+
- name: Build CLI
33+
run: go build -o nexus-cli
34+
35+
- name: Plan (Pull Request)
36+
if: github.event_name == 'pull_request'
37+
env:
38+
BROKER_BASE_URL: ${{ secrets.BROKER_BASE_URL }}
39+
API_KEY: ${{ secrets.BROKER_API_KEY }}
40+
run: ./nexus-cli plan
41+
42+
- name: Apply (Push to Main)
43+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
44+
env:
45+
BROKER_BASE_URL: ${{ secrets.BROKER_BASE_URL }}
46+
API_KEY: ${{ secrets.BROKER_API_KEY }}
47+
run: ./nexus-cli apply --prune <<< "yes"

nexus-broker/internal/audit/service.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ func (s *Service) Log(eventType string, connectionID *uuid.UUID, data map[string
2525
if r != nil {
2626
// Extract IP
2727
if fwd := r.Header.Get("X-Forwarded-For"); fwd != "" {
28-
ip := strings.Split(fwd, ",")[0]
29-
if comma := strings.IndexByte(ip, ','); comma != -1 {
30-
ip = strings.TrimSpace(ip[:comma])
31-
}
28+
ip := strings.TrimSpace(strings.Split(fwd, ",")[0])
3229
ipVal = &ip
3330
} else {
3431
host, _, err := net.SplitHostPort(r.RemoteAddr)

nexus-broker/pkg/storage/pg.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ type AuditEvent struct {
7272
ID uuid.UUID `db:"id" json:"id"`
7373
ConnectionID *uuid.UUID `db:"connection_id" json:"connection_id,omitempty"`
7474
EventType string `db:"event_type" json:"event_type"`
75-
EventData string `db:"event_data" json:"event_data,omitempty"`
76-
IPAddress string `db:"ip_address" json:"ip_address,omitempty"`
77-
UserAgent string `db:"user_agent" json:"user_agent,omitempty"`
75+
EventData *string `db:"event_data" json:"event_data,omitempty"`
76+
IPAddress *string `db:"ip_address" json:"ip_address,omitempty"`
77+
UserAgent *string `db:"user_agent" json:"user_agent,omitempty"`
7878
CreatedAt time.Time `db:"created_at" json:"created_at"`
7979
}
8080

nexus-cli/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func main() {
5959
func runCommand(isPlanOnly bool) {
6060
cmdFlags := flag.NewFlagSet(os.Args[1], flag.ExitOnError)
6161
fileFlag := cmdFlags.String("file", "nexus-providers.yaml", "Path to the providers manifest file")
62+
pruneFlag := cmdFlags.Bool("prune", false, "Delete providers not in the manifest")
6263

6364
if err := cmdFlags.Parse(os.Args[2:]); err != nil {
6465
log.Fatalf("Failed to parse flags: %v", err)
@@ -145,9 +146,13 @@ func runCommand(isPlanOnly bool) {
145146

146147
for name, id := range liveProviderMap {
147148
if _, exists := manifestProviderMap[name]; !exists {
148-
toDelete = append(toDelete, id)
149-
toDeleteNames = append(toDeleteNames, name)
150-
fmt.Printf("- DELETE : %s\n", name)
149+
if *pruneFlag {
150+
toDelete = append(toDelete, id)
151+
toDeleteNames = append(toDeleteNames, name)
152+
fmt.Printf("- DELETE : %s\n", name)
153+
} else {
154+
fmt.Printf("! ORPHAN : %s (would be deleted if --prune was passed)\n", name)
155+
}
151156
}
152157
}
153158

0 commit comments

Comments
 (0)