From 0f0df96176e77340a04de8cc7741fb2bcbb36948 Mon Sep 17 00:00:00 2001 From: Jesse Peterson Date: Wed, 2 May 2018 12:36:48 -0700 Subject: [PATCH] Only allow saving Blueprints with unique names (#382) Fixes #380. --- platform/blueprint/builtin/db.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/platform/blueprint/builtin/db.go b/platform/blueprint/builtin/db.go index 885bf0a2..2451eacf 100644 --- a/platform/blueprint/builtin/db.go +++ b/platform/blueprint/builtin/db.go @@ -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") }