add get_SCOPE_CONFIG

This commit is contained in:
Nick Sweeting 2024-10-29 00:33:14 -07:00
parent eb721bd514
commit 5efeb9d347
No known key found for this signature in database
4 changed files with 89 additions and 9 deletions

View file

@ -174,7 +174,7 @@ class ABIDModel(models.Model):
'uri': self.abid_uri_src,
'subtype': self.abid_subtype_src,
'rand': self.abid_rand_src,
'salt': 'self.abid_salt', # defined as static class vars at build time
'salt': 'self.abid_salt', # defined as static class vars at build time
}
@property

View file

@ -199,15 +199,13 @@ def version(quiet: bool=False,
console = Console()
prnt = console.print
from django.conf import settings
from abx_plugin_default_binproviders import apt, brew, env
from archivebox.config.version import get_COMMIT_HASH, get_BUILD_TIME
from archivebox.config.permissions import ARCHIVEBOX_USER, ARCHIVEBOX_GROUP, RUNNING_AS_UID, RUNNING_AS_GID
from archivebox.config.paths import get_data_locations, get_code_locations
LDAP_ENABLED = archivebox.pm.hook.get_FLAT_CONFIG().LDAP_ENABLED
LDAP_ENABLED = archivebox.pm.hook.get_SCOPE_CONFIG().LDAP_ENABLED
# 0.7.1

View file

@ -1,15 +1,12 @@
__package__ = 'abx_plugin_pocket'
from typing import Dict
from pydantic import Field
from abx_spec_config.base_configset import BaseConfigSet
from abx_spec_config import BaseConfigSet
class PocketConfig(BaseConfigSet):
POCKET_CONSUMER_KEY: str | None = Field(default=None)
POCKET_ACCESS_TOKENS: Dict[str, str] = Field(default=lambda: {}) # {<username>: <access_token>, ...}
POCKET_ACCESS_TOKENS: Dict[str, str] = Field(default=dict) # {<username>: <access_token>, ...}
POCKET_CONFIG = PocketConfig()

View file

@ -51,6 +51,91 @@ class ConfigPluginSpec:
for configset in pm.hook.get_CONFIGS().values()
for key, value in benedict(configset).items()
})
@abx.hookspec(firstresult=True)
@abx.hookimpl
def get_SCOPE_CONFIG(self, extra=None, archiveresult=None, snapshot=None, crawl=None, user=None, collection=..., environment=..., machine=..., default=...) -> Dict[ConfigKeyStr, Any]:
"""Get the config as it applies to you right now, based on the current context"""
return benedict({
**pm.hook.get_default_config(default=default),
# **pm.hook.get_machine_config(machine),
**pm.hook.get_environment_config(environment=environment),
**pm.hook.get_collection_config(collection=collection),
**pm.hook.get_user_config(user=user),
**pm.hook.get_crawl_config(crawl=crawl),
**pm.hook.get_snapshot_config(snapshot=snapshot),
**pm.hook.get_archiveresult_config(archiveresult=archiveresult),
# **pm.hook.get_request_config(request=request),
**(extra or {}),
})
# @abx.hookspec(firstresult=True)
# @abx.hookimpl
# def get_request_config(self, request) -> dict:
# session = getattr(request, 'session', None)
# return getattr(session, 'config', None) or {}
@abx.hookspec(firstresult=True)
@abx.hookimpl
def get_archiveresult_config(self, archiveresult) -> Dict[ConfigKeyStr, Any]:
return getattr(archiveresult, 'config', None) or {}
@abx.hookspec(firstresult=True)
@abx.hookimpl
def get_snapshot_config(self, snapshot) -> Dict[ConfigKeyStr, Any]:
return getattr(snapshot, 'config', None) or {}
@abx.hookspec(firstresult=True)
@abx.hookimpl
def get_crawl_config(self, crawl) -> Dict[ConfigKeyStr, Any]:
return getattr(crawl, 'config', None) or {}
@abx.hookspec(firstresult=True)
@abx.hookimpl
def get_user_config(self, user=None) -> Dict[ConfigKeyStr, Any]:
return getattr(user, 'config', None) or {}
@abx.hookspec(firstresult=True)
@abx.hookimpl
def get_collection_config(self, collection=...) -> Dict[ConfigKeyStr, Any]:
# ... = ellipsis, means automatically get the collection config from the active data/ArchiveBox.conf file
# {} = empty dict, override to ignore the collection config
return benedict({
key: value
for configset in pm.hook.get_CONFIGS().values()
for key, value in configset.from_collection().items()
}) if collection == ... else collection
@abx.hookspec(firstresult=True)
@abx.hookimpl
def get_environment_config(self, environment=...) -> Dict[ConfigKeyStr, Any]:
# ... = ellipsis, means automatically get the environment config from the active environment variables
# {} = empty dict, override to ignore the environment config
return benedict({
key: value
for configset in pm.hook.get_CONFIGS().values()
for key, value in configset.from_environment().items()
}) if environment == ... else environment
# @abx.hookspec(firstresult=True)
# @abx.hookimpl
# def get_machine_config(self, machine=...) -> dict:
# # ... = ellipsis, means automatically get the machine config from the currently executing machine
# # {} = empty dict, override to ignore the machine config
# if machine == ...:
# machine = Machine.objects.get_current()
# return getattr(machine, 'config', None) or {}
@abx.hookspec(firstresult=True)
@abx.hookimpl
def get_default_config(self, default=...) -> Dict[ConfigKeyStr, Any]:
# ... = ellipsis, means automatically get the machine config from the currently executing machine
# {} = empty dict, override to ignore the machine config
return benedict({
key: value
for configset in pm.hook.get_CONFIGS().values()
for key, value in configset.from_defaults().items()
}) if default == ... else default
# TODO: add read_config_file(), write_config_file() hooks