Skip to content

Commit

Permalink
Only check ns exists when create
Browse files Browse the repository at this point in the history
  • Loading branch information
haoming29 committed Jan 8, 2024
1 parent 9965d30 commit 14d7262
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions registry/registry_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,18 @@ func createUpdateNamespace(ctx *gin.Context, isUpdate bool) {
}
ns.Prefix = updated_prefix

// Check if prefix exists before doing anything else
exists, err := namespaceExists(ns.Prefix)
if err != nil {
log.Errorf("Failed to check if namespace already exists: %v", err)
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Server encountered an error checking if namespace already exists"})
return
}
if exists {
ctx.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("The prefix %s is already registered", ns.Prefix)})
return
if !isUpdate {
// Check if prefix exists before doing anything else. Skip check if it's update operation
exists, err := namespaceExists(ns.Prefix)
if err != nil {
log.Errorf("Failed to check if namespace already exists: %v", err)
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Server encountered an error checking if namespace already exists"})
return
}
if exists {
ctx.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("The prefix %s is already registered", ns.Prefix)})
return
}
}
// Check if pubKey is a valid JWK
pubkey, err := validateJwks(ns.Pubkey)
Expand Down

0 comments on commit 14d7262

Please sign in to comment.