mirror of
https://github.com/usememos/memos.git
synced 2026-11-19 10:29:11 +01:00
fix(cmd): warn about legacy-named identity provider files in /etc/secrets
The v0.31 loader read every memos-idp-*.json, warning only when the name was not lowercase kebab case, so the startup warning now matches identity provider files by that prefix and suffix. Instance setting files keep the kebab-case pattern the loader required.
This commit is contained in:
@@ -164,13 +164,15 @@ func TestLegacySecretsFiles(t *testing.T) {
|
||||
require.Nil(t, legacySecretsFiles(filepath.Join(t.TempDir(), "missing")))
|
||||
|
||||
dir := t.TempDir()
|
||||
for _, name := range []string{"memos-idp-company-sso.json", "memos-instance-setting-storage.json", "memos-instance-setting-storage.json.bak", "other.json", "README"} {
|
||||
for _, name := range []string{"memos-idp-company-sso.json", "memos-idp-Google_SSO.json", "memos-instance-setting-storage.json",
|
||||
"memos-instance-setting-Storage.json", "memos-instance-setting-storage.json.bak", "other.json", "README"} {
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, name), []byte("{}"), 0o600))
|
||||
}
|
||||
require.NoError(t, os.Mkdir(filepath.Join(dir, "memos-idp-dir.json"), 0o700))
|
||||
require.NoError(t, os.Symlink(filepath.Join(dir, "other.json"), filepath.Join(dir, "memos-instance-setting-general.json")))
|
||||
|
||||
require.Equal(t, []string{
|
||||
filepath.Join(dir, "memos-idp-Google_SSO.json"),
|
||||
filepath.Join(dir, "memos-idp-company-sso.json"),
|
||||
filepath.Join(dir, "memos-instance-setting-general.json"),
|
||||
filepath.Join(dir, "memos-instance-setting-storage.json"),
|
||||
|
||||
+12
-2
@@ -319,7 +319,17 @@ func (e exitCodeError) Error() string {
|
||||
// reading without a migration.
|
||||
const legacySecretsDir = "/etc/secrets"
|
||||
|
||||
var legacySecretsFilenameMatcher = regexp.MustCompile(`^memos-(?:idp|instance-setting)-[a-z0-9]+(?:-[a-z0-9]+)*\.json$`)
|
||||
var legacyInstanceSettingFilenameMatcher = regexp.MustCompile(`^memos-instance-setting-[a-z0-9]+(?:-[a-z0-9]+)*\.json$`)
|
||||
|
||||
// isLegacySecretsFilename reports whether the v0.31 loader read name. It took
|
||||
// any memos-idp-*.json, warning only about names that were not lowercase kebab
|
||||
// case, but required kebab case for instance settings.
|
||||
func isLegacySecretsFilename(name string) bool {
|
||||
if strings.HasPrefix(name, "memos-idp-") && strings.HasSuffix(name, ".json") {
|
||||
return true
|
||||
}
|
||||
return legacyInstanceSettingFilenameMatcher.MatchString(name)
|
||||
}
|
||||
|
||||
// legacySecretsFiles lists the v0.31 deployment configuration files still
|
||||
// present in dir, so startup can say that nothing reads them: an operator who
|
||||
@@ -333,7 +343,7 @@ func legacySecretsFiles(dir string) []string {
|
||||
}
|
||||
var files []string
|
||||
for _, entry := range entries {
|
||||
if !entry.IsDir() && legacySecretsFilenameMatcher.MatchString(entry.Name()) {
|
||||
if !entry.IsDir() && isLegacySecretsFilename(entry.Name()) {
|
||||
files = append(files, filepath.Join(dir, entry.Name()))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user