From ca3a306b30313221671cd537a69988d478bbc3bc Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 8 Feb 2020 22:15:37 -0500 Subject: [PATCH] feat: ensure networks do not conflict --- plugins/network/subcommands.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/plugins/network/subcommands.go b/plugins/network/subcommands.go index d0ad8c270..3bbe6952b 100644 --- a/plugins/network/subcommands.go +++ b/plugins/network/subcommands.go @@ -174,9 +174,31 @@ func CommandSet(appName string, property string, value string) { "host": true, "bridge": true, } - if attachProperites[property] && invalidNetworks[value] { - common.LogFail("Invalid network name specified for attach") + if attachProperites[property] { + if invalidNetworks[value] { + common.LogFail("Invalid network name specified for attach") + } + + if isConflictingPropertyValue(property, value) { + common.LogFail("Network name already associated with this app") + } } common.CommandPropertySet("network", appName, property, value, DefaultProperties) } + +func isConflictingPropertyValue(property string, value string) bool { + if value == "" { + return false + } + + otherProperty := "attach-post-create" + if property == otherProperty { + otherProperty = "attach-post-deploy" + } + + defaultValue := GetDefaultValue(otherProperty) + otherValue := common.PropertyGetDefault("network", appName, otherProperty, defaultValue) + + return value == otherValue +}