Skip to content

Commit

Permalink
refactor(persistence): Remove logic to persist templates that are nev…
Browse files Browse the repository at this point in the history
…er 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.
  • Loading branch information
UnseenWizzard committed Oct 5, 2023
1 parent 9959f0d commit 2c20206
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions pkg/persistence/config/writer/config_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2c20206

Please sign in to comment.