feat(chalice): changed jira integration

feat(chalice): changed github integration
This commit is contained in:
Taha Yassine Kraiem 2022-09-01 14:34:05 +01:00
parent fdf894f17d
commit 12e3f5f3a5
5 changed files with 37 additions and 11 deletions

View file

@ -7,13 +7,18 @@ class BaseIntegration(ABC):
def __init__(self, user_id, ISSUE_CLASS):
self._user_id = user_id
self.issue_handler = ISSUE_CLASS(self.integration_token)
self.__issue_handler = ISSUE_CLASS(self.integration_token)
@property
@abstractmethod
def provider(self):
pass
@property
@abstractmethod
def issue_handler(self):
pass
@property
def integration_token(self):
integration = self.get()

View file

@ -16,6 +16,10 @@ class GitHubIntegration(integration_base.BaseIntegration):
def provider(self):
return PROVIDER
@property
def issue_handler(self):
return
def get_obfuscated(self):
integration = self.get()
if integration is None:

View file

@ -17,21 +17,29 @@ class JIRAIntegration(integration_base.BaseIntegration):
# super(JIRAIntegration, self).__init__(jwt, user_id, JIRACloudIntegrationProxy)
self._user_id = user_id
self.integration = self.get()
if self.integration is None:
return
self.integration["valid"] = True
try:
self.issue_handler = JIRACloudIntegrationIssue(token=self.integration["token"],
username=self.integration["username"],
url=self.integration["url"])
except Exception as e:
self.issue_handler = None
if not self.integration["url"].endswith('atlassian.net'):
self.integration["valid"] = False
@property
def provider(self):
return PROVIDER
@property
def issue_handler(self):
if self.integration["url"].endswith('atlassian.net') and self.__issue_handler is None:
try:
self.__issue_handler = JIRACloudIntegrationIssue(token=self.integration["token"],
username=self.integration["username"],
url=self.integration["url"])
except Exception as e:
self.__issue_handler = None
self.integration["valid"] = False
return self.__issue_handler
# TODO: remove this once jira-oauth is done
def get(self):
with pg_client.PostgresClient() as cur:
@ -42,7 +50,14 @@ class JIRAIntegration(integration_base.BaseIntegration):
WHERE user_id=%(user_id)s;""",
{"user_id": self._user_id})
)
return helper.dict_to_camel_case(cur.fetchone())
data = helper.dict_to_camel_case(cur.fetchone())
if data is None:
return
data["valid"] = True
if not data["url"].endswith('atlassian.net'):
data["valid"] = False
return data
def get_obfuscated(self):
if self.integration is None:
@ -67,7 +82,7 @@ class JIRAIntegration(integration_base.BaseIntegration):
w = helper.dict_to_camel_case(cur.fetchone())
if obfuscate:
w["token"] = obfuscate_string(w["token"])
return w
return self.get()
# TODO: make this generic for all issue tracking integrations
def _add(self, data):
@ -85,7 +100,7 @@ class JIRAIntegration(integration_base.BaseIntegration):
"token": token, "url": url})
)
w = helper.dict_to_camel_case(cur.fetchone())
return w
return self.get()
def delete(self):
with pg_client.PostgresClient() as cur:

View file

@ -456,6 +456,8 @@ def get_integration_status_github(context: schemas.CurrentContext = Depends(OR_c
@app.put('/integrations/jira', tags=["integrations"])
def add_edit_jira_cloud(data: schemas.JiraSchema = Body(...),
context: schemas.CurrentContext = Depends(OR_context)):
if not data.url.endswith('atlassian.net'):
return {"errors": ["url must be a valid JIRA URL (example.atlassian.net)"]}
error, integration = integrations_manager.get_integration(tool=integration_jira_cloud.PROVIDER,
tenant_id=context.tenant_id,
user_id=context.user_id)

View file

@ -110,7 +110,7 @@ class JiraSchema(GithubSchema):
@validator('url')
def transform_url(cls, v: HttpUrl):
return HttpUrl.build(scheme=v.scheme, host=v.host)
return HttpUrl.build(scheme=v.scheme.lower(), host=v.host.lower())
class CreateEditWebhookSchema(BaseModel):