summaryrefslogtreecommitdiff
path: root/buildscripts/client
diff options
context:
space:
mode:
authorDavid Bradford <david.bradford@mongodb.com>2021-12-29 10:57:03 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-30 15:46:42 +0000
commit69a2128b5e82896594aebc18643da2089e196220 (patch)
treee4e8bfc8ff60a4b1146512d0a75c08b46219bf58 /buildscripts/client
parent8e6ab9a259d921298940190161fadfd118c6dc15 (diff)
downloadmongo-69a2128b5e82896594aebc18643da2089e196220.tar.gz
SERVER-62292: Validate commit messages do not reference internal tickets
Diffstat (limited to 'buildscripts/client')
-rw-r--r--buildscripts/client/jiraclient.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/buildscripts/client/jiraclient.py b/buildscripts/client/jiraclient.py
new file mode 100644
index 00000000000..6251d043e25
--- /dev/null
+++ b/buildscripts/client/jiraclient.py
@@ -0,0 +1,53 @@
+"""Module to access a JIRA server."""
+from enum import Enum
+
+import jira
+from pydantic import BaseSettings
+
+
+class SecurityLevel(Enum):
+ """Security level of SERVER tickets."""
+
+ MONGO_INTERNAL = "Mongo Internal"
+ NONE = "None"
+
+
+class JiraAuth(BaseSettings):
+ """OAuth information to connect to Jira."""
+
+ access_token: str
+ access_token_secret: str
+ consumer_key: str
+ key_cert: str
+
+ class Config:
+ """Configuration for JiraAuth."""
+
+ env_prefix = "JIRA_AUTH_"
+
+
+class JiraClient(object):
+ """A client for JIRA."""
+
+ def __init__(self, server: str, jira_auth: JiraAuth) -> None:
+ """
+ Initialize the JiraClient with the server URL and user credentials.
+
+ :param server: Jira Server to connect to.
+ :param jira_auth: OAuth connection information.
+ """
+ opts = {"server": server, "verify": True}
+ self._jira = jira.JIRA(options=opts, oauth=jira_auth.dict(), validate=True)
+
+ def get_ticket_security_level(self, key: str) -> SecurityLevel:
+ """
+ Lookup the security level of the given ticket.
+
+ :param key: Key of ticket to query.
+ :return: Security level of the given ticket.
+ """
+ ticket = self._jira.issue(key)
+ if hasattr(ticket.fields, "security"):
+ security_level = ticket.fields.security
+ return SecurityLevel(security_level.name)
+ return SecurityLevel.NONE