This commit is contained in:
w-mj 2023-02-23 19:20:56 +08:00
parent e05304b0e3
commit 04b7361df7
No known key found for this signature in database
GPG Key ID: 3A2CB5BE2F835897
5 changed files with 44 additions and 13 deletions

11
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,11 @@
build:
image: docker:latest
stage: build
tags:
- Machine0
only:
- tags
script:
- docker login -u 'robot$gitlab_ci_build' -p $HARBOR_ROBOT docker.educg.net
- docker build -t "docker.educg.net/cg/k8s-manager:$CI_COMMIT_TAG" .
- docker push "docker.educg.net/cg/k8s-manager:$CI_COMMIT_TAG"

View File

@ -1,4 +1,24 @@
FROM alpine:latest
COPY out/manager /manager
FROM golang:1.19.2-alpine as build
WORKDIR /app
ENV GOPROXY=https://proxy.golang.com.cn,direct
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY src ./src
COPY static ./static
COPY template ./template
COPY main.go ./
RUN go build -o manager main.go
FROM alpine:latest as deploy
COPY --from=build /app/manager /manager
RUN chmod +x /manager
EXPOSE 8000
ENTRYPOINT /manager

View File

@ -1,4 +1,4 @@
IMAGE_TAG ?= docker.educg.net/cg/k8s-manager:v1.0.3
IMAGE_TAG ?= docker.educg.net/cg/k8s-manager:v1.0.4
build: export CGO_ENABLED=0
build: export GOOS=linux
@ -6,7 +6,7 @@ build: export GOARCH=amd64
build:
go build -o out/manager main.go
docker: build
docker:
docker build --rm -t $(IMAGE_TAG) .
install: docker

View File

@ -17,7 +17,7 @@ spec:
serviceAccountName: dev
containers:
- name: k8s-manager-pod
image: docker.educg.net/cg/k8s-manager:v1.0.2
image: docker.educg.net/cg/k8s-manager:v1.0.4
ports:
- containerPort: 8080
env:
@ -30,7 +30,7 @@ spec:
- name: DB_PASS
value: 1PQlNf9*9Ulo
- name: JWT_KEY
value: !bd832W0@CG
value: "!bd832W0@CG"
- name: ASE_KEY
value: A5es$&!0GeoEast
---

14
main.go
View File

@ -52,7 +52,7 @@ func main() {
r.POST("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment)
r.DELETE("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment)
r.GET("/login/:username", Test)
r.GET("/login", Test)
r.Any("/test_token", TestToken)
r.GET("/username", m.JWTAuthMiddleware, m.GetUsername)
err := r.Run(":8000")
@ -104,11 +104,11 @@ func generateKey(key []byte) (genKey []byte) {
return genKey
}
func AesDecryptECB(encrypted []byte, key []byte) (decrypted []byte) {
cipher, _ := aes.NewCipher(generateKey(key))
c, _ := aes.NewCipher(key)
decrypted = make([]byte, len(encrypted))
//
for bs, be := 0, cipher.BlockSize(); bs < len(encrypted); bs, be = bs+cipher.BlockSize(), be+cipher.BlockSize() {
cipher.Decrypt(decrypted[bs:be], encrypted[bs:be])
for bs, be := 0, c.BlockSize(); bs < len(encrypted); bs, be = bs+c.BlockSize(), be+c.BlockSize() {
c.Decrypt(decrypted[bs:be], encrypted[bs:be])
}
trim := 0
@ -143,11 +143,11 @@ func AesDecrypt(data []byte, key []byte) ([]byte, error) {
func Test(c *gin.Context) {
//username := c.Param("username")
username, _ := ParseCGToken(c.Request.URL.Query().Get("cgtoken"))
if username == "" {
username, err := ParseCGToken(c.Request.URL.Query().Get("cgtoken"))
if username == "" || err != nil {
c.JSON(http.StatusNotFound, gin.H{
"code": http.StatusNotFound,
"msg": "No user name.",
"msg": "user name error",
})
} else {
token, err := m.GenerateToken(username)