Skip to content
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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:

env:
GOLANGCI_LINT_VERSION: 'v1.49.0'
GOLANGCI_LINT_VERSION: 'v1.50.1'
NFPM_VERSION: 'v2.18.1'

jobs:
Expand All @@ -13,6 +13,9 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
- name: Lint Agent Code
uses: golangci/golangci-lint-action@v3
with:
Expand Down
8 changes: 2 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,8 @@ func handleSignals(
}()
}

func connectionUnavilable(loadedConfig *config.Config) bool {
return loadedConfig.Server.Host == "" || loadedConfig.Server.GrpcPort == 0
}

func createGrpcClients(ctx context.Context, loadedConfig *config.Config) (client.Controller, client.Commander, client.MetricReporter) {
if connectionUnavilable(loadedConfig) {
if !loadedConfig.IsGrpcServerConfigured() {
log.Infof("GRPC clients not created")
return nil, nil, nil
}
Expand Down Expand Up @@ -234,7 +230,7 @@ func loadPlugins(commander client.Commander, binary *core.NginxBinaryType, env *
corePlugins = append(corePlugins, plugins.NewAdvancedMetrics(env, loadedConfig))
}

if loadedConfig.NginxAppProtect != (config.NginxAppProtect{}) {
if loadedConfig.IsNginxAppProtectConfigured() {
napPlugin, err := plugins.NewNginxAppProtect(loadedConfig, env)
if err == nil {
corePlugins = append(corePlugins, napPlugin)
Expand Down
245 changes: 148 additions & 97 deletions sdk/proto/command.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sdk/proto/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ message NginxConfigStatus {
string correlation_id = 1 [(gogoproto.jsontag) = "correlation_id" ];
Status status = 2 [(gogoproto.jsontag) = "status" ];
string message = 3 [(gogoproto.jsontag) = "message" ];
string nginx_id = 4 [(gogoproto.jsontag) = "nginx_id" ];

enum Status {
PENDING = 0;
Expand Down
17 changes: 17 additions & 0 deletions src/core/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ type Config struct {
NAPMonitoring NAPMonitoring `mapstructure:"nap_monitoring" yaml:"nap_monitoring,omitempty"`
}

func (c *Config) IsGrpcServerConfigured() bool {
return c.Server.Host != "" && c.Server.GrpcPort != 0
}

func (c *Config) IsNginxAppProtectConfigured() bool {
return c.NginxAppProtect != (NginxAppProtect{})
}

func (c *Config) IsFeatureEnabled(feature string) bool {
for _, configFeature := range c.Features {
if configFeature == feature {
return true
}
}
return false
}

type Server struct {
Host string `mapstructure:"host" yaml:"-"`
GrpcPort int `mapstructure:"grpcPort" yaml:"-"`
Expand Down
8 changes: 5 additions & 3 deletions src/core/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,11 @@ func (n *NginxBinaryType) ValidateConfig(processId, bin, configLocation string,
log.Debugf("Validating config, %s for nginx process, %s", configLocation, processId)
response, err := runCmd(bin, "-t", "-c", configLocation)
if err != nil {
confFiles, auxFiles, err := sdk.GetNginxConfigFiles(config)
n.writeBackup(config, confFiles, auxFiles)
return fmt.Errorf("error running nginx -t -c %v:\n%s%v", configLocation, response, err)
confFiles, auxFiles, getNginxConfigFilesErr := sdk.GetNginxConfigFiles(config)
if getNginxConfigFilesErr == nil {
n.writeBackup(config, confFiles, auxFiles)
}
return fmt.Errorf("error running nginx -t -c %v:\n%s", configLocation, response)
}

log.Infof("Config validated:\n%s", response)
Expand Down
1 change: 1 addition & 0 deletions src/core/topics.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ const (
ConfigRollbackResponse = "config.rollback.response"
DataplaneSoftwareDetailsUpdated = "dataplane.software.details.updated"
EnableExtension = "enable.extension"
AgentAPIConfigApplyResponse = "agent.api.config.apply.response"
)
Loading