mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-07 13:44:17 +08:00
block tag deletion if used by a acl policy
This commit is contained in:
parent
ea7c1507f1
commit
8a948187bb
2 changed files with 24 additions and 0 deletions
|
@ -216,6 +216,11 @@ func deleteTag(w http.ResponseWriter, r *http.Request) {
|
|||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
||||
return
|
||||
}
|
||||
// check if active policy is using the tag
|
||||
if logic.CheckIfTagAsActivePolicy(tag.ID, tag.Network) {
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(errors.New("tag is currently in use by an active policy"), "badrequest"))
|
||||
return
|
||||
}
|
||||
err = logic.DeleteTag(models.TagID(tagID), true)
|
||||
if err != nil {
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
||||
|
|
|
@ -621,6 +621,25 @@ func UpdateDeviceTag(OldID, newID models.TagID, netID models.NetworkID) {
|
|||
}
|
||||
}
|
||||
|
||||
func CheckIfTagAsActivePolicy(tagID models.TagID, netID models.NetworkID) bool {
|
||||
acls := listDevicePolicies(netID)
|
||||
for _, acl := range acls {
|
||||
for _, srcTagI := range acl.Src {
|
||||
if srcTagI.ID == models.DeviceAclID {
|
||||
if tagID.String() == srcTagI.Value {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, dstTagI := range acl.Dst {
|
||||
if dstTagI.ID == models.DeviceAclID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// RemoveDeviceTagFromAclPolicies - remove device tag from acl policies
|
||||
func RemoveDeviceTagFromAclPolicies(tagID models.TagID, netID models.NetworkID) error {
|
||||
acls := listDevicePolicies(netID)
|
||||
|
|
Loading…
Add table
Reference in a new issue