{"id":22058793,"url":"https://github.com/sd2e/demo-mailbot-reactor","last_synced_at":"2026-04-20T03:05:06.131Z","repository":{"id":73350126,"uuid":"129013091","full_name":"SD2E/demo-mailbot-reactor","owner":"SD2E","description":"Demo Mailbot using Q22018 reactors module","archived":false,"fork":false,"pushed_at":"2018-04-11T00:58:53.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-23T16:45:56.231Z","etag":null,"topics":["agaveapi","demo","reactors"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SD2E.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-11T00:57:35.000Z","updated_at":"2018-04-11T00:59:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"484e7caa-387c-42fc-8535-4b33245e5b30","html_url":"https://github.com/SD2E/demo-mailbot-reactor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SD2E/demo-mailbot-reactor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SD2E%2Fdemo-mailbot-reactor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SD2E%2Fdemo-mailbot-reactor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SD2E%2Fdemo-mailbot-reactor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SD2E%2Fdemo-mailbot-reactor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SD2E","download_url":"https://codeload.github.com/SD2E/demo-mailbot-reactor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SD2E%2Fdemo-mailbot-reactor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32031070,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agaveapi","demo","reactors"],"created_at":"2024-11-30T17:25:07.398Z","updated_at":"2026-04-20T03:05:06.093Z","avatar_url":"https://github.com/SD2E.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mailbot\n\nThis Reactor can send an email message using the [MailGun][1] API. It\ndemonstrates integrating with a third party service and using a *secrets*\nfile to avoid including sensitive information in the Reactor's Docker image.\nIt also demonstrates non-trivial usage of message validation via [JSON schema][2].\nIt reports progress via Reactors library logging interface as it constructs and\nexits with appropriate status depending on the outcome.\n\nIt is built on*[sd2e/reactors:python2][3]* base should also be compatible\nwith *[sd2e/reactors:python3][3]*.\n\n## Build (and Test)\n\n* Run `git clone https://github.com/SD2E/demo-mailbot-reactor`\n* Customize `reactor.rc`\n    * Put own username or organization into `DOCKER_HUB_ORG`\n* Copy `config.yml.sample  and customize it as `config.yml`\n    * :star: Set `sender` to an address you control via Mailgun\n* Obtain a Mailgun API key\n    * Copy `secrets.json.sample` to `secrets.json` and put the key there as illustrated\n* If you will run unit tests, create test data files\n    * Copy and customize `tests/data/executions.json.sample` as `tests/data/executions.json`\n    * Copy and customize `tests/data/tests-deployed-message.json.sample` as `tests/data/tests-deployed-message.json`\n\n### Test Design\n\nReactors rely on environment variables injected a Docker environment by the\nAbaco runtime, making testing a bit challenging. This repository illustrates\none possible solution. The general outline is:\n\n1. Build the container\n    * Leverages `abaco deploy -R` + configuration in [reactor.rc](reactor.rc)\n2. Run `pytest -s` inside the container via `docker run`\n    * Injects the LOCALONLY variable into the environment\n    * Mounts `~/.agave/` as `/root/.agave` to inject API credentials\n    * Mounts $PWD as the working directory in the container\n    * Runs in a Linux user namespace to for improved security\n3. Inject requisite environment variables via the pytest [monkeypatch][4] fixture\n    * Values provided by the Abaco runtime (`_abaco_*`)\n    * Values provided by the function caller\n        * x-nonce\n        * MSG\n        * LOCALONLY\n        * Environent variables sent as URL parameters\n    * Agave API client credentials\n4. Perform tests via `pytest`:\n    * Ensure a Reactor() object can be bootstrapped\n    * Inspect and validate the Reactor object's properties\n    * Ensure necessary environment overrides are set (API keys, etc.)\n    * Check validity of JSON message against a schema (optional)\n    * Ensure the Reactor's main() runs as expected\n    * Inspect and validate contents of log messages\n    * Validate `sys.exit()` response\n\n#### Pytest Configuration\n\nThe repository is set up to run pytests defined in `tests/` but also to review\nthe code for style and portability using [flake8][5]. A few low-criticality\nerrors and warnings set as ignored in `setup.cfg/[flake8]`. Flake8 can be\ndeactivated entirely by commenting out `--flake8` under in `[tool:pyest]`.\n\n### Test via Makefile\n\nAt present, the easiest approach to testing is to use the Makefile, which\nrelies on the Abaco CLI, rational configuration of this repo, and some bundled\nsupport scripts to set up the test environments.\n\n```\nmake container       # Uses abaco-deploy -R to test building the container\nmake container-py3   # Uses Dockerfile.py3 to build the container\nmake tests-local     # Exercise the Reactor image necessarily running it\nmake tests-reactor   # Simulate running the Reactor image on the TACC.cloud\nmake tests-deployed  # Deploy the Reactor and send it a test message\nmake clean           # Remove cache residue from testing\n```\n\nFor the `tests-reactor` and `tests-local` target, the default setting for\nReactor.local (`True`) can be set to `False` via `REACTOR_OVERRIDE_LOCAL=1`\n\n```\nmake tests-local REACTOR_OVERRIDE_LOCAL=1\n```\n\n:star: If the Reactor relies on any feature particular to the Abaco environment,\nsuch as actual filesystem mounts, it may fail in the local test context. Also,\nif the messaage and/or parameters sent to the Reactor will instruct it to take\nactions such as launching a job or sending an email, and if those functions are\ngated behind the status of `Reactor.local`, those actions _will_ be triggered,\nso be forewarned.\n\n## Interfaces\n\nIf this was a more complicated Reactor, there might be extensive documentation\nabout the expected message contents, communications with other Reactors, and\ndescriptions of the code's outputs.\n\n### Inbound Message(s)\n\nA JSON message of the following form is expected. Only `to` is mandatory.\n\n```json\n{ \"to\": \"noreply@tacc.cloud\",\n   \"subject\": \"Hello, computer.\",\n   \"body\":\"A keyboard... how quaint.\"\n}\n```\n\nMessage validation is defined in [message.jsonschema]. The fields  and formats\ntherein should be pretty self-explanatory.\n\n### Actions\n\nThis Reactor does not expect to send messages to other Reactors or Apps.\n\n### Output Message(s)\n\nThis Reactor posts to the Mailgun API.\n\n## Example Build and Test Log\n\n```shell\n$ make tests-local REACTOR_OVERRIDE_LOCAL=1\nrm -rf .hypothesis .pytest_cache __pycache__ */__pycache__\nSending build context to Docker daemon  67.07kB\nStep 1/3 : FROM sd2e/reactors:python2-edge\n# Executing 5 build triggers\n ---\u003e Running in 6f97a709c219\nYou must give at least one requirement to install (see \"pip help install\")\nRemoving intermediate container 6f97a709c219\n ---\u003e a51d2f833b4d\nStep 2/3 : ADD message.jsonschema /message.jsonschema\n ---\u003e 01d86f421c7b\nStep 3/3 : ADD tests /\n ---\u003e ff61c04e0573\nSuccessfully built ff61c04e0573\nSuccessfully tagged sd2e/mailbot:0.6.0\n[INFO] Stopping deployment as this was only a dry run!\n[INFO] Working directory: /Users/mwvaughn/src/SD2/demo-mailbot-reactor\n[INFO] Not running under continous integration\nplatform linux2 -- Python 2.7.12, pytest-3.5.0, py-1.5.3, pluggy-0.6.0 -- /usr/bin/python\ncachedir: .pytest_cache\nrootdir: /mnt/ephemeral-01, inifile: setup.cfg\nplugins: flake8-1.0.0, hypothesis-3.53.0\ncollected 10 items\n\ntests/agavefixtures.py PASSED\ntests/test_jsonschema_message.py PASSED\ntests/test_jsonschema_message.py::test_validate_message_schema PASSED\ntests/test_reactor_main.py PASSED\ntests/test_reactor_main.py::test_test_data PASSED\ntests/test_reactor_main.py::test_reactor_init PASSED\ntests/test_reactor_main.py::test_reactor_read_config PASSED\ntests/test_reactor_main.py::test_reactor_main PASSED\ntests/test_reactor_main.py::test_reactor_invalid_message PASSED\ntests/testdata.py PASSED\n```\n\n[1]: https://documentation.mailgun.com/en/latest/api_reference.html\n[2]: http://json-schema.org/\n[3]: https://hub.docker.com/r/sd2e/reactors/\n[4]: https://docs.pytest.org/en/latest/monkeypatch.html\n[5]: http://flake8.pycqa.org/en/latest/\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsd2e%2Fdemo-mailbot-reactor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsd2e%2Fdemo-mailbot-reactor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsd2e%2Fdemo-mailbot-reactor/lists"}