Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Angel Santiago <>
  • Loading branch information
Jose Angel Santiago committed Apr 15, 2021
1 parent 44d3026 commit 1e714aa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func init() {

if config.Alertmanager.HostPort != "" {
var err error
alertmanagerClient, err = outputs.NewClient("AlertManager", config.Alertmanager.HostPort+outputs.AlertmanagerURI, config.Alertmanager.MutualTls, config, stats, promStats, statsdClient, dogstatsdClient)
alertmanagerClient, err = outputs.NewClient("AlertManager", config.Alertmanager.HostPort+outputs.AlertmanagerURI, config.Alertmanager.MutualTLS, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Alertmanager.HostPort = ""
} else {
Expand All @@ -158,7 +158,7 @@ func init() {

if config.Elasticsearch.HostPort != "" {
var err error
elasticsearchClient, err = outputs.NewClient("Elasticsearch", config.Elasticsearch.HostPort+"/"+config.Elasticsearch.Index+"/"+config.Elasticsearch.Type, config.Elasticsearch.MutualTls, config, stats, promStats, statsdClient, dogstatsdClient)
elasticsearchClient, err = outputs.NewClient("Elasticsearch", config.Elasticsearch.HostPort+"/"+config.Elasticsearch.Index+"/"+config.Elasticsearch.Type, config.Elasticsearch.MutualTLS, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Elasticsearch.HostPort = ""
} else {
Expand All @@ -178,7 +178,7 @@ func init() {

if config.Nats.HostPort != "" {
var err error
natsClient, err = outputs.NewClient("NATS", config.Nats.HostPort, config.Nats.MutualTls, config, stats, promStats, statsdClient, dogstatsdClient)
natsClient, err = outputs.NewClient("NATS", config.Nats.HostPort, config.Nats.MutualTLS, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Nats.HostPort = ""
} else {
Expand All @@ -205,7 +205,7 @@ func init() {
}

var err error
influxdbClient, err = outputs.NewClient("Influxdb", config.Influxdb.HostPort+"/write?db="+config.Influxdb.Database+credentials, config.Influxdb.MutualTls, config, stats, promStats, statsdClient, dogstatsdClient)
influxdbClient, err = outputs.NewClient("Influxdb", config.Influxdb.HostPort+"/write?db="+config.Influxdb.Database+credentials, config.Influxdb.MutualTLS, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Influxdb.HostPort = ""
} else {
Expand Down Expand Up @@ -272,7 +272,7 @@ func init() {

if config.Webhook.Address != "" {
var err error
webhookClient, err = outputs.NewClient("Webhook", config.Webhook.Address, config.Webhook.MutualTls, config, stats, promStats, statsdClient, dogstatsdClient)
webhookClient, err = outputs.NewClient("Webhook", config.Webhook.Address, config.Webhook.MutualTLS, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Webhook.Address = ""
} else {
Expand Down
20 changes: 10 additions & 10 deletions outputs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ var ErrClientCreation = errors.New("Client creation Error")
// EnabledOutputs list all enabled outputs
var EnabledOutputs []string

// Mutual TLS files names are static to work with helm and single docker modes
var MutualTlsClientCertFilename = "/client.crt"
var MutualTlsClientKeyFilename = "/client.key"
var MutualTlsCacertFilename = "/ca.crt"
// files names are static fo the shake of helm and single docker compatibility
var MutualTLSClientCertFilename = "/client.crt"
var MutualTLSClientKeyFilename = "/client.key"
var MutualTLSCacertFilename = "/ca.crt"

// Client communicates with the different API.
type Client struct {
OutputType string
EndpointURL *url.URL
MutualTlsEnabled bool
MutualTLSEnabled bool
Config *types.Configuration
Stats *types.Statistics
PromStats *types.PromStatistics
Expand All @@ -78,7 +78,7 @@ type Client struct {
}

// NewClient returns a new output.Client for accessing the different API.
func NewClient(outputType string, defaultEndpointURL string, mutualTlsEnabled bool, config *types.Configuration, stats *types.Statistics, promStats *types.PromStatistics, statsdClient, dogstatsdClient *statsd.Client) (*Client, error) {
func NewClient(outputType string, defaultEndpointURL string, mutualTLSEnabled bool, config *types.Configuration, stats *types.Statistics, promStats *types.PromStatistics, statsdClient, dogstatsdClient *statsd.Client) (*Client, error) {
reg := regexp.MustCompile(`(http|nats)(s?)://.*`)
if !reg.MatchString(defaultEndpointURL) {
log.Printf("[ERROR] : %v - %v\n", outputType, "Bad Endpoint")
Expand All @@ -93,7 +93,7 @@ func NewClient(outputType string, defaultEndpointURL string, mutualTlsEnabled bo
log.Printf("[ERROR] : %v - %v\n", outputType, err.Error())
return nil, ErrClientCreation
}
return &Client{OutputType: outputType, EndpointURL: endpointURL, MutualTlsEnabled: mutualTlsEnabled, Config: config, Stats: stats, PromStats: promStats, StatsdClient: statsdClient, DogstatsdClient: dogstatsdClient}, nil
return &Client{OutputType: outputType, EndpointURL: endpointURL, MutualTLSEnabled: mutualTLSEnabled, Config: config, Stats: stats, PromStats: promStats, StatsdClient: statsdClient, DogstatsdClient: dogstatsdClient}, nil
}

// Post sends event (payload) to Output.
Expand All @@ -120,15 +120,15 @@ func (c *Client) Post(payload interface{}) error {

customTransport := http.DefaultTransport.(*http.Transport).Clone()

if c.MutualTlsEnabled {
if c.MutualTLSEnabled {
// Load client cert
cert, err := tls.LoadX509KeyPair(c.Config.MutualTlsFilesPath + MutualTlsClientCertFilename, c.Config.MutualTlsFilesPath + MutualTlsClientKeyFilename)
cert, err := tls.LoadX509KeyPair(c.Config.MutualTLSFilesPath+MutualTLSClientCertFilename, c.Config.MutualTLSFilesPath+MutualTLSClientKeyFilename)
if err != nil {
log.Printf("[ERROR] : %v - %v\n", c.OutputType, err.Error())
}

// Load CA cert
caCert, err := ioutil.ReadFile(c.Config.MutualTlsFilesPath + MutualTlsCacertFilename)
caCert, err := ioutil.ReadFile(c.Config.MutualTLSFilesPath + MutualTLSCacertFilename)
if err != nil {
log.Printf("[ERROR] : %v - %v\n", c.OutputType, err.Error())
}
Expand Down
40 changes: 20 additions & 20 deletions outputs/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestNewClient(t *testing.T) {
stats := &types.Statistics{}
promStats := &types.PromStatistics{}

testClientOutput := Client{OutputType: "test", EndpointURL: u, MutualTlsEnabled: false, Config: config, Stats: stats, PromStats: promStats}
testClientOutput := Client{OutputType: "test", EndpointURL: u, MutualTLSEnabled: false, Config: config, Stats: stats, PromStats: promStats}
_, err := NewClient("test", "localhost/%*$¨^!/:;", false, config, stats, promStats, nil, nil)
require.NotNil(t, err)

Expand Down Expand Up @@ -87,16 +87,16 @@ func TestPost(t *testing.T) {

func TestMutualTlsPost(t *testing.T) {
config := &types.Configuration{}
config.MutualTlsFilesPath = "/tmp/falcosidekicktests"
config.MutualTLSFilesPath = "/tmp/falcosidekicktests"
// delete folder to avoid makedir failure
os.RemoveAll(config.MutualTlsFilesPath)
os.RemoveAll(config.MutualTLSFilesPath)

serverTLSConf, err := certsetup(config)
if err != nil {
require.Nil(t, err)
}
require.Nil(t, err)
}

tls_url := "127.0.0.1:5443"
tlsUrl := "127.0.0.1:5443"

// set up the httptest.Server using our certificate signed by our CA
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -109,13 +109,13 @@ func TestMutualTlsPost(t *testing.T) {
}))
// This Listen config is required since server.URL generates a "Server already started" Panic error
// Check https://golang.org/src/net/http/httptest/server.go#:~:text=s.URL
l, _ := net.Listen("tcp", tls_url)
server.Listener = l
l, _ := net.Listen("tcp", tlsUrl)
server.Listener = l
server.TLS = serverTLSConf
server.StartTLS()
defer server.Close()

nc, err := NewClient("", server.URL + "/200", true, config, &types.Statistics{}, &types.PromStatistics{}, nil, nil)
nc, err := NewClient("", server.URL+"/200", true, config, &types.Statistics{}, &types.PromStatistics{}, nil, nil)
require.Nil(t, err)
require.NotEmpty(t, nc)

Expand All @@ -125,10 +125,10 @@ func TestMutualTlsPost(t *testing.T) {
}

func certsetup(config *types.Configuration) (serverTLSConf *tls.Config, err error) {
err = os.Mkdir(config.MutualTlsFilesPath, 0755)
if err != nil {
return nil, err
}
err = os.Mkdir(config.MutualTLSFilesPath, 0755)
if err != nil {
return nil, err
}

// set up our CA certificate
ca := &x509.Certificate{
Expand Down Expand Up @@ -169,7 +169,7 @@ func certsetup(config *types.Configuration) (serverTLSConf *tls.Config, err erro
})

// save ca to ca.crt file (it will be used by Client)
err = ioutil.WriteFile(config.MutualTlsFilesPath + "/ca.crt", caPEM.Bytes(), 0644)
err = ioutil.WriteFile(config.MutualTLSFilesPath+"/ca.crt", caPEM.Bytes(), 0644)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -220,15 +220,15 @@ func certsetup(config *types.Configuration) (serverTLSConf *tls.Config, err erro
if err != nil {
return nil, err
}

// create server TLS config
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caPEM.Bytes())
serverTLSConf = &tls.Config{
Certificates: []tls.Certificate{serverCert},
ClientCAs: caCertPool,
RootCAs: caCertPool,
ClientAuth: tls.RequireAndVerifyClientCert,
ClientCAs: caCertPool,
RootCAs: caCertPool,
ClientAuth: tls.RequireAndVerifyClientCert,
}

// create client certificate
Expand Down Expand Up @@ -268,7 +268,7 @@ func certsetup(config *types.Configuration) (serverTLSConf *tls.Config, err erro
})

// save client cert and key to client.crt and client.key
err = ioutil.WriteFile(config.MutualTlsFilesPath + "/client.crt", clientCertPEM.Bytes(), 0644)
err = ioutil.WriteFile(config.MutualTLSFilesPath+"/client.crt", clientCertPEM.Bytes(), 0644)
if err != nil {
return nil, err
}
Expand All @@ -277,7 +277,7 @@ func certsetup(config *types.Configuration) (serverTLSConf *tls.Config, err erro
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(clientCertPrivKey),
})
err = ioutil.WriteFile(config.MutualTlsFilesPath + "/client.key", clientCertPrivKeyPEM.Bytes(), 0644)
err = ioutil.WriteFile(config.MutualTLSFilesPath+"/client.key", clientCertPrivKeyPEM.Bytes(), 0644)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type FalcoPayload struct {
// Configuration is a struct to store configuration
type Configuration struct {
CheckCert bool
MutualTlsFilesPath string
MutualTLSFilesPath string
Debug bool
ListenAddress string
ListenPort int
Expand Down Expand Up @@ -115,7 +115,7 @@ type DiscordOutputConfig struct {
type alertmanagerOutputConfig struct {
HostPort string
MinimumPriority string
MutualTls bool
MutualTLS bool
}

type elasticsearchOutputConfig struct {
Expand All @@ -124,7 +124,7 @@ type elasticsearchOutputConfig struct {
Type string
MinimumPriority string
Suffix string
MutualTls bool
MutualTLS bool
}

type influxdbOutputConfig struct {
Expand All @@ -133,7 +133,7 @@ type influxdbOutputConfig struct {
User string
Password string
MinimumPriority string
MutualTls bool
MutualTLS bool
}

type lokiOutputConfig struct {
Expand All @@ -144,7 +144,7 @@ type lokiOutputConfig struct {
type natsOutputConfig struct {
HostPort string
MinimumPriority string
MutualTls bool
MutualTLS bool
}

type stanOutputConfig struct {
Expand Down Expand Up @@ -216,7 +216,7 @@ type WebhookOutputConfig struct {
Address string
CustomHeaders map[string]string
MinimumPriority string
MutualTls bool
MutualTLS bool
}

// CloudEventsOutputConfig represents parameters for CloudEvents
Expand Down

0 comments on commit 1e714aa

Please sign in to comment.