Skip to content

Commit e8b18d3

Browse files
oliveromahonysean-breenaphralG
authored
Lua config apply (#963)
* added the config to unit test * updated crossplane version * fix hanging agent * fix hanging agent * added http block * add Lua LexOptions by default when calling crossplane.Parse * make deps --------- Co-authored-by: Sean Breen <[email protected]> Co-authored-by: Aphral Griffin <[email protected]>
1 parent 192b9cd commit e8b18d3

File tree

5 files changed

+86
-4
lines changed

5 files changed

+86
-4
lines changed

sdk/config_helpers.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,19 @@ func GetNginxConfigWithIgnoreDirectives(
117117
ignoreDirectives []string,
118118
) (*proto.NginxConfig, error) {
119119
readLock.Lock()
120+
lua := crossplane.Lua{}
120121
payload, err := crossplane.Parse(confFile,
121122
&crossplane.ParseOptions{
122123
IgnoreDirectives: ignoreDirectives,
123124
SingleFile: false,
124125
StopParsingOnError: true,
126+
LexOptions: crossplane.LexOptions{
127+
Lexers: []crossplane.RegisterLexer{lua.RegisterLexer()},
128+
},
125129
},
126130
)
127131
if err != nil {
132+
readLock.Unlock()
128133
return nil, fmt.Errorf("error reading config from %s, error: %s", confFile, err)
129134
}
130135

@@ -144,10 +149,11 @@ func GetNginxConfigWithIgnoreDirectives(
144149

145150
err = updateNginxConfigFromPayload(confFile, payload, nginxConfig, allowedDirectories)
146151
if err != nil {
152+
readLock.Unlock()
147153
return nil, fmt.Errorf("error assemble payload from %s, error: %s", confFile, err)
148154
}
149-
readLock.Unlock()
150155

156+
readLock.Unlock()
151157
return nginxConfig, nil
152158
}
153159

sdk/config_helpers_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,64 @@ var tests = []struct {
799799
"/tmp/testdata/nginx/ca/ca.crt": {},
800800
},
801801
},
802+
{
803+
fileName: "/tmp/testdata/nginx/lua.conf",
804+
config: `http {
805+
server {
806+
listen 443 ssl;
807+
server_name lua.example.com;
808+
809+
#ssl_certificate /etc/nginx/ssl/server.cert;
810+
#ssl_certificate_key /etc/nginx/ssl/server.key;
811+
812+
ssl_certificate_by_lua_block {
813+
print("Test lua ssl certificate!")
814+
}
815+
}
816+
}`,
817+
plusApi: "",
818+
expected: &proto.NginxConfig{
819+
Action: proto.NginxConfigAction_RETURN,
820+
DirectoryMap: &proto.DirectoryMap{
821+
Directories: []*proto.Directory{
822+
{
823+
Name: "/tmp/testdata/nginx",
824+
Permissions: "0755",
825+
Files: []*proto.File{
826+
{
827+
Name: "lua.conf",
828+
Permissions: "0644",
829+
Lines: int32(12),
830+
},
831+
},
832+
},
833+
},
834+
},
835+
AccessLogs: &proto.AccessLogs{
836+
AccessLog: []*proto.AccessLog{},
837+
},
838+
ErrorLogs: &proto.ErrorLogs{
839+
ErrorLog: []*proto.ErrorLog{},
840+
},
841+
ConfigData: &proto.ConfigDescriptor{
842+
NginxId: nginxID,
843+
SystemId: systemID,
844+
Checksum: "",
845+
},
846+
Ssl: &proto.SslCertificates{
847+
SslCerts: []*proto.SslCertificate{},
848+
},
849+
// using RootDirectory for allowed in the tests, but the "root" directive is /tmp/testdata/foo, so
850+
// should have an empty file list from the aux
851+
Zaux: nil,
852+
Zconfig: &proto.ZippedFile{
853+
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},
854+
Checksum: "46502784daf997bcbbe63e6ec23ee45cbcc666e6657a581c385d5b1416abeb1d",
855+
RootDirectory: "/tmp/testdata/nginx",
856+
},
857+
},
858+
expectedAuxFiles: map[string]struct{}{},
859+
},
802860
}
803861

804862
func TestGetNginxConfigFiles(t *testing.T) {

test/integration/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/performance/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/nginx/agent/sdk/v2/config_helpers.go

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)