diff --git a/pkg/converter/tool/builder.go b/pkg/converter/tool/builder.go index 78f860029a..b3564f4b3b 100644 --- a/pkg/converter/tool/builder.go +++ b/pkg/converter/tool/builder.go @@ -305,7 +305,41 @@ func Unpack(option UnpackOption) error { } if option.BackendConfigPath != "" { - args = append(args, "--backend-config", option.BackendConfigPath) + configFile, err := os.Open(option.BackendConfigPath) + if err != nil { + return errors.Wrapf(err, "fail to open backend config file %s", option.BackendConfigPath) + } + defer configFile.Close() + + configBytes, err := os.ReadFile(option.BackendConfigPath) + if err != nil { + return errors.Wrapf(err, "fail to read backend config file %s", option.BackendConfigPath) + } + + var config map[string]interface{} + if err := json.Unmarshal(configBytes, &config); err != nil { + return errors.Wrapf(err, "fail to unmarshal backend config file %s", option.BackendConfigPath) + } + + backendConfigType, ok := config["backend"].(map[string]interface{})["type"] + if !ok { + return errors.New("backend config file should contain a valid backend type") + } + + backendConfig, ok := config["backend"].(map[string]interface{})[backendConfigType.(string)] + if !ok { + return errors.New("failed to get backend config with type " + backendConfigType.(string)) + } + + backendConfigBytes, err := json.Marshal(backendConfig) + if err != nil { + return errors.Wrapf(err, "fail to marshal backend config %v", backendConfig) + } + + logrus.Errorf("Backend config: %s", backendConfigBytes) + + args = append(args, "--backend-type", backendConfigType.(string)) + args = append(args, "--backend-config", string(backendConfigBytes)) } else if option.BlobPath != "" { args = append(args, "--blob", option.BlobPath) }