From 7342ab1a1893578b16f8e39b0a359b26e4c18f69 Mon Sep 17 00:00:00 2001 From: UnseenWizzard Date: Mon, 2 Oct 2023 16:26:18 +0200 Subject: [PATCH] refactor(persistence): Remove logic to persist templates that are never persisted FileBasedTemplate is only used when a config was loaded from a file (in deployments), and these types of Templates will never be passed to the config writer. Only download and conversion will ever persist their configurations, and both create InMemoryTemplates. To simplify the persistence code and don't make it look like we ever persist FileBasedTemplates, the codepath is simply removed. If an unexpected type of Template still get's passed to the Writer, an error is returned. If we ever extend Templates and don't implement persistence logic, we'll get an error. As the interface already includes an error return and we won't notice this on compile, an error was chosen over a hard-exit by panicking. --- pkg/persistence/config/writer/config_writer.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pkg/persistence/config/writer/config_writer.go b/pkg/persistence/config/writer/config_writer.go index b447a58e31..3fc5f1211b 100644 --- a/pkg/persistence/config/writer/config_writer.go +++ b/pkg/persistence/config/writer/config_writer.go @@ -617,16 +617,8 @@ func extractTemplate(context *detailedSerializerContext, cfg config.Config) (str name = sanitize(t.ID()) + ".json" path = filepath.Join(context.configFolder, name) } - case *template.FileBasedTemplate: - path = t.FilePath() - if path == "" { - return "", configTemplate{}, newDetailedConfigWriterError(context.serializerContext, fmt.Errorf("file-based template %q is missing file path - can not write to file", t.ID())) - } - n, err := filepath.Rel(context.configFolder, filepath.Clean(path)) - if err != nil { - return "", configTemplate{}, newDetailedConfigWriterError(context.serializerContext, err) - } - name = n + default: + return "", configTemplate{}, newDetailedConfigWriterError(context.serializerContext, fmt.Errorf("can not persist unexpected template type %q", t)) } content, err := cfg.Template.Content()