mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-10 16:22:38 +02:00
Revert "feat: implement Jira OAuth integration and connector routes"
This reverts commit bfed9a31f8.
This commit is contained in:
parent
bfed9a31f8
commit
f236110a08
14 changed files with 522 additions and 845 deletions
|
|
@ -3,7 +3,6 @@ Jira Connector Module
|
|||
|
||||
A module for retrieving data from Jira.
|
||||
Allows fetching issue lists and their comments, projects and more.
|
||||
Supports both OAuth 2.0 (preferred) and legacy API token authentication.
|
||||
"""
|
||||
|
||||
import base64
|
||||
|
|
@ -19,8 +18,6 @@ class JiraConnector:
|
|||
def __init__(
|
||||
self,
|
||||
base_url: str | None = None,
|
||||
access_token: str | None = None,
|
||||
cloud_id: str | None = None,
|
||||
email: str | None = None,
|
||||
api_token: str | None = None,
|
||||
):
|
||||
|
|
@ -28,39 +25,18 @@ class JiraConnector:
|
|||
Initialize the JiraConnector class.
|
||||
|
||||
Args:
|
||||
base_url: Jira instance base URL (e.g., 'https://yourcompany.atlassian.net')
|
||||
access_token: OAuth 2.0 access token (preferred method)
|
||||
cloud_id: Atlassian cloud ID (used with OAuth for API URL construction)
|
||||
email: Jira account email address (legacy method, used with api_token)
|
||||
api_token: Jira API token (legacy method, used with email)
|
||||
base_url: Jira instance base URL (e.g., 'https://yourcompany.atlassian.net') (optional)
|
||||
email: Jira account email address (optional)
|
||||
api_token: Jira API token (optional)
|
||||
"""
|
||||
self.base_url = base_url.rstrip("/") if base_url else None
|
||||
self.access_token = access_token
|
||||
self.cloud_id = cloud_id
|
||||
self.email = email
|
||||
self.api_token = api_token
|
||||
self.api_version = "3" # Jira Cloud API version
|
||||
self._use_oauth = access_token is not None
|
||||
|
||||
def set_oauth_credentials(
|
||||
self, base_url: str, access_token: str, cloud_id: str | None = None
|
||||
) -> None:
|
||||
"""
|
||||
Set OAuth 2.0 credentials (preferred method).
|
||||
|
||||
Args:
|
||||
base_url: Jira instance base URL
|
||||
access_token: OAuth 2.0 access token
|
||||
cloud_id: Atlassian cloud ID (optional, used for API URL construction)
|
||||
"""
|
||||
self.base_url = base_url.rstrip("/")
|
||||
self.access_token = access_token
|
||||
self.cloud_id = cloud_id
|
||||
self._use_oauth = True
|
||||
|
||||
def set_credentials(self, base_url: str, email: str, api_token: str) -> None:
|
||||
"""
|
||||
Set the Jira credentials (legacy method using API token).
|
||||
Set the Jira credentials.
|
||||
|
||||
Args:
|
||||
base_url: Jira instance base URL
|
||||
|
|
@ -70,69 +46,50 @@ class JiraConnector:
|
|||
self.base_url = base_url.rstrip("/")
|
||||
self.email = email
|
||||
self.api_token = api_token
|
||||
self._use_oauth = False
|
||||
|
||||
def set_email(self, email: str) -> None:
|
||||
"""
|
||||
Set the Jira account email (legacy method).
|
||||
Set the Jira account email.
|
||||
|
||||
Args:
|
||||
email: Jira account email address
|
||||
"""
|
||||
self.email = email
|
||||
self._use_oauth = False
|
||||
|
||||
def set_api_token(self, api_token: str) -> None:
|
||||
"""
|
||||
Set the Jira API token (legacy method).
|
||||
Set the Jira API token.
|
||||
|
||||
Args:
|
||||
api_token: Jira API token
|
||||
"""
|
||||
self.api_token = api_token
|
||||
self._use_oauth = False
|
||||
|
||||
def get_headers(self) -> dict[str, str]:
|
||||
"""
|
||||
Get headers for Jira API requests.
|
||||
|
||||
Uses OAuth Bearer token if available, otherwise falls back to Basic Auth.
|
||||
Get headers for Jira API requests using Basic Authentication.
|
||||
|
||||
Returns:
|
||||
Dictionary of headers
|
||||
|
||||
Raises:
|
||||
ValueError: If credentials have not been set
|
||||
ValueError: If email, api_token, or base_url have not been set
|
||||
"""
|
||||
if self._use_oauth:
|
||||
# OAuth 2.0 authentication
|
||||
if not self.base_url or not self.access_token:
|
||||
raise ValueError(
|
||||
"Jira OAuth credentials not initialized. Call set_oauth_credentials() first."
|
||||
)
|
||||
if not all([self.base_url, self.email, self.api_token]):
|
||||
raise ValueError(
|
||||
"Jira credentials not initialized. Call set_credentials() first."
|
||||
)
|
||||
|
||||
return {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {self.access_token}",
|
||||
"Accept": "application/json",
|
||||
}
|
||||
else:
|
||||
# Legacy Basic Auth
|
||||
if not all([self.base_url, self.email, self.api_token]):
|
||||
raise ValueError(
|
||||
"Jira credentials not initialized. Call set_credentials() first."
|
||||
)
|
||||
# Create Basic Auth header using email:api_token
|
||||
auth_str = f"{self.email}:{self.api_token}"
|
||||
auth_bytes = auth_str.encode("utf-8")
|
||||
auth_header = "Basic " + base64.b64encode(auth_bytes).decode("ascii")
|
||||
|
||||
# Create Basic Auth header using email:api_token
|
||||
auth_str = f"{self.email}:{self.api_token}"
|
||||
auth_bytes = auth_str.encode("utf-8")
|
||||
auth_header = "Basic " + base64.b64encode(auth_bytes).decode("ascii")
|
||||
|
||||
return {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": auth_header,
|
||||
"Accept": "application/json",
|
||||
}
|
||||
return {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": auth_header,
|
||||
"Accept": "application/json",
|
||||
}
|
||||
|
||||
def make_api_request(
|
||||
self,
|
||||
|
|
@ -147,25 +104,21 @@ class JiraConnector:
|
|||
Args:
|
||||
endpoint: API endpoint (without base URL)
|
||||
params: Query parameters for the request (optional)
|
||||
method: HTTP method (GET or POST)
|
||||
json_payload: JSON payload for POST requests (optional)
|
||||
|
||||
Returns:
|
||||
Response data from the API
|
||||
|
||||
Raises:
|
||||
ValueError: If credentials have not been set
|
||||
ValueError: If email, api_token, or base_url have not been set
|
||||
Exception: If the API request fails
|
||||
"""
|
||||
headers = self.get_headers()
|
||||
if not all([self.base_url, self.email, self.api_token]):
|
||||
raise ValueError(
|
||||
"Jira credentials not initialized. Call set_credentials() first."
|
||||
)
|
||||
|
||||
# Construct API URL based on authentication method
|
||||
if self._use_oauth and self.cloud_id:
|
||||
# Use Atlassian API gateway with cloud_id for OAuth
|
||||
url = f"https://api.atlassian.com/ex/jira/{self.cloud_id}/rest/api/{self.api_version}/{endpoint}"
|
||||
else:
|
||||
# Use direct base URL (works for both OAuth and legacy)
|
||||
url = f"{self.base_url}/rest/api/{self.api_version}/{endpoint}"
|
||||
url = f"{self.base_url}/rest/api/{self.api_version}/{endpoint}"
|
||||
headers = self.get_headers()
|
||||
|
||||
if method.upper() == "POST":
|
||||
response = requests.post(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue