-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
per package validations
- Loading branch information
Showing
8 changed files
with
229 additions
and
205 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package catalog | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/treeverse/lakefs/pkg/validator" | ||
) | ||
|
||
const ( | ||
MaxPathLength = 1024 | ||
) | ||
|
||
func ValidatePath(v interface{}) error { | ||
s, ok := v.(Path) | ||
if !ok { | ||
panic(ErrInvalidType) | ||
} | ||
|
||
l := len(s) | ||
if l == 0 { | ||
return ErrPathRequiredValue | ||
} | ||
if l > MaxPathLength { | ||
return fmt.Errorf("%w: %d is above maximum length (%d)", ErrInvalidValue, l, MaxPathLength) | ||
} | ||
return nil | ||
} | ||
|
||
var ValidatePathOptional = validator.MakeValidateOptional(ValidatePath) |
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
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 |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package graveler | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/treeverse/lakefs/pkg/ident" | ||
"github.com/treeverse/lakefs/pkg/validator" | ||
) | ||
|
||
func ValidateStorageNamespace(v interface{}) error { | ||
s, ok := v.(StorageNamespace) | ||
if !ok { | ||
panic(ErrInvalidType) | ||
} | ||
|
||
if len(s) == 0 { | ||
return ErrRequiredValue | ||
} | ||
return nil | ||
} | ||
|
||
func ValidateRef(v interface{}) error { | ||
s, ok := v.(Ref) | ||
if !ok { | ||
panic(ErrInvalidType) | ||
} | ||
if len(s) == 0 { | ||
return ErrRequiredValue | ||
} | ||
if !validator.ReValidRef.MatchString(s.String()) { | ||
return ErrInvalidRef | ||
} | ||
return nil | ||
} | ||
|
||
func ValidateBranchID(v interface{}) error { | ||
s, ok := v.(BranchID) | ||
if !ok { | ||
panic(ErrInvalidType) | ||
} | ||
if len(s) == 0 { | ||
return ErrRequiredValue | ||
} | ||
if !validator.ReValidBranchID.MatchString(s.String()) { | ||
return ErrInvalidBranchID | ||
} | ||
return nil | ||
} | ||
|
||
func ValidateTagID(v interface{}) error { | ||
s, ok := v.(TagID) | ||
if !ok { | ||
panic(ErrInvalidType) | ||
} | ||
|
||
// https://git-scm.com/docs/git-check-ref-format | ||
if len(s) == 0 { | ||
return ErrRequiredValue | ||
} | ||
|
||
tagID := s.String() | ||
if tagID == "@" { | ||
return ErrInvalidTagID | ||
} | ||
if strings.HasSuffix(tagID, ".") || strings.HasSuffix(tagID, ".lock") || strings.HasSuffix(tagID, "/") { | ||
return ErrInvalidTagID | ||
} | ||
if strings.Contains(tagID, "..") || strings.Contains(tagID, "//") || strings.Contains(tagID, "@{") { | ||
return ErrInvalidTagID | ||
} | ||
// Unlike git, we do allow '~'. That supports migration from our previous ref format where commits started with a tilde. | ||
if strings.ContainsAny(tagID, "^:?*[\\") { | ||
return ErrInvalidTagID | ||
} | ||
for _, r := range tagID { | ||
if isControlCodeOrSpace(r) { | ||
return ErrInvalidTagID | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func isControlCodeOrSpace(r rune) bool { | ||
const space = 0x20 | ||
return r <= space | ||
} | ||
|
||
func ValidateCommitID(v interface{}) error { | ||
s, ok := v.(CommitID) | ||
if !ok { | ||
panic(ErrInvalidType) | ||
} | ||
|
||
if len(s) == 0 { | ||
return ErrRequiredValue | ||
} | ||
if !ident.IsContentAddress(s.String()) { | ||
return ErrInvalidCommitID | ||
} | ||
return nil | ||
} | ||
|
||
func ValidateRepositoryID(v interface{}) error { | ||
s, ok := v.(RepositoryID) | ||
if !ok { | ||
panic(ErrInvalidType) | ||
} | ||
|
||
if len(s) == 0 { | ||
return ErrRequiredValue | ||
} | ||
if !validator.ReValidRepositoryID.MatchString(s.String()) { | ||
return ErrInvalidRepositoryID | ||
} | ||
return nil | ||
} | ||
|
||
var ValidateTagIDOptional = validator.MakeValidateOptional(ValidateTagID) |
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
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