* [Feature] Added DevContainer Public Key Login, and deprecated SSH Password login * [Improvement] Anti-spam * GET /api/devstar_ssh/key_pair/new_temp: SSH Keypair Gen * fix HTTP 500 error while deleting Repo * updated DevContainer WorkDIR * updated warn msg
79 lines
2.3 KiB
Go
79 lines
2.3 KiB
Go
package setting
|
||
|
||
import (
|
||
"code.gitea.io/gitea/modules/log"
|
||
)
|
||
|
||
const (
|
||
DEVCONTAINER_AGENT_NAME_K8S string = "k8s"
|
||
DEVCONTAINER_AGENT_NAME_DOCKER string = "docker"
|
||
)
|
||
|
||
// package 内部私有变量,是一个 Set 结构,标识目前系统所有支持的 DevContainer Agent 类型
|
||
var validDevcontainerAgentSet = map[string]struct{}{
|
||
DEVCONTAINER_AGENT_NAME_K8S: {},
|
||
DEVCONTAINER_AGENT_NAME_DOCKER: {},
|
||
}
|
||
|
||
var Devstar = struct {
|
||
Devcontainer DevcontainerType `ini:"devstar.devcontainer"`
|
||
SSHKeypair SSHKeyPairType `ini:"devstar.ssh_key_pair"`
|
||
}{
|
||
Devcontainer: DevcontainerType{
|
||
Enabled: false,
|
||
Namespace: "default",
|
||
TimeoutSeconds: 900, // 最长等待 DevContainer 就绪时间(阻塞式),默认15分钟,可被 app.ini 指定值覆盖
|
||
},
|
||
SSHKeypair: SSHKeyPairType{
|
||
KeySize: 2048,
|
||
},
|
||
}
|
||
|
||
type DevcontainerType struct {
|
||
Enabled bool
|
||
Host string
|
||
Agent string
|
||
Namespace string
|
||
TimeoutSeconds int64
|
||
}
|
||
|
||
type SSHKeyPairType struct {
|
||
KeySize int
|
||
}
|
||
|
||
// validateDevstarDevcontainerSettings 检查从 ini 配置文件中读取 DevStar DevContainer 配置信息,若数据无效,则自动禁用 DevContainer
|
||
func validateDevstarDevcontainerSettings() {
|
||
|
||
// 检查 Host 是否为空,若为空,则自动将 DevContainer 设置为禁用
|
||
if len(Devstar.Devcontainer.Host) == 0 {
|
||
log.Warn("INVALID config 'host' for DevStar DevContainer")
|
||
Devstar.Devcontainer.Enabled = false
|
||
}
|
||
|
||
// 检查用户输入的 DevContainer Agent 是否存在支持列表,若不支持,则将 DevContainer 设置为禁用
|
||
if _, exists := validDevcontainerAgentSet[Devstar.Devcontainer.Agent]; !exists {
|
||
log.Warn("INVALID config 'agent' for DevStar DevContainer")
|
||
Devstar.Devcontainer.Enabled = false
|
||
}
|
||
|
||
if Devstar.Devcontainer.Enabled == false {
|
||
log.Warn("DevStar DevContainer Service Disabled")
|
||
} else {
|
||
log.Info("DevStar DevContainer Service Enabled")
|
||
}
|
||
}
|
||
|
||
// validateDevstarSSHKeyPairSettings 检查从 ini 配置文件中读取 DevStar SSH Key Pair 配置信息
|
||
func validateDevstarSSHKeyPairSettings() {
|
||
if Devstar.SSHKeypair.KeySize < 1024 {
|
||
Devstar.SSHKeypair.KeySize = 1024
|
||
}
|
||
}
|
||
|
||
func loadDevstarFrom(rootCfg ConfigProvider) {
|
||
mustMapSetting(rootCfg, "devstar", &Devstar)
|
||
|
||
validateDevstarDevcontainerSettings()
|
||
validateDevstarSSHKeyPairSettings()
|
||
}
|