mirror of
https://github.com/inventree/InvenTree.git
synced 2026-03-11 14:44:18 +00:00
!refactor(backend): remove measures for config path changes (#9814)
* moving config files out of the source directories Fixes #9756 * add folder for config * fix lookup paths * reorder ignores * remove temporary measures from #9769 * reduce diff * remove temporary measures added in inventree#9769 * add changelog * remove legacy tests * fix indent
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -51,12 +51,6 @@ inventree_media
|
||||
inventree_static
|
||||
static_i18n
|
||||
|
||||
# Local config files
|
||||
config.yaml
|
||||
plugins.txt
|
||||
secret_key.txt
|
||||
oidc.pem
|
||||
|
||||
# Default data file
|
||||
data.json
|
||||
*.json.tmp
|
||||
|
||||
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Breaking Changes - Remove deprecated features and APIs
|
||||
|
||||
- [#9814](https://github.com/inventree/InvenTree/pull/9814) - removes legacy config path support
|
||||
|
||||
## Unreleased - YYYY-MM-DD
|
||||
|
||||
|
||||
@@ -157,9 +157,6 @@ def get_config_file(create=True) -> Path:
|
||||
|
||||
if cfg_filename:
|
||||
cfg_filename = Path(cfg_filename.strip()).resolve()
|
||||
elif get_base_dir().joinpath('config.yaml').exists():
|
||||
# If the config file is in the old directory, use that
|
||||
cfg_filename = base_dir.joinpath('config.yaml').resolve()
|
||||
else:
|
||||
# Config file is *not* specified - use the default
|
||||
cfg_filename = conf_dir.joinpath('config.yaml').resolve()
|
||||
@@ -427,8 +424,6 @@ def get_secret_key(return_path: bool = False) -> str | Path:
|
||||
# Look for secret key file
|
||||
if secret_key_file := get_setting('INVENTREE_SECRET_KEY_FILE', 'secret_key_file'):
|
||||
secret_key_file = Path(secret_key_file).resolve()
|
||||
elif get_base_dir().joinpath('secret_key.txt').exists():
|
||||
secret_key_file = get_base_dir().joinpath('secret_key.txt')
|
||||
else:
|
||||
# Default location for secret key file
|
||||
secret_key_file = get_config_dir().joinpath('secret_key.txt').resolve()
|
||||
@@ -472,15 +467,9 @@ def get_oidc_private_key(return_path: bool = False) -> str | Path:
|
||||
)
|
||||
)
|
||||
|
||||
# Trying old default location
|
||||
if not key_loc.exists():
|
||||
old_def_path = get_base_dir().joinpath('oidc.pem')
|
||||
if old_def_path.exists():
|
||||
key_loc = old_def_path.resolve()
|
||||
|
||||
check_config_dir('INVENTREE_OIDC_PRIVATE_KEY_FILE', key_loc)
|
||||
if key_loc.exists():
|
||||
return key_loc.read_text() if not return_path else key_loc
|
||||
return key_loc.read_text(encoding='utf-8') if not return_path else key_loc
|
||||
else:
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
from cryptography.hazmat.primitives.asymmetric import rsa
|
||||
@@ -500,7 +489,7 @@ def get_oidc_private_key(return_path: bool = False) -> str | Path:
|
||||
encryption_algorithm=serialization.NoEncryption(),
|
||||
)
|
||||
)
|
||||
return key_loc.read_text() if not return_path else key_loc
|
||||
return key_loc.read_text(encoding='utf-8') if not return_path else key_loc
|
||||
|
||||
|
||||
def get_custom_file(
|
||||
|
||||
@@ -4,7 +4,6 @@ import os
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
from decimal import Decimal
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
@@ -1266,22 +1265,6 @@ class TestSettings(InvenTreeTestCase):
|
||||
str(test_file).lower(), str(config.get_config_file()).lower()
|
||||
)
|
||||
|
||||
# LEGACY - old path
|
||||
if settings.DOCKER: # pragma: no cover
|
||||
# In Docker, the legacy path is not used
|
||||
return
|
||||
legacy_path = config.get_base_dir().joinpath('config.yaml')
|
||||
assert not legacy_path.exists(), (
|
||||
'Legacy config file does exist, stopping as a percaution!'
|
||||
)
|
||||
self.assertTrue(test_file.exists(), f'Test file {test_file} does not exist!')
|
||||
test_file.rename(legacy_path)
|
||||
self.assertIn(
|
||||
'src/backend/inventree/config.yaml', str(config.get_config_file()).lower()
|
||||
)
|
||||
# Clean up again
|
||||
legacy_path.unlink(missing_ok=True)
|
||||
|
||||
def test_helpers_plugin_file(self):
|
||||
"""Test get_plugin_file."""
|
||||
# normal run - not configured
|
||||
@@ -1312,22 +1295,6 @@ class TestSettings(InvenTreeTestCase):
|
||||
with in_env_context({'INVENTREE_SECRET_KEY_FILE': str(test_file)}):
|
||||
self.assertIn(str(test_file), str(config.get_secret_key(return_path=True)))
|
||||
|
||||
# LEGACY - old path
|
||||
if settings.DOCKER: # pragma: no cover
|
||||
# In Docker, the legacy path is not used
|
||||
return
|
||||
legacy_path = config.get_base_dir().joinpath('secret_key.txt')
|
||||
assert not legacy_path.exists(), (
|
||||
'Legacy secret key file does exist, stopping as a percaution!'
|
||||
)
|
||||
test_file.rename(legacy_path)
|
||||
self.assertIn(
|
||||
'src/backend/inventree/secret_key.txt',
|
||||
str(config.get_secret_key(return_path=True)).lower(),
|
||||
)
|
||||
# Clean up again
|
||||
legacy_path.unlink(missing_ok=True)
|
||||
|
||||
# Test with content set per environment
|
||||
with in_env_context({'INVENTREE_SECRET_KEY': '123abc123'}):
|
||||
self.assertEqual(config.get_secret_key(), '123abc123')
|
||||
@@ -1353,27 +1320,6 @@ class TestSettings(InvenTreeTestCase):
|
||||
with in_env_context({'INVENTREE_OIDC_PRIVATE_KEY': '123abc123'}):
|
||||
self.assertEqual(config.get_oidc_private_key(), '123abc123')
|
||||
|
||||
# LEGACY - old path
|
||||
if settings.DOCKER: # pragma: no cover
|
||||
# In Docker, the legacy path is not used
|
||||
return
|
||||
legacy_path = config.get_base_dir().joinpath('oidc.pem')
|
||||
assert not legacy_path.exists(), (
|
||||
'Legacy OIDC private key file does exist, stopping as a precaution!'
|
||||
)
|
||||
test_file.rename(legacy_path)
|
||||
assert isinstance(trgt_path, Path)
|
||||
new_path = trgt_path.rename(
|
||||
trgt_path.parent / '_oidc.pem'
|
||||
) # move out current config
|
||||
self.assertIn(
|
||||
'src/backend/inventree/oidc.pem',
|
||||
str(config.get_oidc_private_key(return_path=True)).lower(),
|
||||
)
|
||||
# Clean up again
|
||||
legacy_path.unlink(missing_ok=True)
|
||||
new_path.rename(trgt_path) # restore original path for current config
|
||||
|
||||
def test_helpers_setting(self):
|
||||
"""Test get_setting."""
|
||||
TEST_ENV_NAME = '123TEST'
|
||||
|
||||
Reference in New Issue
Block a user