-
Notifications
You must be signed in to change notification settings - Fork 101
NGINX Configs to Reference Remote External Files #1389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1389 +/- ##
==========================================
+ Coverage 86.31% 86.51% +0.20%
==========================================
Files 102 102
Lines 12603 12801 +198
==========================================
+ Hits 10878 11075 +197
+ Misses 1249 1242 -7
- Partials 476 484 +8
... and 6 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
|
||
| continue | ||
| case model.Delete, model.Update: | ||
| case model.Delete, model.Update, model.ExternalFile: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the external files are the files still considered updated, added or deleted? Just wondering instead should it be a field added to the file rather than an action this might fix a few of the things the linter had an issue with which required the checking of Adding and updating in the switch statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, external files still involve Add and Update actions. The challenge is that these actions are only confirmed after a call to the third-party server. Because we must make this external call every time a reference to the third-party file is encountered, we introduced a new flow that triggers based on the presence of the External File URL.
| return fso.sendUpdateFileStream(ctx, fileToUpdate, fso.agentConfig.Client.Grpc.FileChunkSize) | ||
| } | ||
|
|
||
| func (fso *FileServiceOperator) RenameExternalFile( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of duplicating the RenameFile function can we update the RenameFile function to just rename the file and have the hash validation in a separate function like this:
func (fso *FileServiceOperator) RenameAndValidateFile(
ctx context.Context, source, destination string,
) error {
err := fso.RenameFile(ctx, source, destination)
if err != nil {
return err
}
return fso.validateFileHash(desination, hash)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The core issue with the current implementation is that the function call lacks necessary attributes to make a decision. Specifically, we should only proceed with the hash validation if File.GetExternalDataSource() returns an empty value.
| wantErrMsg string | ||
| wantErr bool | ||
| }{ | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these tests please be combined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| return filepath.Join(filepath.Dir(fileName), tempFileName) | ||
| } | ||
|
|
||
| func (fms *FileManagerService) downloadExternalFile(ctx context.Context, fileAction *model.FileCache, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add an extra operator maybe like the file operator to handle the external file download as this file is getting a little too large and complex
| for _, fileAction := range fms.fileActions { | ||
| var err error | ||
| fileMeta := fileAction.File.GetFileMeta() | ||
| tempFilePath := tempFilePath(fileAction.File.GetFileMeta().GetName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could fileMeta be used more instead of fileAction.File.GetFileMeta() throughout this for loop?
| tempFilePath := tempFilePath(fileAction.File.GetFileMeta().GetName()) | |
| tempFilePath := tempFilePath(fileMeta.GetName()) |
| regexLabelPattern = "^[a-zA-Z0-9]([a-zA-Z0-9-_]{0,254}[a-zA-Z0-9])?$" | ||
| ) | ||
|
|
||
| var domainRegex = regexp.MustCompile( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we group the two var declarations into one block?
| var domainRegex = regexp.MustCompile( | |
| var ( | |
| domainRegex = regexp.MustCompile( | |
| `^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$`, | |
| ) | |
| viperInstance = viper.NewWithOptions(viper.KeyDelimiter(KeyDelimiter)) | |
| ) |
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)