forked from noobaa/noobaa-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed regexp to compile once and removed complexity term
Signed-off-by: Aayush Chouhan <[email protected]>
- Loading branch information
1 parent
db9b6c1
commit 2b78cec
Showing
2 changed files
with
9 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ package noobaaaccount | |
import ( | ||
"context" | ||
"fmt" | ||
"regexp" | ||
"time" | ||
|
||
nbv1 "github.com/noobaa/noobaa-operator/v5/pkg/apis/noobaa/v1alpha1" | ||
|
@@ -418,7 +417,7 @@ func RunCredentials(cmd *cobra.Command, args []string) { | |
log.Fatalf(`❌ access_key and secret_key flags must be provided`) | ||
} | ||
|
||
// validating access_keys complexity | ||
// validating access_keys | ||
ValidateAccessKeys(accessKeys) | ||
|
||
if !util.KubeCheck(noobaaAccount) && (name != "[email protected]") { | ||
|
@@ -862,19 +861,17 @@ func UpdateNonCrdAccountKeys(name string, accessKeys nb.S3AccessKeys) error { | |
return nil | ||
} | ||
|
||
// ValidateAccessKeys checks for complexity of credentials(access_key and secret_key) | ||
// ValidateAccessKeys checks validity of credentials (access_key and secret_key) | ||
func ValidateAccessKeys(accessKeys nb.S3AccessKeys) { | ||
log := util.Logger() | ||
|
||
// Checking complexity for access_key | ||
regex := regexp.MustCompile(util.AccessKeyRegexp) | ||
if !regex.MatchString(accessKeys.AccessKey) { | ||
// validations for access_key | ||
if !util.AccessKeyRegexp.MatchString(accessKeys.AccessKey) { | ||
log.Fatalf(`❌ Account access key length must be 20, and must contain only alpha-numeric chars`) | ||
} | ||
|
||
// Checking complexity for secret_key | ||
regex = regexp.MustCompile(util.SecretKeyRegexp) | ||
if !regex.MatchString(accessKeys.SecretKey) { | ||
// validations for secret_key | ||
if !util.SecretKeyRegexp.MatchString(accessKeys.SecretKey) { | ||
log.Fatalf(`❌ Account secret length must be 40, and must contain only alpha-numeric chars, "+", "/"`) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters