mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
In bridge, network config to be validated last
- Currently validation is run before the processing of well-known labels is completed. Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
parent
03dc873478
commit
e244043eb3
1 changed files with 38 additions and 22 deletions
|
@ -170,14 +170,14 @@ func (c *networkConfiguration) Conflict(o *networkConfiguration) bool {
|
||||||
|
|
||||||
// FromMap retrieve the configuration data from the map form.
|
// FromMap retrieve the configuration data from the map form.
|
||||||
func (c *networkConfiguration) FromMap(data map[string]interface{}) error {
|
func (c *networkConfiguration) FromMap(data map[string]interface{}) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
if i, ok := data["BridgeName"]; ok && i != nil {
|
if i, ok := data["BridgeName"]; ok && i != nil {
|
||||||
if c.BridgeName, ok = i.(string); !ok {
|
if c.BridgeName, ok = i.(string); !ok {
|
||||||
return types.BadRequestErrorf("invalid type for BridgeName value")
|
return types.BadRequestErrorf("invalid type for BridgeName value")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
|
||||||
|
|
||||||
if i, ok := data["Mtu"]; ok && i != nil {
|
if i, ok := data["Mtu"]; ok && i != nil {
|
||||||
if s, ok := i.(string); ok {
|
if s, ok := i.(string); ok {
|
||||||
if c.Mtu, err = strconv.Atoi(s); err != nil {
|
if c.Mtu, err = strconv.Atoi(s); err != nil {
|
||||||
|
@ -376,35 +376,51 @@ func (d *driver) getNetwork(id types.UUID) (*bridgeNetwork, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseNetworkOptions(option options.Generic) (*networkConfiguration, error) {
|
func parseNetworkGenericOptions(data interface{}) (*networkConfiguration, error) {
|
||||||
config := &networkConfiguration{}
|
var (
|
||||||
if genData, ok := option[netlabel.GenericData]; ok && genData != nil {
|
err error
|
||||||
switch opt := genData.(type) {
|
config *networkConfiguration
|
||||||
|
)
|
||||||
|
|
||||||
case map[string]interface{}:
|
switch opt := data.(type) {
|
||||||
if err := config.FromMap(opt); err != nil {
|
case *networkConfiguration:
|
||||||
return nil, err
|
config = opt
|
||||||
}
|
case map[string]interface{}:
|
||||||
case options.Generic:
|
config = &networkConfiguration{}
|
||||||
opaqueConfig, err := options.GenerateFromModel(opt, &networkConfiguration{})
|
err = config.FromMap(opt)
|
||||||
if err != nil {
|
case options.Generic:
|
||||||
return nil, err
|
var opaqueConfig interface{}
|
||||||
}
|
if opaqueConfig, err = options.GenerateFromModel(opt, config); err == nil {
|
||||||
config = opaqueConfig.(*networkConfiguration)
|
config = opaqueConfig.(*networkConfiguration)
|
||||||
case *networkConfiguration:
|
}
|
||||||
config = opt
|
default:
|
||||||
default:
|
err = types.BadRequestErrorf("do not recognize network configuration format: %T", opt)
|
||||||
return nil, types.BadRequestErrorf("do not recognize network configuration format: %T", opt)
|
}
|
||||||
|
|
||||||
|
return config, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseNetworkOptions(option options.Generic) (*networkConfiguration, error) {
|
||||||
|
var err error
|
||||||
|
config := &networkConfiguration{}
|
||||||
|
|
||||||
|
// Parse generic label first, config will be re-assigned
|
||||||
|
if genData, ok := option[netlabel.GenericData]; ok && genData != nil {
|
||||||
|
if config, err = parseNetworkGenericOptions(genData); err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := config.Validate(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Process well-known labels next
|
||||||
if _, ok := option[netlabel.EnableIPv6]; ok {
|
if _, ok := option[netlabel.EnableIPv6]; ok {
|
||||||
config.EnableIPv6 = option[netlabel.EnableIPv6].(bool)
|
config.EnableIPv6 = option[netlabel.EnableIPv6].(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finally validate the configuration
|
||||||
|
if err = config.Validate(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue