sovereign 0.18.1__tar.gz → 0.19.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sovereign might be problematic. Click here for more details.
- {sovereign-0.18.1 → sovereign-0.19.1}/PKG-INFO +1 -1
- {sovereign-0.18.1 → sovereign-0.19.1}/pyproject.toml +1 -1
- {sovereign-0.18.1 → sovereign-0.19.1}/setup.py +1 -1
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/__init__.py +7 -3
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/context.py +18 -13
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/server.py +19 -1
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/sources/poller.py +6 -9
- sovereign-0.19.1/src/sovereign/utils/entry_point_loader.py +18 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/LICENSE.txt +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/README.md +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/app.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/config_loader.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/discovery.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/error_info.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/logs.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/middlewares.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/modifiers/__init__.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/modifiers/lib.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/modifiers/test.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/schemas.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/sources/__init__.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/sources/file.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/sources/inline.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/sources/lib.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/static/sass/style.scss +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/static/style.css +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/statistics.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/templates/base.html +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/templates/err.html +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/templates/resources.html +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/templates/ul_filter.html +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/utils/__init__.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/utils/auth.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/utils/crypto.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/utils/dictupdate.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/utils/eds.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/utils/mock.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/utils/templates.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/utils/timer.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/utils/version_info.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/utils/weighted_clusters.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/views/__init__.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/views/admin.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/views/crypto.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/views/discovery.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/views/healthchecks.py +0 -0
- {sovereign-0.18.1 → sovereign-0.19.1}/src/sovereign/views/interface.py +0 -0
|
@@ -47,7 +47,7 @@ entry_points = \
|
|
|
47
47
|
|
|
48
48
|
setup_kwargs = {
|
|
49
49
|
'name': 'sovereign',
|
|
50
|
-
'version': '0.
|
|
50
|
+
'version': '0.19.1',
|
|
51
51
|
'description': 'Envoy Proxy control-plane written in Python',
|
|
52
52
|
'long_description': 'sovereign\n=========\n\nMission statement\n-----------------\nThis project implements a JSON control-plane based on the [envoy](https://envoyproxy.io) [data-plane-api](https://github.com/envoyproxy/data-plane-api)\n\nThe purpose of `sovereign` is to supply downstream envoy proxies with \nconfiguration in near-realtime by responding to discovery requests.\n\nMechanism of Operation\n----------------------\ntl;dr version:\n```\n* Polls HTTP/File/Other for data\n* (optional) Applies transforms to the data\n* Uses the data to generate Envoy configuration from templates\n```\n\nIn a nutshell, Sovereign \ngathers contextual data (*"sources"* and *"template context"*), \noptionally applies transforms to that data (using *"modifiers"*) and finally \nuses the data to generate envoy configuration from either python code, or jinja2 templates.\n\nThis is performed in a semi-stateless way, where the only state is data cached in memory.\n\nTemplate context is intended to be statically configured, whereas *Sources* \nare meant to be dynamic - for example, fetching from an API, an S3 bucket, \nor a file that receives updates.\n\n*Modifiers* can mutate the data retrieved from sources, just in case the data \nis in a less than favorable structure.\n\nBoth modifiers and sources are pluggable, i.e. it\'s easy to write your own and \nplug them into Sovereign for your use-case.\n\nCurrently, Sovereign supports only providing configuration to Envoy as JSON. \nThat is to say, gRPC is not supported yet. Contributions in this area are highly\nappreciated!\n\nThe JSON configuration can be viewed in real-time with Sovereign\'s read-only web interface.\n\nRequirements\n------------\n* Python 3.8+\n\nInstallation\n------------\n```\npip install sovereign\n```\n\nDocumentation\n-------------\n[Read the docs here!](https://vsyrakis.bitbucket.io/sovereign/docs/)\n\n:new: Read-only user interface\n------------------------\nAdded in `v0.5.3`!\n\nThis interface allows you to browse the resources currently returned by Sovereign.\n\n\n\nLocal development\n=================\n\nRequirements\n------------\n* Docker\n* Docker-compose\n\nInstalling dependencies for dev\n-------------------------------\nI recommend creating a virtualenv before doing any dev work\n\n```\npython3 -m venv venv\nsource venv/bin/activate\npip install -r requirements-dev.txt\n```\n\nRunning locally\n---------------\nRunning the test env\n\n```\nmake run\n```\n \nRunning the test env daemonized\n\n```\nmake run-daemon\n```\n\nPylint\n\n```\nmake lint\n```\n\nUnit tests\n\n```\nmake unit\n```\n\nAcceptance tests\n\n```\nmake run-daemon acceptance\n```\n\n\nContributors\n============\n\nPull requests, issues and comments welcome. For pull requests:\n\n* Add tests for new features and bug fixes\n* Follow the existing style\n* Separate unrelated changes into multiple pull requests\n\nSee the existing issues for things to start contributing.\n\nFor bigger changes, make sure you start a discussion first by creating\nan issue and explaining the intended change.\n\nAtlassian requires contributors to sign a Contributor License Agreement,\nknown as a CLA. This serves as a record stating that the contributor is\nentitled to contribute the code/documentation/translation to the project\nand is willing to have it used in distributions and derivative works\n(or is willing to transfer ownership).\n\nPrior to accepting your contributions we ask that you please follow the appropriate\nlink below to digitally sign the CLA. The Corporate CLA is for those who are\ncontributing as a member of an organization and the individual CLA is for\nthose contributing as an individual.\n\n* [CLA for corporate contributors](https://na2.docusign.net/Member/PowerFormSigning.aspx?PowerFormId=e1c17c66-ca4d-4aab-a953-2c231af4a20b)\n* [CLA for individuals](https://na2.docusign.net/Member/PowerFormSigning.aspx?PowerFormId=3f94fbdc-2fbe-46ac-b14c-5d152700ae5d)\n\n\nLicense\n========\n\nCopyright (c) 2018 Atlassian and others.\nApache 2.0 licensed, see [LICENSE.txt](LICENSE.txt) file.\n\n\n',
|
|
53
53
|
'author': 'Vasili Syrakis',
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from contextvars import ContextVar
|
|
3
3
|
from typing import Type, Any, Mapping
|
|
4
|
-
from
|
|
4
|
+
from importlib.metadata import version
|
|
5
|
+
from pkg_resources import resource_filename
|
|
5
6
|
|
|
6
7
|
from fastapi.responses import JSONResponse
|
|
7
8
|
from starlette.templating import Jinja2Templates
|
|
@@ -52,9 +53,12 @@ def get_request_id() -> str:
|
|
|
52
53
|
return _request_id_ctx_var.get()
|
|
53
54
|
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
DIST_NAME = "sovereign"
|
|
57
|
+
|
|
58
|
+
__version__ = version(DIST_NAME)
|
|
56
59
|
config_path = os.getenv("SOVEREIGN_CONFIG", "file:///etc/sovereign.yaml")
|
|
57
|
-
|
|
60
|
+
|
|
61
|
+
html_templates = Jinja2Templates(resource_filename(DIST_NAME, "templates"))
|
|
58
62
|
|
|
59
63
|
try:
|
|
60
64
|
config = SovereignConfigv2(**parse_raw_configuration(config_path))
|
|
@@ -26,10 +26,10 @@ class TemplateContext:
|
|
|
26
26
|
self.configured_context = configured_context
|
|
27
27
|
self.crypto = encryption_suite
|
|
28
28
|
self.disabled_suite = disabled_suite
|
|
29
|
-
# initial load
|
|
30
|
-
self.context = self.load_context_variables()
|
|
31
29
|
self.logger = logger
|
|
32
30
|
self.stats = stats
|
|
31
|
+
# initial load
|
|
32
|
+
self.context = self.load_context_variables()
|
|
33
33
|
|
|
34
34
|
async def start_refresh_context(self) -> NoReturn:
|
|
35
35
|
if self.refresh_cron is not None:
|
|
@@ -40,21 +40,26 @@ class TemplateContext:
|
|
|
40
40
|
raise RuntimeError("Failed to start refresh_context, this should never happen")
|
|
41
41
|
|
|
42
42
|
async def refresh_context(self) -> None:
|
|
43
|
-
|
|
44
|
-
self.context = self.load_context_variables()
|
|
45
|
-
self.stats.increment("context.refresh.success")
|
|
46
|
-
# pylint: disable=broad-except
|
|
47
|
-
except Exception as e:
|
|
48
|
-
self.logger(event=e)
|
|
49
|
-
self.stats.increment("context.refresh.error")
|
|
43
|
+
self.context = self.load_context_variables()
|
|
50
44
|
|
|
51
45
|
def load_context_variables(self) -> Dict[str, Any]:
|
|
52
46
|
ret = dict()
|
|
53
47
|
for k, v in self.configured_context.items():
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
try:
|
|
49
|
+
if isinstance(v, Loadable):
|
|
50
|
+
ret[k] = v.load()
|
|
51
|
+
elif isinstance(v, str):
|
|
52
|
+
ret[k] = Loadable.from_legacy_fmt(v).load()
|
|
53
|
+
self.stats.increment(
|
|
54
|
+
"context.refresh.success",
|
|
55
|
+
tags=[f"context:{k}"],
|
|
56
|
+
)
|
|
57
|
+
except Exception as e: # pylint: disable=broad-exception-caught
|
|
58
|
+
self.logger(event=e)
|
|
59
|
+
self.stats.increment(
|
|
60
|
+
"context.refresh.error",
|
|
61
|
+
tags=[f"context:{k}"],
|
|
62
|
+
)
|
|
58
63
|
if "crypto" not in ret:
|
|
59
64
|
ret["crypto"] = self.crypto
|
|
60
65
|
return ret
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import gunicorn.app.base
|
|
2
2
|
from fastapi import FastAPI
|
|
3
|
-
from typing import Optional, Dict, Any
|
|
3
|
+
from typing import Optional, Dict, Any, Callable
|
|
4
4
|
from sovereign import asgi_config
|
|
5
5
|
from sovereign.app import app
|
|
6
|
+
from sovereign.utils.entry_point_loader import EntryPointLoader
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
class StandaloneApplication(gunicorn.app.base.BaseApplication): # type: ignore
|
|
10
|
+
_HOOKS = ["pre_fork", "post_fork"]
|
|
11
|
+
|
|
9
12
|
def __init__(
|
|
10
13
|
self, application: FastAPI, options: Optional[Dict[str, Any]] = None
|
|
11
14
|
) -> None:
|
|
15
|
+
self.loader = EntryPointLoader(*self._HOOKS)
|
|
12
16
|
self.options = options or {}
|
|
13
17
|
self.application = application
|
|
14
18
|
super().__init__()
|
|
@@ -17,6 +21,20 @@ class StandaloneApplication(gunicorn.app.base.BaseApplication): # type: ignore
|
|
|
17
21
|
for key, value in self.options.items():
|
|
18
22
|
self.cfg.set(key.lower(), value)
|
|
19
23
|
|
|
24
|
+
for hook in self._HOOKS:
|
|
25
|
+
self._install_hooks(hook)
|
|
26
|
+
|
|
27
|
+
def _install_hooks(self, name: str) -> None:
|
|
28
|
+
hooks: list[Callable[[Any, Any], None]] = [
|
|
29
|
+
ep.load() for ep in self.loader.groups[name]
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
def master_hook(server: Any, worker: Any) -> None:
|
|
33
|
+
for hook in hooks:
|
|
34
|
+
hook(server, worker)
|
|
35
|
+
|
|
36
|
+
self.cfg.set(name, master_hook)
|
|
37
|
+
|
|
20
38
|
def load(self) -> FastAPI:
|
|
21
39
|
return self.application
|
|
22
40
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import traceback
|
|
3
3
|
from copy import deepcopy
|
|
4
|
+
from importlib.metadata import EntryPoint
|
|
4
5
|
from datetime import timedelta, datetime
|
|
5
|
-
from pkg_resources import iter_entry_points, EntryPoint
|
|
6
6
|
from typing import Iterable, Any, Dict, List, Union, Type, Optional
|
|
7
7
|
|
|
8
8
|
from glom import glom, PathAccessError
|
|
9
9
|
|
|
10
|
+
from sovereign.utils.entry_point_loader import EntryPointLoader
|
|
10
11
|
from sovereign.sources.lib import Source
|
|
11
12
|
from sovereign.modifiers.lib import Modifier, GlobalModifier
|
|
12
13
|
from sovereign.schemas import (
|
|
@@ -50,14 +51,10 @@ class SourcePoller:
|
|
|
50
51
|
self.logger = logger
|
|
51
52
|
self.stats = stats
|
|
52
53
|
|
|
53
|
-
self.entry_points
|
|
54
|
-
for entry_point in ("sources", "modifiers", "global_modifiers"):
|
|
55
|
-
self.entry_points[entry_point] = list(
|
|
56
|
-
iter_entry_points(f"sovereign.{entry_point}")
|
|
57
|
-
)
|
|
54
|
+
self.entry_points = EntryPointLoader("sources", "modifiers", "global_modifiers")
|
|
58
55
|
|
|
59
56
|
self.source_classes: Dict[str, Type[Source]] = {
|
|
60
|
-
e.name: e.load() for e in self.entry_points["sources"]
|
|
57
|
+
e.name: e.load() for e in self.entry_points.groups["sources"]
|
|
61
58
|
}
|
|
62
59
|
self.sources = [self.setup_source(s) for s in sources]
|
|
63
60
|
if not self.sources:
|
|
@@ -89,14 +86,14 @@ class SourcePoller:
|
|
|
89
86
|
if len(self.modifiers) == len(modifiers):
|
|
90
87
|
return
|
|
91
88
|
self.modifiers = self.load_modifier_entrypoints(
|
|
92
|
-
self.entry_points["modifiers"], modifiers
|
|
89
|
+
self.entry_points.groups["modifiers"], modifiers
|
|
93
90
|
)
|
|
94
91
|
|
|
95
92
|
def lazy_load_global_modifiers(self, global_modifiers: List[str]) -> None:
|
|
96
93
|
if len(self.global_modifiers) == len(global_modifiers):
|
|
97
94
|
return
|
|
98
95
|
self.global_modifiers = self.load_global_modifier_entrypoints(
|
|
99
|
-
self.entry_points["global_modifiers"], global_modifiers
|
|
96
|
+
self.entry_points.groups["global_modifiers"], global_modifiers
|
|
100
97
|
)
|
|
101
98
|
|
|
102
99
|
def load_modifier_entrypoints(
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from typing import Dict
|
|
2
|
+
from functools import cached_property
|
|
3
|
+
from importlib.metadata import entry_points, EntryPoints
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class EntryPointLoader:
|
|
7
|
+
ENTRY_POINTS = entry_points()
|
|
8
|
+
|
|
9
|
+
def __init__(self, *args: str) -> None:
|
|
10
|
+
self._groups = args
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
def _select(cls, group: str) -> EntryPoints:
|
|
14
|
+
return cls.ENTRY_POINTS.select(group=f"sovereign.{group}")
|
|
15
|
+
|
|
16
|
+
@cached_property
|
|
17
|
+
def groups(self) -> Dict[str, EntryPoints]:
|
|
18
|
+
return {group: self._select(group) for group in self._groups}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|