Skip to content

Commit

Permalink
fix: fix max lenght file secret issue
Browse files Browse the repository at this point in the history
  • Loading branch information
gitahernandez committed Feb 28, 2024
1 parent f76de38 commit 41c649a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ The library supports retrieval of secrets from BeyondInsight/Password Safe versi
- type: int
- default: 2 minutes
- required: False
- maxFileSecretSize
- description: Max file secret size
- type: int
- required: True

## Methods

Expand Down Expand Up @@ -141,7 +145,7 @@ In order to use Release Please App, we need to use conventional commits, but [he
Some of the more important and common commit types are:

| Type | Description | Triggers Release Please |
|:---------|:--------------------------------------------------------------|:-------------------------|
| :------- | :------------------------------------------------------------ | :---------------------- |
| feat! | Introduce a major change e.g. v1.0.0 to v2.0.0 | Yes |
| feat | Introduce a minor change e.g. v1.0.0 to v1.1.0 | Yes |
| fix | Introduce a patch change e.g. v1.0.0 to v1.0.1 | Yes |
Expand Down
5 changes: 3 additions & 2 deletions TestClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ func main() {
clientTimeOutInSeconds := 30
verifyCa := true
retryMaxElapsedTimeMinutes := 2
maxFileSecretSize := 4000

// validate inputs
errorsInInputs := utils.ValidateInputs(clientId, clientSecret, apiUrl, clientTimeOutInSeconds, &separator, verifyCa, zapLogger, certificate, certificateKey, &retryMaxElapsedTimeMinutes)
errorsInInputs := utils.ValidateInputs(clientId, clientSecret, apiUrl, clientTimeOutInSeconds, &separator, verifyCa, zapLogger, certificate, certificateKey, &retryMaxElapsedTimeMinutes, maxFileSecretSize)

if errorsInInputs != nil {
return
Expand All @@ -52,7 +53,7 @@ func main() {
}

// instantiating secret obj
secretObj, _ := secrets.NewSecretObj(*authenticate, zapLogger, 4000)
secretObj, _ := secrets.NewSecretObj(*authenticate, zapLogger, maxFileSecretSize)

paths := "fake/text1,fake/text2"
errors_in_path := utils.ValidatePath(paths)
Expand Down
2 changes: 1 addition & 1 deletion api/secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (secretObj *SecretObj) GetSecretFlow(secretsToRetrieve []string, separator
secretInBytes := []byte(fileSecretContent)

if len(secretInBytes) > secretObj.maxFileSecretSize {
secretObj.log.Debug(fmt.Sprintf("%v%v%v: %v %v %v", secretPath, separator, secretTitle, "Secret Size:", len(secretInBytes), "is greater than allowed one", secretObj.maxFileSecretSize))
secretObj.log.Error(fmt.Sprintf("%v%v%v: %v %v %v", secretPath, separator, secretTitle, "Secret file Size:", len(secretInBytes), "is greater than the maximum allowed size:", secretObj.maxFileSecretSize))
} else {
secretDictionary[secretToRetrieve] = fileSecretContent
}
Expand Down
4 changes: 3 additions & 1 deletion api/utils/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ type UserInputValidaton struct {
ClientTimeOutinSeconds int `validate:"gte=1,lte=300"`
Separator string `validate:"required,min=1,max=1"`
VerifyCa bool `validate:"required"`
MaxFileSecretSize int `validate:"gte=1,lte=5000"`
}

var validate *validator.Validate

// ValidateInputs is responsible for validating end-user inputs.
func ValidateInputs(clientId string, clientSecret string, apiUrl string, clientTimeOutinSeconds int, separator *string, verifyCa bool, logger logging.Logger, certificate string, certificate_key string, retryMaxElapsedTimeMinutes *int) error {
func ValidateInputs(clientId string, clientSecret string, apiUrl string, clientTimeOutinSeconds int, separator *string, verifyCa bool, logger logging.Logger, certificate string, certificate_key string, retryMaxElapsedTimeMinutes *int, maxFileSecretSize int) error {

if clientTimeOutinSeconds == 0 {
clientTimeOutinSeconds = 30
Expand All @@ -45,6 +46,7 @@ func ValidateInputs(clientId string, clientSecret string, apiUrl string, clientT
ClientTimeOutinSeconds: clientTimeOutinSeconds,
Separator: *separator,
VerifyCa: verifyCa,
MaxFileSecretSize: maxFileSecretSize,
}

if strings.TrimSpace(*separator) == "" {
Expand Down

0 comments on commit 41c649a

Please sign in to comment.