Only allow saving Blueprints with unique names (#382)

Fixes #380.
This commit is contained in:
Jesse Peterson
2018-05-02 12:36:48 -07:00
committed by GitHub
parent 27786e12a1
commit 0f0df96176

View File

@@ -81,11 +81,18 @@ func (db *DB) Save(bp *blueprint.Blueprint) error {
if err != nil {
return err
}
check_bp, err := db.BlueprintByName(bp.Name)
if err != nil && !isNotFound(err) {
return err
}
if err == nil && bp.UUID != check_bp.UUID {
return fmt.Errorf("Blueprint not saved: same name %s exists", bp.Name)
}
// verify that each Profile ID represents a profile we know about
for _, p := range bp.ProfileIdentifiers {
if _, err := db.profDB.ProfileById(p); err != nil {
if profile.IsNotFound(err) {
return errors.New(fmt.Sprintf("Profile ID %s in Blueprint %s does not exist", p, bp.Name))
return fmt.Errorf("Profile ID %s in Blueprint %s does not exist", p, bp.Name)
}
return errors.Wrap(err, "fetching profile")
}