Skip to content

Commit

Permalink
Chore: Warn: Update connection with database and broker to show messa…
Browse files Browse the repository at this point in the history
…ge of warn for default usr and pwd (#93)

Signed-off-by: wiliansilvazup wilian.silva@zup.com.br
wiliansilvazup authored Sep 20, 2021
1 parent 48280ce commit 9e9778c
Showing 9 changed files with 43 additions and 241 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
This CODEOWNERS file contains errors

CODEOWNERS errors

  • Unknown owner on line 3: make sure @wiliansilvazup exists and has write access to the repository
    * @wiliansilvazup @lucasbrunozup @nathanmartinszup @iancardosozup @matheusalcantarazup
  • Unknown owner on line 3: make sure @lucasbrunozup exists and has write access to the repository
    * @wiliansilvazup @lucasbrunozup @nathanmartinszup @iancardosozup @matheusalcantarazup
  • Unknown owner on line 3: make sure @nathanmartinszup exists and has write access to the repository
    …wiliansilvazup @lucasbrunozup @nathanmartinszup @iancardosozup @matheusalcantarazup
  • Unknown owner on line 3: make sure @iancardosozup exists and has write access to the repository
    …casbrunozup @nathanmartinszup @iancardosozup @matheusalcantarazup
  • Unknown owner on line 3: make sure @matheusalcantarazup exists and has write access to the repository
    …thanmartinszup @iancardosozup @matheusalcantarazup
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GitHub code owners
# See https://github.com/blog/2392-introducing-code-owners
* @wiliansilvazup @nathannascimentozup @lucasbrunozup @nathanmartinszup @tiagoangelozup @lucasgarciazup
* @wiliansilvazup @lucasbrunozup @nathanmartinszup @iancardosozup @matheusalcantarazup

10 changes: 4 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ require (
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/protobuf v1.5.2
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/uuid v1.3.0
github.com/gopherjs/gopherjs v0.0.0-20210420193930-a4630ec28c79 // indirect
github.com/iancoleman/strcase v0.2.0
@@ -27,20 +28,17 @@ require (
github.com/prometheus/procfs v0.7.3 // indirect
github.com/sirupsen/logrus v1.8.1
github.com/smartystreets/assertions v1.2.0 // indirect
github.com/smartystreets/goconvey v1.6.4
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.9.0
github.com/streadway/amqp v1.0.0
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/swaggo/http-swagger v1.1.1
golang.org/x/crypto v0.0.0-20210920023735-84f357641f63
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
google.golang.org/genproto v0.0.0-20210713002101-d411969a0d9a // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71 // indirect
google.golang.org/grpc v1.40.0
google.golang.org/protobuf v1.27.1
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gorm.io/driver/postgres v1.1.0
gorm.io/gorm v1.21.11
)
222 changes: 1 addition & 221 deletions go.sum

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions pkg/services/broker/config/config.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@ package config
import (
"fmt"

"github.com/ZupIT/horusec-devkit/pkg/utils/logger"

validation "github.com/go-ozzo/ozzo-validation/v4"

"github.com/ZupIT/horusec-devkit/pkg/services/broker/enums"
@@ -47,8 +49,8 @@ func NewBrokerConfig() IConfig {
config := &Config{}
config.SetHost(env.GetEnvOrDefault(enums.EnvBrokerHost, "127.0.0.1"))
config.SetPort(env.GetEnvOrDefault(enums.EnvBrokerPort, "5672"))
config.SetUsername(env.GetEnvOrDefault(enums.EnvBrokerUsername, "guest"))
config.SetPassword(env.GetEnvOrDefault(enums.EnvBrokerPassword, "guest"))
config.SetUsername(env.GetEnvOrDefault(enums.EnvBrokerUsername, enums.DefaultUsername))
config.SetPassword(env.GetEnvOrDefault(enums.EnvBrokerPassword, enums.DefaultPassword))

return config
}
@@ -81,6 +83,9 @@ func (c *Config) SetPort(port string) {
}

func (c *Config) GetUsername() string {
if c.username == enums.DefaultUsername {
logger.LogWarn(enums.MessageWarningDefaultBrokerConnection)
}
return c.username
}

@@ -89,6 +94,9 @@ func (c *Config) SetUsername(username string) {
}

func (c *Config) GetPassword() string {
if c.password == enums.DefaultUsername {
logger.LogWarn(enums.MessageWarningDefaultBrokerConnection)
}
return c.password
}

20 changes: 11 additions & 9 deletions pkg/services/broker/enums/messages.go
Original file line number Diff line number Diff line change
@@ -15,13 +15,15 @@
package enums

const (
MessageFailedConnectBroker = "{ERROR_BROKER} failed to connect"
MessageFailedCreateChannelPublish = "{ERROR_BROKER} failed to create channel while publishing"
MessageFailedDeclareExchangePublish = "{ERROR_BROKER} failed to declare exchange while publishing"
MessageFailedCreateChannelConsume = "{ERROR_BROKER} failed to create channel in consume"
MessageFailedCreateQueueConsume = "{ERROR_BROKER} error declaring queue in consumer"
MessageFailedConsumeHandlingDelivery = "{ERROR_BROKER} consume error while handling deliveries"
MessageFailedSetConsumerPrefetch = "{ERROR_BROKER} failed to set consumer prefetch"
MessageFailedToDeclareExchangeQueue = "{ERROR_BROKER} failed to declare exchange while declaring queue"
MessageFailedBindQueueConsume = "{ERROR_BROKER} failed to queue bind in consume"
MessageFailedConnectBroker = "{ERROR_BROKER} failed to connect"
MessageFailedCreateChannelPublish = "{ERROR_BROKER} failed to create channel while publishing"
MessageFailedDeclareExchangePublish = "{ERROR_BROKER} failed to declare exchange while publishing"
MessageFailedCreateChannelConsume = "{ERROR_BROKER} failed to create channel in consume"
MessageFailedCreateQueueConsume = "{ERROR_BROKER} error declaring queue in consumer"
MessageFailedConsumeHandlingDelivery = "{ERROR_BROKER} consume error while handling deliveries"
MessageFailedSetConsumerPrefetch = "{ERROR_BROKER} failed to set consumer prefetch"
MessageFailedToDeclareExchangeQueue = "{ERROR_BROKER} failed to declare exchange while declaring queue"
MessageFailedBindQueueConsume = "{ERROR_BROKER} failed to queue bind in consume"
MessageWarningDefaultBrokerConnection = "{WARN} your user or password for connection with message broker " +
"is default content, please change for you best security"
)
3 changes: 3 additions & 0 deletions pkg/services/broker/enums/values.go
Original file line number Diff line number Diff line change
@@ -19,4 +19,7 @@ const (
EnvBrokerPort = "HORUSEC_BROKER_PORT"
EnvBrokerUsername = "HORUSEC_BROKER_USERNAME"
EnvBrokerPassword = "HORUSEC_BROKER_PASSWORD" //nolint:gosec // false positive

DefaultUsername = "guest"
DefaultPassword = "guest"
)
7 changes: 7 additions & 0 deletions pkg/services/database/config/config.go
Original file line number Diff line number Diff line change
@@ -15,8 +15,12 @@
package config

import (
"strings"

validation "github.com/go-ozzo/ozzo-validation/v4"

"github.com/ZupIT/horusec-devkit/pkg/utils/logger"

"github.com/ZupIT/horusec-devkit/pkg/services/database/enums"
"github.com/ZupIT/horusec-devkit/pkg/utils/env"
)
@@ -48,6 +52,9 @@ func (c *Config) SetURI(uri string) {
}

func (c *Config) GetURI() string {
if strings.Contains(c.uri, enums.DefaultUsernameAndPassword) {
logger.LogWarn(enums.MessageWarningDefaultDatabaseConnection)
}
return c.uri
}

6 changes: 4 additions & 2 deletions pkg/services/database/enums/messages.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@
package enums

const (
MessageFailedToConnectToDatabase = "{ERROR_DATABASE} failed to connect with postgres database"
MessageFailedToVerifyIsAvailable = "{ERROR_DATABASE} failed to get database while checking if is available"
MessageFailedToConnectToDatabase = "{ERROR_DATABASE} failed to connect with postgres database"
MessageFailedToVerifyIsAvailable = "{ERROR_DATABASE} failed to get database while checking if is available"
MessageWarningDefaultDatabaseConnection = "{WARN} your user or password for connection with database " +
"is default content, please change for you best security"
)
2 changes: 2 additions & 0 deletions pkg/services/database/enums/values.go
Original file line number Diff line number Diff line change
@@ -17,4 +17,6 @@ package enums
const (
EnvRelationalURI = "HORUSEC_DATABASE_SQL_URI"
EnvRelationalLogMode = "HORUSEC_DATABASE_SQL_LOG_MODE"

DefaultUsernameAndPassword = "root:root"
)

0 comments on commit 9e9778c

Please sign in to comment.