Skip to content

Commit

Permalink
fix: max length file secret
Browse files Browse the repository at this point in the history
  • Loading branch information
thejurysays committed Feb 29, 2024
1 parent a9f61d3 commit 8df5a30
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ The library supports retrieval of secrets from BeyondInsight/Password Safe versi
- type: int
- default: 2 minutes
- required: False
- maxFileSecretSize
- description: Max file size allows the user of the library to set a limit on the file size that the library will work with. Range 1-5000000 Bytes.
- maxFileSecretSizeBytes
- description: Max file size allows the user of the library to set a limit on the file size. If max size is exceeded an error is logged and the secret is ignored. Range 1-5000000 Bytes.
- type: int
- default: 4000
- required: false
Expand Down
6 changes: 3 additions & 3 deletions TestClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func main() {
clientTimeOutInSeconds := 30
verifyCa := true
retryMaxElapsedTimeMinutes := 2
maxFileSecretSize := 4000
maxFileSecretSizeBytes := 4000

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

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

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

secretPaths := []string{"fake/Client", "fake/test_file_1"}

Expand Down
18 changes: 9 additions & 9 deletions api/secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ import (

// SecretObj responsible for session requests.
type SecretObj struct {
log logging.Logger
authenticationObj authentication.AuthenticationObj
maxFileSecretSize int
log logging.Logger
authenticationObj authentication.AuthenticationObj
maxFileSecretSizeBytes int
}

// NewSecretObj creates secret obj
func NewSecretObj(authentication authentication.AuthenticationObj, logger logging.Logger, maxFileSecretSize int) (*SecretObj, error) {
func NewSecretObj(authentication authentication.AuthenticationObj, logger logging.Logger, maxFileSecretSizeBytes int) (*SecretObj, error) {
secretObj := &SecretObj{
log: logger,
authenticationObj: authentication,
maxFileSecretSize: maxFileSecretSize,
log: logger,
authenticationObj: authentication,
maxFileSecretSizeBytes: maxFileSecretSizeBytes,
}
return secretObj, nil
}
Expand Down Expand Up @@ -80,8 +80,8 @@ func (secretObj *SecretObj) GetSecretFlow(secretsToRetrieve []string, separator

secretInBytes := []byte(fileSecretContent)

if len(secretInBytes) > secretObj.maxFileSecretSize {
secretObj.log.Error(fmt.Sprintf("%v%v%v: %v %v %v %v", secretPath, separator, secretTitle, "Secret file Size:", len(secretInBytes), "is greater than the maximum allowed size:", secretObj.maxFileSecretSize))
if len(secretInBytes) > secretObj.maxFileSecretSizeBytes {
secretObj.log.Error(fmt.Sprintf("%v%v%v: %v %v %v %v", secretPath, separator, secretTitle, "Secret file Size:", len(secretInBytes), "is greater than the maximum allowed size:", secretObj.maxFileSecretSizeBytes))
} else {
secretDictionary[secretToRetrieve] = fileSecretContent
}
Expand Down
10 changes: 5 additions & 5 deletions api/utils/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,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"`
MaxFileSecretSizeBytes 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, maxFileSecretSize *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, maxFileSecretSizeBytes *int) error {

if clientTimeOutinSeconds == 0 {
clientTimeOutinSeconds = 30
Expand All @@ -39,8 +39,8 @@ func ValidateInputs(clientId string, clientSecret string, apiUrl string, clientT
*retryMaxElapsedTimeMinutes = 2
}

if *maxFileSecretSize == 0 {
*maxFileSecretSize = 4000
if *maxFileSecretSizeBytes == 0 {
*maxFileSecretSizeBytes = 4000
}

validate = validator.New(validator.WithRequiredStructEnabled())
Expand All @@ -52,7 +52,7 @@ func ValidateInputs(clientId string, clientSecret string, apiUrl string, clientT
ClientTimeOutinSeconds: clientTimeOutinSeconds,
Separator: *separator,
VerifyCa: verifyCa,
MaxFileSecretSize: *maxFileSecretSize,
MaxFileSecretSizeBytes: *maxFileSecretSizeBytes,
}

if !verifyCa {
Expand Down

0 comments on commit 8df5a30

Please sign in to comment.