From 1e839fdf0af02b9b63172c869c918c5f2bd4f553 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Tue, 10 Dec 2024 00:35:59 -0800 Subject: [PATCH 1/2] Adding a docker compose setup; Adding a dragonfly package; Adding derived add_auth_spec --- Dockerfile | 4 +- docker-compose.yaml | 42 +++++++++++++++++++ dragonfly/__init__.py | 17 ++++++++ dripline/extensions/__init__.py | 22 +++------- dripline/extensions/add_auth_spec.py | 41 ++++++++++++++++++ dripline_mesh.yaml | 1 + ...jitter_example.yml => jitter_example.yaml} | 4 +- examples/key-value-store.yaml | 21 ++++++++++ setup.py | 2 +- 9 files changed, 132 insertions(+), 22 deletions(-) create mode 100644 docker-compose.yaml create mode 100644 dragonfly/__init__.py create mode 100644 dripline/extensions/add_auth_spec.py create mode 100644 dripline_mesh.yaml rename examples/{jitter_example.yml => jitter_example.yaml} (69%) create mode 100644 examples/key-value-store.yaml diff --git a/Dockerfile b/Dockerfile index edf1616..4414f8d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,9 @@ ARG img_tag=new-auth FROM ${img_user}/${img_repo}:${img_tag} -COPY . /usr/local/src/dragonfly +COPY . /usr/local/src_dragonfly -WORKDIR /usr/local/src/dragonfly +WORKDIR /usr/local/src_dragonfly RUN pip install . WORKDIR / diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..9ff66ea --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,42 @@ +services: + + # The broker for the mesh + rabbit-broker: + image: rabbitmq:3-management + ports: + - "15672:15672" + environment: + - RABBITMQ_DEFAULT_USER=dripline + - RABBITMQ_DEFAULT_PASS=dripline + healthcheck: + test: ["CMD-SHELL", "curl -u dripline:dripline http://rabbit-broker:15672/api/overview &> /dev/null || exit 1"] + + # The classic key-value store, a configuration based on the base Service class + key-value-store: + image: ghcr.io/project8/dragonfly:${DGFLY_IMG_TAG:-latest-dev} + depends_on: + rabbit-broker: + condition: service_healthy + volumes: + - ./examples/key-value-store.yaml:/root/key-value-store.yaml + - ./dripline_mesh.yaml:/root/.dripline_mesh.yaml + environment: + - DRIPLINE_USER=dripline + - DRIPLINE_PASSWORD=dripline + command: > + bash -c "dl-serve -vv -c /root/key-value-store.yaml" + + # The classic key-value-store service with a jitter endpoint + jitter: + image: ghcr.io/project8/dragonfly:${DGFLY_IMG_TAG:-latest-dev} + depends_on: + rabbit-broker: + condition: service_healthy + volumes: + - ./examples/jitter_example.yaml:/root/jitter_example.yaml + - ./dripline_mesh.yaml:/root/.dripline_mesh.yaml + environment: + - DRIPLINE_USER=dripline + - DRIPLINE_PASSWORD=dripline + command: > + bash -c "dl-serve -vv -c /root/jitter_example.yaml" diff --git a/dragonfly/__init__.py b/dragonfly/__init__.py new file mode 100644 index 0000000..ae9daaf --- /dev/null +++ b/dragonfly/__init__.py @@ -0,0 +1,17 @@ +import logging +logger = logging.getLogger(__name__) + +def __get_version(): + import scarab + import dragonfly + import pkg_resources + #TODO: this all needs to be populated from setup.py and gita + version = scarab.VersionSemantic() + logger.info('version should be: {}'.format(pkg_resources.get_distribution('dragonfly').version)) + version.parse(pkg_resources.get_distribution('dragonfly').version) + version.package = 'project8/dragonfly' + version.commit = 'na' + dragonfly.core.add_version('dragonfly', version) + return version +version = __get_version() +__version__ = version.version diff --git a/dripline/extensions/__init__.py b/dripline/extensions/__init__.py index 48f5d09..b62df1e 100644 --- a/dripline/extensions/__init__.py +++ b/dripline/extensions/__init__.py @@ -1,21 +1,9 @@ +__all__ = [] + __path__ = __import__('pkgutil').extend_path(__path__, __name__) +# Subdirectories from . import jitter -# add further subdirectories here - -import logging -logger = logging.getLogger(__name__) -def __get_version(): - import scarab - import dragonfly - import pkg_resources - #TODO: this all needs to be populated from setup.py and gita - version = scarab.VersionSemantic() - logger.info('version should be: {}'.format(pkg_resources.get_distribution('dragonfly').version)) - version.parse(pkg_resources.get_distribution('dragonfly').version) - version.package = 'project8/dragonfly' - version.commit = 'na' - dragonfly.core.add_version('dragonfly', version) - return version -version = __get_version() +# Modules in this directory +from .add_auth_spec import * diff --git a/dripline/extensions/add_auth_spec.py b/dripline/extensions/add_auth_spec.py new file mode 100644 index 0000000..13e176f --- /dev/null +++ b/dripline/extensions/add_auth_spec.py @@ -0,0 +1,41 @@ +''' +Contains the AddAuthSpec class, for adding authentication specifications +''' + +import dripline.implementations +import scarab + +import logging + +logger = logging.getLogger(__name__) + +__all__ = [] + +__all__.append('AddAuthSpec') +class AddAuthSpec(dripline.implementations.BaseAddAuthSpec): + ''' + + ''' + + def __init__(self, app): + ''' + ''' + dripline.implementations.BaseAddAuthSpec.__init__() + app.add_all(app) + + def add_all(self, app): + self.add_postgres_auth_spec(app) + self.add_slack_auth_spec(app) + + def add_slack_auth_spec(self, app): + ''' + Adds the Slack authenticaiton specification to a scarab::main_app object + ''' + auth_spec = { + 'dripline': { + 'default': 'default-token', + 'env': 'DRIPLINE_SLACK_TOKEN', + }, + } + app.add_default_auth_spec_group( 'slack', scarab.to_param(auth_spec).as_node() ) + logging.debug('Added slack auth spec') diff --git a/dripline_mesh.yaml b/dripline_mesh.yaml new file mode 100644 index 0000000..ce34d78 --- /dev/null +++ b/dripline_mesh.yaml @@ -0,0 +1 @@ +broker: rabbit-broker diff --git a/examples/jitter_example.yml b/examples/jitter_example.yaml similarity index 69% rename from examples/jitter_example.yml rename to examples/jitter_example.yaml index ffac51c..378e1a2 100644 --- a/examples/jitter_example.yml +++ b/examples/jitter_example.yaml @@ -1,7 +1,7 @@ -name: my_store +name: jitter-store module: Service endpoints: - - name: peaches + - name: jitter-peaches module: JitterEntity calibration: '2*{}' initial_value: 0.75 diff --git a/examples/key-value-store.yaml b/examples/key-value-store.yaml new file mode 100644 index 0000000..8b26530 --- /dev/null +++ b/examples/key-value-store.yaml @@ -0,0 +1,21 @@ +name: my_store +module: Service +endpoints: + - name: peaches + module: KeyValueStore + calibration: '2*{}' + initial_value: 0.75 + log_interval: 10 + get_on_set: True + log_on_set: True + - name: chips + module: KeyValueStore + calibration: 'times3({})' + initial_value: 1.75 + - name: waffles + module: KeyValueStore + #log_interval: 30 + #log_on_set: True + calibration: '1.*{}' + initial_value: 4.00 + diff --git a/setup.py b/setup.py index f6894b9..adbc55d 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_namespace_packages -packages = find_namespace_packages('.', include=['dripline.extensions.*']) +packages = find_namespace_packages('.', include=['dragonfly', 'dripline.extensions', 'dripline.extensions.*']) print('packages are: {}'.format(packages)) setup( From d4be276d3482627353a870192540acddbeabe536 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Tue, 10 Dec 2024 17:48:51 -0800 Subject: [PATCH 2/2] The base add auth class now takes care of postgres --- dripline/extensions/add_auth_spec.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/dripline/extensions/add_auth_spec.py b/dripline/extensions/add_auth_spec.py index 13e176f..a36687a 100644 --- a/dripline/extensions/add_auth_spec.py +++ b/dripline/extensions/add_auth_spec.py @@ -20,11 +20,7 @@ class AddAuthSpec(dripline.implementations.BaseAddAuthSpec): def __init__(self, app): ''' ''' - dripline.implementations.BaseAddAuthSpec.__init__() - app.add_all(app) - - def add_all(self, app): - self.add_postgres_auth_spec(app) + dripline.implementations.BaseAddAuthSpec.__init__(self, app) self.add_slack_auth_spec(app) def add_slack_auth_spec(self, app):