Skip to content

Commit ab0949b

Browse files
committed
version update
1 parent daa7f85 commit ab0949b

File tree

9 files changed

+96
-2
lines changed

9 files changed

+96
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.0.43"
9+
version = "2.0.44"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.0.43'
2+
__version__ = '2.0.44'

socketsecurity/plugins/__init__.py

Whitespace-only changes.

socketsecurity/plugins/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Plugin:
2+
def __init__(self, config):
3+
self.config = config
4+
5+
def send(self, message, level):
6+
raise NotImplementedError("Plugin must implement send()")

socketsecurity/plugins/jira.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from .base import Plugin
2+
import requests
3+
import base64
4+
5+
class JiraPlugin(Plugin):
6+
def send(self, message, level):
7+
if not self.config.get("enabled", False):
8+
return
9+
if level not in self.config.get("levels", ["block", "warn"]):
10+
return
11+
12+
url = self.config["url"]
13+
project = self.config["project"]
14+
auth = base64.b64encode(f"{self.config['email']}:{self.config['api_token']}".encode()).decode()
15+
16+
payload = {
17+
"fields": {
18+
"project": {"key": project},
19+
"summary": message.get("title", "No title"),
20+
"description": message.get("description", ""),
21+
"issuetype": {"name": "Task"}
22+
}
23+
}
24+
25+
headers = {
26+
"Authorization": f"Basic {auth}",
27+
"Content-Type": "application/json"
28+
}
29+
30+
requests.post(f"{url}/rest/api/3/issue", json=payload, headers=headers)

socketsecurity/plugins/manager.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from . import jira, webhook, slack, teams
2+
3+
PLUGIN_CLASSES = {
4+
"jira": jira.JiraPlugin,
5+
"slack": slack.SlackPlugin,
6+
"webhook": webhook.WebhookPlugin,
7+
"teams": teams.TeamsPlugin,
8+
}
9+
10+
class PluginManager:
11+
def __init__(self, config):
12+
self.plugins = []
13+
for name, conf in config.items():
14+
if conf.get("enabled"):
15+
plugin_cls = PLUGIN_CLASSES.get(name)
16+
if plugin_cls:
17+
self.plugins.append(plugin_cls(conf))
18+
19+
def send(self, message, level):
20+
for plugin in self.plugins:
21+
plugin.send(message, level)

socketsecurity/plugins/slack.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from .base import Plugin
2+
import requests
3+
4+
class SlackPlugin(Plugin):
5+
def send(self, message, level):
6+
if not self.config.get("enabled", False):
7+
return
8+
if level not in self.config.get("levels", ["block", "warn"]):
9+
return
10+
11+
payload = {"text": message.get("title", "No title")}
12+
requests.post(self.config["webhook_url"], json=payload)

socketsecurity/plugins/teams.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from .base import Plugin
2+
import requests
3+
4+
class TeamsPlugin(Plugin):
5+
def send(self, message, level):
6+
if not self.config.get("enabled", False):
7+
return
8+
if level not in self.config.get("levels", ["block", "warn"]):
9+
return
10+
11+
payload = {"text": message.get("title", "No title")}
12+
requests.post(self.config["webhook_url"], json=payload)

socketsecurity/plugins/webhook.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from .base import Plugin
2+
import requests
3+
4+
class WebhookPlugin(Plugin):
5+
def send(self, message, level):
6+
if not self.config.get("enabled", False):
7+
return
8+
if level not in self.config.get("levels", ["block", "warn"]):
9+
return
10+
11+
url = self.config["url"]
12+
headers = self.config.get("headers", {"Content-Type": "application/json"})
13+
requests.post(url, json=message, headers=headers)

0 commit comments

Comments
 (0)