Jcloud Settings增加Git Username和Git Access Token,App source支持gitea私有库克隆
This commit is contained in:
parent
99fa89a1a0
commit
9892c569ac
@ -262,8 +262,18 @@ def branches(owner, name, installation=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_auth_headers(installation_id: str | None = None) -> "dict[str, str]":
|
def get_auth_headers(installation_id: str | None = None) -> "dict[str, str]":
|
||||||
if token := get_access_token(installation_id):
|
settings = jingrow.get_single("Jcloud Settings")
|
||||||
return {"Authorization": f"token {token}"}
|
git_service_type = settings.get("git_service_type") or "gitea"
|
||||||
|
|
||||||
|
if git_service_type.lower() == "gitea":
|
||||||
|
git_access_token = settings.get_password("git_access_token")
|
||||||
|
if git_access_token:
|
||||||
|
return {"Authorization": f"token {git_access_token}"}
|
||||||
|
|
||||||
|
if git_service_type.lower() == "github" and installation_id:
|
||||||
|
if token := get_access_token(installation_id):
|
||||||
|
return {"Authorization": f"token {token}"}
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -237,24 +237,54 @@ class AppSource(Document):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_auth_headers(self) -> dict:
|
def get_auth_headers(self) -> dict:
|
||||||
return get_auth_headers(self.github_installation_id)
|
settings = jingrow.get_single("Jcloud Settings")
|
||||||
|
git_service_type = settings.get("git_service_type") or "gitea"
|
||||||
|
|
||||||
|
if git_service_type.lower() == "gitea":
|
||||||
|
git_access_token = settings.get_password("git_access_token")
|
||||||
|
if git_access_token:
|
||||||
|
return {"Authorization": f"token {git_access_token}"}
|
||||||
|
|
||||||
|
if git_service_type.lower() == "github" and self.github_installation_id:
|
||||||
|
return get_auth_headers(self.github_installation_id)
|
||||||
|
|
||||||
|
return {}
|
||||||
|
|
||||||
def get_access_token(self) -> Optional[str]:
|
def get_access_token(self) -> Optional[str]:
|
||||||
if self.github_installation_id:
|
settings = jingrow.get_single("Jcloud Settings")
|
||||||
|
git_service_type = settings.get("git_service_type") or "gitea"
|
||||||
|
|
||||||
|
if git_service_type.lower() == "gitea":
|
||||||
|
git_access_token = settings.get_password("git_access_token")
|
||||||
|
if git_access_token:
|
||||||
|
return git_access_token
|
||||||
|
|
||||||
|
if git_service_type.lower() == "github" and self.github_installation_id:
|
||||||
return get_access_token(self.github_installation_id)
|
return get_access_token(self.github_installation_id)
|
||||||
|
|
||||||
return jingrow.get_value("Jcloud Settings", None, "github_access_token")
|
return settings.get_password("github_access_token")
|
||||||
|
|
||||||
def get_repo_url(self) -> str:
|
def get_repo_url(self) -> str:
|
||||||
if not self.github_installation_id:
|
settings = jingrow.get_single("Jcloud Settings")
|
||||||
|
if not settings:
|
||||||
return self.repository_url
|
return self.repository_url
|
||||||
|
|
||||||
token = get_access_token(self.github_installation_id)
|
git_service_type = settings.get("git_service_type") or "gitea"
|
||||||
if token is None:
|
|
||||||
# Do not edit without updating deploy_notifications.py
|
if git_service_type.lower() == "gitea":
|
||||||
raise Exception("App installation token could not be fetched", self.app)
|
gite_username = settings.get("gite_username")
|
||||||
|
git_access_token = settings.get_password("git_access_token")
|
||||||
return f"https://x-access-token:{token}@git.jingrow.com/{self.repository_owner}/{self.repository}"
|
if gite_username and git_access_token:
|
||||||
|
return f"http://{gite_username}:{git_access_token}@git.jingrow.com/{self.repository_owner}/{self.repository}"
|
||||||
|
|
||||||
|
if git_service_type.lower() == "github" and self.github_installation_id:
|
||||||
|
token = get_access_token(self.github_installation_id)
|
||||||
|
if token is None:
|
||||||
|
# Do not edit without updating deploy_notifications.py
|
||||||
|
raise Exception("App installation token could not be fetched", self.app)
|
||||||
|
return f"https://x-access-token:{token}@git.jingrow.com/{self.repository_owner}/{self.repository}"
|
||||||
|
|
||||||
|
return self.repository_url
|
||||||
|
|
||||||
def get_gitea_commit_info(self, commit_hash: None | str = None) -> tuple[str, dict, bool]:
|
def get_gitea_commit_info(self, commit_hash: None | str = None) -> tuple[str, dict, bool]:
|
||||||
"""专门处理Gitea API响应的函数"""
|
"""专门处理Gitea API响应的函数"""
|
||||||
|
|||||||
@ -204,8 +204,10 @@
|
|||||||
"infrastructure_tab",
|
"infrastructure_tab",
|
||||||
"git_section",
|
"git_section",
|
||||||
"git_service_type",
|
"git_service_type",
|
||||||
|
"gite_username",
|
||||||
"column_break_jhbn",
|
"column_break_jhbn",
|
||||||
"git_url",
|
"git_url",
|
||||||
|
"git_access_token",
|
||||||
"agent_section",
|
"agent_section",
|
||||||
"agent_repository_owner",
|
"agent_repository_owner",
|
||||||
"agent_sentry_dsn",
|
"agent_sentry_dsn",
|
||||||
@ -1597,11 +1599,21 @@
|
|||||||
"fieldname": "west_api_password",
|
"fieldname": "west_api_password",
|
||||||
"fieldtype": "Password",
|
"fieldtype": "Password",
|
||||||
"label": "West Api Password"
|
"label": "West Api Password"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "gite_username",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Gite Username"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "git_access_token",
|
||||||
|
"fieldtype": "Password",
|
||||||
|
"label": "Git Access Token"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2025-07-31 17:10:00.443783",
|
"modified": "2025-08-21 23:47:53.416916",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Jcloud",
|
"module": "Jcloud",
|
||||||
"name": "Jcloud Settings",
|
"name": "Jcloud Settings",
|
||||||
|
|||||||
@ -80,8 +80,10 @@ class JcloudSettings(Document):
|
|||||||
enforce_storage_limits: DF.Check
|
enforce_storage_limits: DF.Check
|
||||||
free_credits_cny: DF.Currency
|
free_credits_cny: DF.Currency
|
||||||
free_credits_usd: DF.Currency
|
free_credits_usd: DF.Currency
|
||||||
|
git_access_token: DF.Password | None
|
||||||
git_service_type: DF.Literal["gitea", "github"]
|
git_service_type: DF.Literal["gitea", "github"]
|
||||||
git_url: DF.Data | None
|
git_url: DF.Data | None
|
||||||
|
gite_username: DF.Data | None
|
||||||
github_access_token: DF.Data | None
|
github_access_token: DF.Data | None
|
||||||
github_app_client_id: DF.Data | None
|
github_app_client_id: DF.Data | None
|
||||||
github_app_client_secret: DF.Data | None
|
github_app_client_secret: DF.Data | None
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user