Skip to content

Commit 0a380ec

Browse files
Remove env var management (#27)
Environment variable management is now handled by the CLI it does not need to be handled by the hooks as well
1 parent d399102 commit 0a380ec

9 files changed

Lines changed: 5 additions & 156 deletions

File tree

slack_cli_hooks/hooks/start.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,12 @@
44
import sys
55

66
from slack_cli_hooks.error import CliError
7-
from slack_cli_hooks.hooks.utils import ManagedOSEnvVars
87
from slack_cli_hooks.protocol import Protocol, build_protocol
98

109
PROTOCOL: Protocol
1110

1211
DEFAULT_MAIN_FILE = "app.py"
1312

14-
SLACK_CLI_XOXB = "SLACK_CLI_XOXB"
15-
SLACK_CLI_XAPP = "SLACK_CLI_XAPP"
16-
SLACK_BOT_TOKEN = "SLACK_BOT_TOKEN"
17-
SLACK_APP_TOKEN = "SLACK_APP_TOKEN"
18-
19-
20-
def validate_env() -> None:
21-
if not os.environ.get(SLACK_CLI_XOXB):
22-
raise CliError(f"Missing local run bot token ({SLACK_CLI_XOXB}).")
23-
if not os.environ.get(SLACK_CLI_XAPP):
24-
raise CliError(f"Missing local run app token ({SLACK_CLI_XAPP}).")
25-
2613

2714
def get_main_file() -> str:
2815
custom_file = os.environ.get("SLACK_APP_PATH")
@@ -38,25 +25,18 @@ def get_main_path(working_directory: str) -> str:
3825

3926

4027
def start(working_directory: str) -> None:
41-
validate_env()
42-
4328
entrypoint_path = get_main_path(working_directory)
4429

4530
if not os.path.exists(entrypoint_path):
4631
raise CliError(f"Could not find {get_main_file()} file")
4732

4833
parent_package = os.path.dirname(entrypoint_path)
49-
os_env_vars = ManagedOSEnvVars(PROTOCOL)
5034

5135
try:
52-
os_env_vars.set_if_absent(SLACK_BOT_TOKEN, os.environ[SLACK_CLI_XOXB])
53-
os_env_vars.set_if_absent(SLACK_APP_TOKEN, os.environ[SLACK_CLI_XAPP])
5436
sys.path.insert(0, parent_package) # Add parent package to sys path
55-
5637
runpy.run_path(entrypoint_path, run_name="__main__")
5738
finally:
5839
sys.path.remove(parent_package)
59-
os_env_vars.clear()
6040

6141

6242
if __name__ == "__main__":

slack_cli_hooks/hooks/utils/__init__.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

slack_cli_hooks/hooks/utils/managed_os_env_vars.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/scenario_test/test_app/app.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
from slack_bolt.app import App
55
from utils import get_test_socket_mode_handler, wait_for_test_socket_connection
66

7-
assert "SLACK_BOT_TOKEN" in os.environ
8-
assert "SLACK_APP_TOKEN" in os.environ
9-
107
web_client = WebClient(base_url="http://localhost:8888", token=os.environ.get("SLACK_BOT_TOKEN"))
118

129
app = App(signing_secret="valid", client=web_client)

tests/scenario_test/test_app/my_app.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
from slack_bolt.app import App
55
from utils import get_test_socket_mode_handler, wait_for_test_socket_connection
66

7-
assert "SLACK_BOT_TOKEN" in os.environ
8-
assert "SLACK_APP_TOKEN" in os.environ
9-
107
web_client = WebClient(base_url="http://localhost:8888", token=os.environ.get("SLACK_BOT_TOKEN"))
118

129
app = App(signing_secret="valid", client=web_client)

tests/scenario_test/test_start.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ class TestStart:
1414

1515
def setup_method(self):
1616
self.old_os_env = remove_os_env_temporarily()
17-
os.environ["SLACK_CLI_XOXB"] = "xoxb-valid"
18-
os.environ["SLACK_CLI_XAPP"] = "xapp-A111-222-xyz"
17+
os.environ["SLACK_BOT_TOKEN"] = "xoxb-valid"
18+
os.environ["SLACK_APP_TOKEN"] = "xapp-A111-222-xyz"
1919
setup_mock_web_api_server(self)
2020
start_socket_mode_server(self, 3012)
2121
self.cwd = os.getcwd()
2222

2323
def teardown_method(self):
2424
os.chdir(self.cwd)
25-
os.environ.pop("SLACK_CLI_XOXB", None)
26-
os.environ.pop("SLACK_CLI_XAPP", None)
25+
os.environ.pop("SLACK_BOT_TOKEN", None)
26+
os.environ.pop("SLACK_APP_TOKEN", None)
2727
os.environ.pop("SLACK_APP_PATH", None)
2828
cleanup_mock_web_api_server(self)
2929
stop_socket_mode_server(self)

tests/slack_cli_hooks/hooks/test_start.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import pytest
21
import os
3-
from slack_cli_hooks.error import CliError
42

5-
from slack_cli_hooks.hooks.start import validate_env, get_main_file, get_main_path
3+
from slack_cli_hooks.hooks.start import get_main_file, get_main_path
64
from tests.utils import remove_os_env_temporarily, restore_os_env
75

8-
SLACK_CLI_XOXB = "SLACK_CLI_XOXB"
9-
SLACK_CLI_XAPP = "SLACK_CLI_XAPP"
106
SLACK_APP_PATH = "SLACK_APP_PATH"
117

128

@@ -17,29 +13,9 @@ def setup_method(self):
1713
self.old_os_env = remove_os_env_temporarily()
1814

1915
def teardown_method(self):
20-
os.environ.pop(SLACK_CLI_XOXB, None)
21-
os.environ.pop(SLACK_CLI_XAPP, None)
2216
os.environ.pop(SLACK_APP_PATH, None)
2317
restore_os_env(self.old_os_env)
2418

25-
def test_validate_env(self):
26-
os.environ[SLACK_CLI_XOXB] = "xoxb-valid"
27-
os.environ[SLACK_CLI_XAPP] = "xapp-A111-222-xyz"
28-
29-
assert validate_env() is None
30-
31-
def test_validate_env_with_missing_xoxb(self):
32-
os.environ[SLACK_CLI_XAPP] = "xapp-A111-222-xyz"
33-
with pytest.raises(CliError) as e:
34-
validate_env()
35-
assert str(e.value) == f"Missing local run bot token ({SLACK_CLI_XOXB})."
36-
37-
def test_validate_env_with_missing_xapp(self):
38-
os.environ[SLACK_CLI_XOXB] = "xoxb-valid"
39-
with pytest.raises(CliError) as e:
40-
validate_env()
41-
assert str(e.value) == f"Missing local run app token ({SLACK_CLI_XAPP})."
42-
4319
def test_get_main_file(self):
4420
assert get_main_file() == "app.py"
4521

tests/slack_cli_hooks/hooks/utils/__init__.py

Whitespace-only changes.

tests/slack_cli_hooks/hooks/utils/test_managed_os_env_vars.py

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)