diff options
Diffstat (limited to 'buildscripts/client/jiraclient.py')
-rw-r--r-- | buildscripts/client/jiraclient.py | 53 |
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 |