Skip to content

Commit

Permalink
schema version validation changes:
Browse files Browse the repository at this point in the history
* schema version validation error response code changed from 500 to 400
* optional bugfix version allowed

Signed-off-by: Michael Valdron <[email protected]>
  • Loading branch information
michael-valdron committed Jun 14, 2023
1 parent 200b4f0 commit 9e8694b
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions index/server/pkg/server/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,21 +428,21 @@ func buildIndexAPIResponse(c *gin.Context, wantV1Index bool) {
maxSchemaVersion := c.Query("maxSchemaVersion")
if maxSchemaVersion != "" || minSchemaVersion != "" {
// check if schema version filters are in valid format.
// should only include major and minor version. e.g. 2.1
// should include major and minor versions as well as an optional bugfix version. e.g. 2.1 or 2.1.0
if minSchemaVersion != "" {
matched, err := regexp.MatchString(`^([2-9])\.([0-9]+)$`, minSchemaVersion)
matched, err := regexp.MatchString(`^([2-9])\.([0-9]+)(\.[0-9]+)?$`, minSchemaVersion)
if !matched || err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"status": fmt.Sprintf("minSchemaVersion %s is not valid, should only include major and minor version. %v", minSchemaVersion, err),
c.JSON(http.StatusBadRequest, gin.H{
"status": fmt.Sprintf("minSchemaVersion %s is not valid, version format should be '[major].[minor]' or '[major].[minor].[bugfix]'. %v", minSchemaVersion, err),
})
return
}
}
if maxSchemaVersion != "" {
matched, err := regexp.MatchString(`^([2-9])\.([0-9]+)$`, maxSchemaVersion)
matched, err := regexp.MatchString(`^([2-9])\.([0-9]+)(\.[0-9]+)?$`, maxSchemaVersion)
if !matched || err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"status": fmt.Sprintf("maxSchemaVersion %s is not valid, should only include major and minor version. %v", maxSchemaVersion, err),
c.JSON(http.StatusBadRequest, gin.H{
"status": fmt.Sprintf("maxSchemaVersion %s is not valid, version format should be '[major].[minor]' or '[major].[minor].[bugfix]'. %v", maxSchemaVersion, err),
})
return
}
Expand Down Expand Up @@ -538,21 +538,21 @@ func fetchDevfile(c *gin.Context, name string, version string) ([]byte, indexSch
minSchemaVersion := c.Query("minSchemaVersion")
maxSchemaVersion := c.Query("maxSchemaVersion")
// check if schema version filters are in valid format.
// should only include major and minor version. e.g. 2.1
// should include major and minor versions as well as an optional bugfix version. e.g. 2.1 or 2.1.0
if minSchemaVersion != "" {
matched, err := regexp.MatchString(`^([2-9])\.([0-9]+)$`, minSchemaVersion)
matched, err := regexp.MatchString(`^([2-9])\.([0-9]+)(\.[0-9]+)?$`, minSchemaVersion)
if !matched || err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"status": fmt.Sprintf("minSchemaVersion %s is not valid, should only include major and minor version. %v", minSchemaVersion, err),
c.JSON(http.StatusBadRequest, gin.H{
"status": fmt.Sprintf("minSchemaVersion %s is not valid, version format should be '[major].[minor]' or '[major].[minor].[bugfix]'. %v", minSchemaVersion, err),
})
return []byte{}, indexSchema.Schema{}
}
}
if maxSchemaVersion != "" {
matched, err := regexp.MatchString(`^([2-9])\.([0-9]+)$`, maxSchemaVersion)
matched, err := regexp.MatchString(`^([2-9])\.([0-9]+)(\.[0-9]+)?$`, maxSchemaVersion)
if !matched || err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"status": fmt.Sprintf("maxSchemaVersion %s is not valid, should only include major and minor version. %v", maxSchemaVersion, err),
c.JSON(http.StatusBadRequest, gin.H{
"status": fmt.Sprintf("maxSchemaVersion %s is not valid, version format should be '[major].[minor]' or '[major].[minor].[bugfix]'. %v", maxSchemaVersion, err),
})
return []byte{}, indexSchema.Schema{}
}
Expand Down

0 comments on commit 9e8694b

Please sign in to comment.