feat(api): changed jira integration
feat(api): changed github integration
This commit is contained in:
parent
6930b71c5f
commit
245af37291
4 changed files with 26 additions and 13 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from abc import ABC, abstractmethod
|
||||
|
||||
from chalicelib.utils import pg_client, helper
|
||||
|
||||
|
||||
|
|
@ -37,7 +38,7 @@ class BaseIntegration(ABC):
|
|||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update(self, changes):
|
||||
def update(self, changes, obfuscate=False):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from chalicelib.utils import pg_client, helper
|
||||
from chalicelib.core.integration_github_issue import GithubIntegrationIssue
|
||||
from chalicelib.core import integration_base
|
||||
from chalicelib.core.integration_github_issue import GithubIntegrationIssue
|
||||
from chalicelib.utils import pg_client, helper
|
||||
|
||||
PROVIDER = "GITHUB"
|
||||
|
||||
|
|
@ -15,8 +15,6 @@ class GitHubIntegration(integration_base.BaseIntegration):
|
|||
def provider(self):
|
||||
return PROVIDER
|
||||
|
||||
|
||||
|
||||
def get_obfuscated(self):
|
||||
integration = self.get()
|
||||
if integration is None:
|
||||
|
|
@ -24,7 +22,7 @@ class GitHubIntegration(integration_base.BaseIntegration):
|
|||
token = "*" * (len(integration["token"]) - 4) + integration["token"][-4:]
|
||||
return {"token": token, "provider": self.provider.lower()}
|
||||
|
||||
def update(self, changes):
|
||||
def update(self, changes, obfuscate=False):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
sub_query = [f"{helper.key_to_snake_case(k)} = %({k})s" for k in changes.keys()]
|
||||
cur.execute(
|
||||
|
|
@ -71,8 +69,11 @@ class GitHubIntegration(integration_base.BaseIntegration):
|
|||
if s is not None:
|
||||
return self.update(
|
||||
changes={
|
||||
"token": data["token"]
|
||||
}
|
||||
"token": data["token"] \
|
||||
if data.get("token") and len(data["token"]) > 0 and data["token"].find("***") == -1 \
|
||||
else s["token"]
|
||||
},
|
||||
obfuscate=True
|
||||
)
|
||||
else:
|
||||
return self.add(token=data["token"])
|
||||
|
|
|
|||
|
|
@ -5,6 +5,10 @@ from chalicelib.utils import pg_client, helper
|
|||
PROVIDER = "JIRA"
|
||||
|
||||
|
||||
def obfuscate_string(string):
|
||||
return "*" * (len(string) - 4) + string[-4:]
|
||||
|
||||
|
||||
class JIRAIntegration(integration_base.BaseIntegration):
|
||||
def __init__(self, tenant_id, user_id):
|
||||
self.__tenant_id = tenant_id
|
||||
|
|
@ -36,11 +40,11 @@ class JIRAIntegration(integration_base.BaseIntegration):
|
|||
integration = self.get()
|
||||
if integration is None:
|
||||
return None
|
||||
integration["token"] = "*" * (len(integration["token"]) - 4) + integration["token"][-4:]
|
||||
integration["token"] = obfuscate_string(integration["token"])
|
||||
integration["provider"] = self.provider.lower()
|
||||
return integration
|
||||
|
||||
def update(self, changes):
|
||||
def update(self, changes, obfuscate=False):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
sub_query = [f"{helper.key_to_snake_case(k)} = %({k})s" for k in changes.keys()]
|
||||
cur.execute(
|
||||
|
|
@ -53,6 +57,8 @@ class JIRAIntegration(integration_base.BaseIntegration):
|
|||
**changes})
|
||||
)
|
||||
w = helper.dict_to_camel_case(cur.fetchone())
|
||||
if obfuscate:
|
||||
w["token"] = obfuscate_string(w["token"])
|
||||
return w
|
||||
|
||||
# TODO: make this generic for all issue tracking integrations
|
||||
|
|
@ -93,7 +99,8 @@ class JIRAIntegration(integration_base.BaseIntegration):
|
|||
if data.get("token") and len(data["token"]) > 0 and data["token"].find("***") == -1 \
|
||||
else s["token"],
|
||||
"url": data["url"]
|
||||
}
|
||||
},
|
||||
obfuscate=True
|
||||
)
|
||||
else:
|
||||
return self.add(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from enum import Enum
|
||||
from typing import Optional, List, Union, Literal
|
||||
|
||||
from pydantic import BaseModel, Field, EmailStr, HttpUrl, root_validator
|
||||
from pydantic import BaseModel, Field, EmailStr, HttpUrl, root_validator, validator
|
||||
|
||||
from chalicelib.utils.TimeUTC import TimeUTC
|
||||
|
||||
|
|
@ -107,7 +107,11 @@ class JiraGithubSchema(BaseModel):
|
|||
provider: str = Field(...)
|
||||
username: str = Field(...)
|
||||
token: str = Field(...)
|
||||
url: str = Field(...)
|
||||
url: HttpUrl = Field(...)
|
||||
|
||||
@validator('url')
|
||||
def transform_url(cls, v: HttpUrl):
|
||||
return HttpUrl.build(scheme=v.scheme, host=v.host)
|
||||
|
||||
|
||||
class CreateEditWebhookSchema(BaseModel):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue