NGINX Configs to Reference Remote External Files#1389
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1389 +/- ##
==========================================
- Coverage 85.13% 85.05% -0.09%
==========================================
Files 102 103 +1
Lines 13217 13487 +270
==========================================
+ Hits 11252 11471 +219
- Misses 1475 1506 +31
- Partials 490 510 +20
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
| wantErrMsg string | ||
| wantErr bool | ||
| }{ | ||
| { |
There was a problem hiding this comment.
The following scenarios could increase coverage:
- No destination specified
- Restricted directory.
- Two files to the same destination.
| }{ | ||
| { | ||
| name: "Test 1: success", | ||
| prepare: func(t *testing.T) (string, string) { |
There was a problem hiding this comment.
Can this be changed to follow the way other tests are set up and formatted
| } | ||
|
|
||
| //nolint:gocognit,revive,govet // cognitive complexity is 22 | ||
| func TestFileManagerService_downloadExternalFiles_Cases(t *testing.T) { |
There was a problem hiding this comment.
Can this test be simplified and changed to match the way other tests are set up and structured
| assert.Equal(t, fileName, dstArg, "RenameExternalFile destination argument mismatch") | ||
| } | ||
|
|
||
| func TestDownloadFileContent_MaxBytesLimit(t *testing.T) { |
There was a problem hiding this comment.
Can these tests please be combined
There was a problem hiding this comment.
I tried to consolidate these divergent test scenarios (MaxBytes vs. Proxy Errors) but it spiked the cognitive complexity to 23 due the very different validation steps. Therefore I kept them seperate.
# Conflicts: # internal/config/config.go # internal/config/types.go # internal/file/file_manager_service.go
# Conflicts: # internal/file/file_manager_service.go
e50d100 to
2e981e0
Compare
|
✅ All required contributors have signed the F5 CLA for this PR. Thank you! |
52e6aa3 to
99042ad
Compare
internal/config/config.go
Outdated
| for _, domain := range domains { | ||
| // Validating syntax using the RFC-compliant regex | ||
| if !domainRegex.MatchString(domain) || domain == "" { | ||
| slog.Error("domain specified in allowed_domains is invalid", "domain", domain) |
There was a problem hiding this comment.
Can you remove this log line and have a log message in the resolveExternalDataSource function instead?
| } | ||
|
|
||
| if err := validateAllowedDomains(externalDataSource.AllowedDomains); err != nil { | ||
| return nil |
There was a problem hiding this comment.
Can you add a log line here like this
slog.Error("External data source not configured due to invalid configuration", "error", err)
| permission := fileAction.File.GetFileMeta().GetPermissions() | ||
| fileName := fileAction.File.GetFileMeta().GetName() | ||
|
|
||
| slog.InfoContext(ctx, "Downloading external file from", "location", location) |
There was a problem hiding this comment.
| slog.InfoContext(ctx, "Downloading external file from", "location", location) | |
| slog.InfoContext(ctx, "Downloading external file", "location", location) |
| headers.ETag = resp.Header.Get("ETag") | ||
| headers.LastModified = resp.Header.Get("Last-Modified") | ||
| case http.StatusNotModified: | ||
| slog.DebugContext(ctx, "File content unchanged (304 Not Modified)", "file_name", fileName) |
There was a problem hiding this comment.
| slog.DebugContext(ctx, "File content unchanged (304 Not Modified)", "file_name", fileName) | |
| slog.InfoContext(ctx, "Received 304 status code in response from external data source, file has not been modified", "file_name", fileName) |
I think this would be better as info instead for debug
| case model.Delete: | ||
| slog.InfoContext(ctx, "Deleting file", "file", fileAction.File.GetFileMeta().GetName()) | ||
| if err := os.Remove(fileAction.File.GetFileMeta().GetName()); err != nil && !os.IsNotExist(err) { | ||
| slog.DebugContext(ctx, "Deleting file", "file", fileMeta.GetName()) |
There was a problem hiding this comment.
| slog.DebugContext(ctx, "Deleting file", "file", fileMeta.GetName()) | |
| slog.InfoContext(ctx, "Deleting file", "file", fileMeta.GetName()) |
internal/file/file_plugin.go
Outdated
| if rollbackErr != nil { | ||
| // include both the original apply error and the rollback error so the management plane | ||
| // receives actionable information about what failed during apply and what failed during rollback | ||
| combinedErr := fmt.Sprintf("apply error: %s; rollback error: %s", err.Error(), rollbackErr.Error()) |
There was a problem hiding this comment.
Would it be better to use errors.Join function here?
Extends the ConfigApply capability to manage NGINX configurations that reference external resources hosted at remote URLs. The agent now handles downloading of these files into the NGINX configuration directory before applying the new configuration.
Checklist
Before creating a PR, run through this checklist and mark each as complete.
CONTRIBUTINGdocumentmake install-toolsand have attached any dependency changes to this pull requestREADME.md)