Skip to content

Commit

Permalink
Move Slack Token/Channel to Local method (demisto#32232)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgal-pan authored Jan 16, 2024
1 parent 3803323 commit 81a433b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os

import pytest
import requests
Expand Down Expand Up @@ -88,6 +89,7 @@ def test_get_my_place_in_the_queue(mocker):
then: assert that returns the right place and the right previous_build_in_queue.
"""
storage = MockResponse()
mocker.patch.dict(os.environ, {"SLACK_TOKEN": "myslacktoken"})
mocker.patch('Tests.scripts.lock_cloud_machines.send_slack_notification')
mocker.patch.object(storage, 'list_blobs', return_value=[MockResponse('test/queue/1234', '08/04/2000'),
MockResponse('test/queue/1235', '05/04/2000'),
Expand Down
14 changes: 7 additions & 7 deletions Tests/scripts/lock_cloud_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from google.cloud import storage # noqa
import argparse
from Utils.github_workflow_scripts.utils import get_env_var
from slack_sdk import WebClient
from slack_sdk import WebClient as SlackWebClient
from datetime import datetime

GITLAB_SERVER_URL = get_env_var('CI_SERVER_URL', 'https://gitlab.xdr.pan.local') # disable-secrets-detection
Expand All @@ -19,10 +19,6 @@
CONTENT_GITLAB_PROJECT_ID = get_env_var('CI_PROJECT_ID', '1061')


SLACK_TOKEN = get_env_var('SLACK_TOKEN')
SLACK_CHANNEL = get_env_var('WAIT_SLACK_CHANNEL', "dmst-test-wait-in-line")


def send_slack_notification(text: list[str]):
"""
Sends a Slack notification with a list of items.
Expand All @@ -31,10 +27,14 @@ def send_slack_notification(text: list[str]):
text (List[str]): A list of items to be included in the Slack notification.
"""

slack_token = get_env_var('SLACK_TOKEN')
slack_channel = get_env_var('WAIT_SLACK_CHANNEL', "dmst-test-wait-in-line")

text = "\n".join(text)
client = WebClient(token=SLACK_TOKEN)
client = SlackWebClient(token=slack_token)
client.chat_postMessage(
channel=SLACK_CHANNEL,
channel=slack_channel,
text=text
)

Expand Down

0 comments on commit 81a433b

Please sign in to comment.