mirror of https://github.com/grpc/grpc-go.git
xds/bootstrap: Use correct format for "certificate_providers" field. (#3922)
This commit is contained in:
parent
8fbea72764
commit
d5280589eb
|
|
@ -118,8 +118,14 @@ type xdsServer struct {
|
||||||
// ],
|
// ],
|
||||||
// "server_features": [ ... ]
|
// "server_features": [ ... ]
|
||||||
// "certificate_providers" : {
|
// "certificate_providers" : {
|
||||||
// "default": { default cert provider config },
|
// "default": {
|
||||||
// "foo": { config for provider foo }
|
// "plugin_name": "default-plugin-name",
|
||||||
|
// "config": { default plugin config in JSON }
|
||||||
|
// },
|
||||||
|
// "foo": {
|
||||||
|
// "plugin_name": "foo",
|
||||||
|
// "config": { foo plugin config in JSON }
|
||||||
|
// }
|
||||||
// }
|
// }
|
||||||
// },
|
// },
|
||||||
// "node": <JSON form of Node proto>
|
// "node": <JSON form of Node proto>
|
||||||
|
|
@ -208,16 +214,21 @@ func NewConfig() (*Config, error) {
|
||||||
configs := make(map[string]CertProviderConfig)
|
configs := make(map[string]CertProviderConfig)
|
||||||
getBuilder := internal.GetCertificateProviderBuilder.(func(string) certprovider.Builder)
|
getBuilder := internal.GetCertificateProviderBuilder.(func(string) certprovider.Builder)
|
||||||
for instance, data := range providerInstances {
|
for instance, data := range providerInstances {
|
||||||
var providerConfigs map[string]json.RawMessage
|
var nameAndConfig struct {
|
||||||
if err := json.Unmarshal(data, &providerConfigs); err != nil {
|
PluginName string `json:"plugin_name"`
|
||||||
|
Config json.RawMessage `json:"config"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(data, &nameAndConfig); err != nil {
|
||||||
return nil, fmt.Errorf("xds: json.Unmarshal(%v) for field %q failed during bootstrap: %v", string(v), instance, err)
|
return nil, fmt.Errorf("xds: json.Unmarshal(%v) for field %q failed during bootstrap: %v", string(v), instance, err)
|
||||||
}
|
}
|
||||||
for name, cfg := range providerConfigs {
|
|
||||||
parser := getBuilder(name)
|
name := nameAndConfig.PluginName
|
||||||
|
parser := getBuilder(nameAndConfig.PluginName)
|
||||||
if parser == nil {
|
if parser == nil {
|
||||||
// We ignore plugins that we do not know about.
|
// We ignore plugins that we do not know about.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
cfg := nameAndConfig.Config
|
||||||
c, err := parser.ParseConfig(cfg)
|
c, err := parser.ParseConfig(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("xds: Config parsing for plugin %q failed: %v", name, err)
|
return nil, fmt.Errorf("xds: Config parsing for plugin %q failed: %v", name, err)
|
||||||
|
|
@ -227,7 +238,6 @@ func NewConfig() (*Config, error) {
|
||||||
Config: c,
|
Config: c,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
config.CertProviderConfigs = configs
|
config.CertProviderConfigs = configs
|
||||||
}
|
}
|
||||||
// Do not fail the xDS bootstrap when an unknown field is seen. This can
|
// Do not fail the xDS bootstrap when an unknown field is seen. This can
|
||||||
|
|
|
||||||
|
|
@ -564,10 +564,12 @@ func TestNewConfigWithCertificateProviders(t *testing.T) {
|
||||||
"server_features" : ["foo", "bar", "xds_v3"],
|
"server_features" : ["foo", "bar", "xds_v3"],
|
||||||
"certificate_providers": {
|
"certificate_providers": {
|
||||||
"unknownProviderInstance1": {
|
"unknownProviderInstance1": {
|
||||||
"foo1": "bar1"
|
"plugin_name": "foo",
|
||||||
|
"config": {"foo": "bar"}
|
||||||
},
|
},
|
||||||
"unknownProviderInstance2": {
|
"unknownProviderInstance2": {
|
||||||
"foo2": "bar2"
|
"plugin_name": "bar",
|
||||||
|
"config": {"foo": "bar"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
|
|
@ -588,17 +590,12 @@ func TestNewConfigWithCertificateProviders(t *testing.T) {
|
||||||
"server_features" : ["foo", "bar", "xds_v3"],
|
"server_features" : ["foo", "bar", "xds_v3"],
|
||||||
"certificate_providers": {
|
"certificate_providers": {
|
||||||
"unknownProviderInstance": {
|
"unknownProviderInstance": {
|
||||||
"foo": "bar"
|
"plugin_name": "foo",
|
||||||
},
|
"config": {"foo": "bar"}
|
||||||
"fakeProviderInstance": {
|
|
||||||
"fake-certificate-provider": {
|
|
||||||
"configKey": "configValue"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"fakeProviderInstanceBad": {
|
"fakeProviderInstanceBad": {
|
||||||
"fake-certificate-provider": {
|
"plugin_name": "fake-certificate-provider",
|
||||||
"configKey": 666
|
"config": {"configKey": 666}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
|
|
@ -619,12 +616,12 @@ func TestNewConfigWithCertificateProviders(t *testing.T) {
|
||||||
"server_features" : ["foo", "bar", "xds_v3"],
|
"server_features" : ["foo", "bar", "xds_v3"],
|
||||||
"certificate_providers": {
|
"certificate_providers": {
|
||||||
"unknownProviderInstance": {
|
"unknownProviderInstance": {
|
||||||
"foo": "bar"
|
"plugin_name": "foo",
|
||||||
|
"config": {"foo": "bar"}
|
||||||
},
|
},
|
||||||
"fakeProviderInstance": {
|
"fakeProviderInstance": {
|
||||||
"fake-certificate-provider": {
|
"plugin_name": "fake-certificate-provider",
|
||||||
"configKey": "configValue"
|
"config": {"configKey": "configValue"}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
|
|
@ -692,7 +689,7 @@ func TestNewConfigWithCertificateProviders(t *testing.T) {
|
||||||
}
|
}
|
||||||
c, err := NewConfig()
|
c, err := NewConfig()
|
||||||
if (err != nil) != test.wantErr {
|
if (err != nil) != test.wantErr {
|
||||||
t.Fatalf("NewConfig() returned: %v, wantErr: %v", err, test.wantErr)
|
t.Fatalf("NewConfig() returned: (%+v, %v), wantErr: %v", c.CertProviderConfigs, err, test.wantErr)
|
||||||
}
|
}
|
||||||
if test.wantErr {
|
if test.wantErr {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue