This commit is contained in:
w-mj 2023-02-28 15:02:06 +08:00
parent ae28a70c71
commit ac7329479f
No known key found for this signature in database
GPG Key ID: 3A2CB5BE2F835897
3 changed files with 34 additions and 19 deletions

View File

@ -37,6 +37,14 @@ spec:
value: 192.168.252.250 value: 192.168.252.250
- name: NFS_PATH - name: NFS_PATH
value: /mnt/CGdata/ms value: /mnt/CGdata/ms
volumeMounts:
- name: k8s-manager-nfs-volume
mountPath: /mnt/CGdata/ms
volumes:
- name: k8s-manager-nfs-volume
nfs:
server: 192.168.252.250
path: /mnt/CGdata/ms
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service

42
main.go
View File

@ -41,7 +41,7 @@ func main() {
r.POST("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment) r.POST("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment)
r.DELETE("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment) r.DELETE("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment)
r.GET("/login", Test) r.GET("/login", LoginToken)
r.Any("/test_token", TestToken) r.Any("/test_token", TestToken)
r.GET("/username", m.JWTAuthMiddleware, m.GetUsername) r.GET("/username", m.JWTAuthMiddleware, m.GetUsername)
err := r.Run(":8000") err := r.Run(":8000")
@ -135,7 +135,7 @@ func AesDecrypt(data []byte, key []byte) ([]byte, error) {
return crypted, nil return crypted, nil
} }
func Test(c *gin.Context) { func LoginToken(c *gin.Context) {
username := c.Request.URL.Query().Get("username") username := c.Request.URL.Query().Get("username")
var err error var err error
if username == "" { if username == "" {
@ -147,26 +147,30 @@ func Test(c *gin.Context) {
"msg": "user name error", "msg": "user name error",
}) })
} else { } else {
token, err := m.GenerateToken(username) Login(c, username)
if err != nil {
log.Error(err)
c.Abort()
return
}
log.WithField("user name", username).Info("Login success.")
c.SetCookie("Authorization", "Bearer "+token, 0, "", "", false, false)
c.Header("Authorization", "Bearer "+token)
c.Header("Cache-Control", "no-store")
redirectUrl := ""
if os.Getenv("URL_PREFIX") == "" {
redirectUrl = "/index"
} else {
redirectUrl = fmt.Sprintf("/%s/index", os.Getenv("URL_PREFIX"))
}
c.Redirect(http.StatusTemporaryRedirect, redirectUrl)
} }
} }
func Login(c *gin.Context, username string) {
token, err := m.GenerateToken(username)
if err != nil {
log.Error(err)
c.Abort()
return
}
log.WithField("user name", username).Info("Login success.")
c.SetCookie("Authorization", "Bearer "+token, 0, "", "", false, false)
c.Header("Authorization", "Bearer "+token)
c.Header("Cache-Control", "no-store")
redirectUrl := ""
if os.Getenv("URL_PREFIX") == "" {
redirectUrl = "/index"
} else {
redirectUrl = fmt.Sprintf("/%s/index", os.Getenv("URL_PREFIX"))
}
c.Redirect(http.StatusTemporaryRedirect, redirectUrl)
}
func TestToken(c *gin.Context) { func TestToken(c *gin.Context) {
token := c.Request.URL.Query().Get("cgtoken") token := c.Request.URL.Query().Get("cgtoken")
if token == "" { if token == "" {

View File

@ -74,6 +74,9 @@ func (c *K8sClient) DeploymentExists(deploymentName string) bool {
func (c *K8sClient) UpdateDeployment(app *AppModel) { func (c *K8sClient) UpdateDeployment(app *AppModel) {
labelKey, labelValue := app.GetLabel() labelKey, labelValue := app.GetLabel()
l := map[string]string{labelKey: labelValue} l := map[string]string{labelKey: labelValue}
if _, err := os.Stat(app.NFSPath()); os.IsNotExist(err) {
os.MkdirAll(app.NFSPath(), os.ModeDir)
}
podLabels := map[string]string{ podLabels := map[string]string{
labelKey: labelValue, labelKey: labelValue,
"cg-deployment": app.DeploymentName(), "cg-deployment": app.DeploymentName(),