Skip to content
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

Lua config apply #963

Merged
merged 8 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion sdk/config_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,19 @@ func GetNginxConfigWithIgnoreDirectives(
ignoreDirectives []string,
) (*proto.NginxConfig, error) {
readLock.Lock()
lua := crossplane.Lua{}
payload, err := crossplane.Parse(confFile,
&crossplane.ParseOptions{
IgnoreDirectives: ignoreDirectives,
SingleFile: false,
StopParsingOnError: true,
LexOptions: crossplane.LexOptions{
Lexers: []crossplane.RegisterLexer{lua.RegisterLexer()},
},
},
)
if err != nil {
readLock.Unlock()
return nil, fmt.Errorf("error reading config from %s, error: %s", confFile, err)
}

Expand All @@ -144,10 +149,11 @@ func GetNginxConfigWithIgnoreDirectives(

err = updateNginxConfigFromPayload(confFile, payload, nginxConfig, allowedDirectories)
if err != nil {
readLock.Unlock()
return nil, fmt.Errorf("error assemble payload from %s, error: %s", confFile, err)
}
readLock.Unlock()

readLock.Unlock()
return nginxConfig, nil
}

Expand Down
58 changes: 58 additions & 0 deletions sdk/config_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,64 @@ var tests = []struct {
"/tmp/testdata/nginx/ca/ca.crt": {},
},
},
{
fileName: "/tmp/testdata/nginx/lua.conf",
config: `http {
server {
listen 443 ssl;
server_name lua.example.com;

#ssl_certificate /etc/nginx/ssl/server.cert;
#ssl_certificate_key /etc/nginx/ssl/server.key;

ssl_certificate_by_lua_block {
print("Test lua ssl certificate!")
}
}
}`,
plusApi: "",
expected: &proto.NginxConfig{
Action: proto.NginxConfigAction_RETURN,
DirectoryMap: &proto.DirectoryMap{
Directories: []*proto.Directory{
{
Name: "/tmp/testdata/nginx",
Permissions: "0755",
Files: []*proto.File{
{
Name: "lua.conf",
Permissions: "0644",
Lines: int32(12),
},
},
},
},
},
AccessLogs: &proto.AccessLogs{
AccessLog: []*proto.AccessLog{},
},
ErrorLogs: &proto.ErrorLogs{
ErrorLog: []*proto.ErrorLog{},
},
ConfigData: &proto.ConfigDescriptor{
NginxId: nginxID,
SystemId: systemID,
Checksum: "",
},
Ssl: &proto.SslCertificates{
SslCerts: []*proto.SslCertificate{},
},
// using RootDirectory for allowed in the tests, but the "root" directive is /tmp/testdata/foo, so
// should have an empty file list from the aux
Zaux: nil,
Zconfig: &proto.ZippedFile{
Contents: []uint8{31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 1, 0, 0, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0},
Checksum: "46502784daf997bcbbe63e6ec23ee45cbcc666e6657a581c385d5b1416abeb1d",
RootDirectory: "/tmp/testdata/nginx",
},
},
expectedAuxFiles: map[string]struct{}{},
},
}

func TestGetNginxConfigFiles(t *testing.T) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion vendor/github.com/nginx/agent/sdk/v2/config_helpers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.