From 35df63664ec6b0ac8b85938399640cdf01d5e4a3 Mon Sep 17 00:00:00 2001 From: "xiaozhe.ma" Date: Mon, 5 Aug 2024 19:26:31 +0900 Subject: [PATCH] =?UTF-8?q?feat:kintone=20API=E3=81=AE=E3=83=91=E3=82=B9?= =?UTF-8?q?=E3=83=AF=E3=83=BC=E3=83=89=E3=81=AE=E6=9A=97=E5=8F=B7=E5=8C=96?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/core/config.py | 2 +- backend/app/db/crud.py | 13 ++++++------- backend/app/db/models.py | 5 +++++ backend/app/db/schemas.py | 1 - 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/app/core/config.py b/backend/app/core/config.py index ecee426..c644f96 100644 --- a/backend/app/core/config.py +++ b/backend/app/core/config.py @@ -38,4 +38,4 @@ class KINTONE_ENV: self.DOMAIN_ID=domain.id self.BASE_URL = domain.url self.KINTONE_USER = domain.kintoneuser - self.API_V1_AUTH_VALUE = base64.b64encode(bytes(f"{domain.kintoneuser}:{domain.kintonepwd}","utf-8")) \ No newline at end of file + self.API_V1_AUTH_VALUE = base64.b64encode(bytes(f"{domain.kintoneuser}:{domain.decrypt_kintonepwd()}","utf-8")) \ No newline at end of file diff --git a/backend/app/db/crud.py b/backend/app/db/crud.py index b68beb0..0ee5161 100644 --- a/backend/app/db/crud.py +++ b/backend/app/db/crud.py @@ -266,19 +266,18 @@ def get_domain(db: Session, userid: str): domains = db.query(models.Domain).join(models.UserDomain,models.UserDomain.domainid == models.Domain.id ).filter(models.UserDomain.userid == userid).all() if not domains: raise HTTPException(status_code=404, detail="Data not found") - for domain in domains: - decrypted_pwd = chacha20Decrypt(domain.kintonepwd) - domain.kintonepwd = decrypted_pwd - + # for domain in domains: + # decrypted_pwd = chacha20Decrypt(domain.kintonepwd) + # domain.kintonepwd = decrypted_pwd return domains def get_domains(db: Session,tenantid:str): domains = db.query(models.Domain).filter(models.Domain.tenantid == tenantid ).all() if not domains: raise HTTPException(status_code=404, detail="Data not found") - for domain in domains: - decrypted_pwd = chacha20Decrypt(domain.kintonepwd) - domain.kintonepwd = decrypted_pwd + # for domain in domains: + # decrypted_pwd = chacha20Decrypt(domain.kintonepwd) + # domain.kintonepwd = decrypted_pwd return domains def get_events(db: Session): diff --git a/backend/app/db/models.py b/backend/app/db/models.py index c0876d5..ed5bae9 100644 --- a/backend/app/db/models.py +++ b/backend/app/db/models.py @@ -2,6 +2,8 @@ from sqlalchemy import Boolean, Column, Integer, String, DateTime,ForeignKey from sqlalchemy.ext.declarative import as_declarative from datetime import datetime +from app.core.security import chacha20Decrypt + @as_declarative() class Base: id = Column(Integer, primary_key=True, index=True) @@ -68,6 +70,9 @@ class Domain(Base): url = Column(String(200), nullable=False) kintoneuser = Column(String(100), nullable=False) kintonepwd = Column(String(100), nullable=False) + def decrypt_kintonepwd(self): + decrypted_pwd = chacha20Decrypt(self.kintonepwd) + return decrypted_pwd class UserDomain(Base): diff --git a/backend/app/db/schemas.py b/backend/app/db/schemas.py index f896c96..08beedf 100644 --- a/backend/app/db/schemas.py +++ b/backend/app/db/schemas.py @@ -131,7 +131,6 @@ class Domain(Base): url: str kintoneuser: str kintonepwd: str - class Config: orm_mode = True