提交 21c2e492 编写于 作者: R runzexia 提交者: zryfish

delete user in devops

上级 7748ad8f
......@@ -29,6 +29,8 @@ import (
"kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/models/iam"
"kubesphere.io/kubesphere/pkg/signals"
"kubesphere.io/kubesphere/pkg/simple/client/admin_jenkins"
"kubesphere.io/kubesphere/pkg/simple/client/devops_mysql"
"kubesphere.io/kubesphere/pkg/utils/jwtutil"
"log"
"net/http"
......@@ -69,6 +71,9 @@ func Run(s *options.ServerRunOptions) error {
waitForResourceSync()
initializeAdminJenkins()
initializeDevOpsDatabase()
err = iam.Init(s.AdminEmail, s.AdminPassword, expireTime)
jwtutil.Setup(s.JWTSecret)
......@@ -119,3 +124,11 @@ func waitForResourceSync() {
ksInformerFactory.WaitForCacheSync(stopChan)
log.Println("resources sync success")
}
func initializeAdminJenkins() {
admin_jenkins.Client()
}
func initializeDevOpsDatabase() {
devops_mysql.OpenDatabase()
}
......@@ -1034,6 +1034,22 @@ func (j *Jenkins) AddProjectRole(roleName string, pattern string, ids ProjectPer
return responseRole, nil
}
func (j *Jenkins) DeleteUserInProject(username string) error {
param := map[string]string{
"type": PROJECT_ROLE,
"sid": username,
}
responseString := ""
response,err := j.Requester.Post("/role-strategy/strategy/deleteSid",nil,&responseString,param)
if err != nil {
return err
}
if response.StatusCode != http.StatusOK {
return errors.New(strconv.Itoa(response.StatusCode))
}
return nil
}
func (j *Jenkins) GetQueueItem(number int64) (*QueueItemResponse, error) {
responseItem := &QueueItemResponse{}
response, err := j.Requester.GetJSON(fmt.Sprintf("/queue/item/%s", strconv.FormatInt(number, 10)),
......
......@@ -23,10 +23,14 @@ import (
"fmt"
"io/ioutil"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/db"
"kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/models/devops"
"kubesphere.io/kubesphere/pkg/models/kubeconfig"
"kubesphere.io/kubesphere/pkg/models/kubectl"
"kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/simple/client/admin_jenkins"
"kubesphere.io/kubesphere/pkg/simple/client/devops_mysql"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
"kubesphere.io/kubesphere/pkg/simple/client/redis"
"kubesphere.io/kubesphere/pkg/utils/k8sutil"
......@@ -545,7 +549,27 @@ func DeleteUser(username string) error {
glog.Errorln("delete user terminal pod failed", username, err)
}
devopsDb := devops_mysql.OpenDatabase()
jenkinsClient := admin_jenkins.Client()
_, err = devopsDb.DeleteFrom(devops.DevOpsProjectMembershipTableName).
Where(db.And(
db.Eq(devops.DevOpsProjectMembershipUsernameColumn, username),
)).Exec()
if err != nil {
glog.Errorf("%+v", err)
return err
}
err = jenkinsClient.DeleteUserInProject(username)
if err != nil {
glog.Errorf("%+v", err)
return err
}
return nil
}
func deleteRoleBindings(username string) error {
......
......@@ -30,7 +30,7 @@ var (
)
func init() {
flag.StringVar(&dsn, "devops-database-connection", "root@tcp(127.0.0.1:3306)/devops", "data source name")
flag.StringVar(&dsn, "devops-database-connection", "root:password@tcp(openpitrix-db.openpitrix-system.svc:3306)/devops", "data source name")
}
var defaultEventReceiver = db.EventReceiver{}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册