Skip to content

Commit

Permalink
feat: sub domain support update team
Browse files Browse the repository at this point in the history
  • Loading branch information
askyrie authored and SongZhen0704 committed Jul 24, 2024
1 parent 3779179 commit e37a88d
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 26 deletions.
2 changes: 1 addition & 1 deletion server/controller/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func (c *Cloud) runKubernetesGatherTask() {
lcuuid := subDomain.(string)
oldSubDomain := c.kubernetesGatherTaskMap[lcuuid]
newSubDomain := lcuuidToSubDomain[lcuuid]
if oldSubDomain.SubDomainConfig != newSubDomain.Config || oldSubDomain.kubernetesGather.Name != newSubDomain.Name {
if oldSubDomain.SubDomainConfig != newSubDomain.Config || oldSubDomain.kubernetesGather.Name != newSubDomain.Name || oldSubDomain.kubernetesGather.TeamID != newSubDomain.TeamID {
log.Infof("oldSubDomainConfig: %s", oldSubDomain.SubDomainConfig)
log.Infof("newSubDomainConfig: %s", newSubDomain.Config)
c.kubernetesGatherTaskMap[lcuuid].Stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var log = logging.MustGetLogger("cloud.kubernetes_gather")

type KubernetesGather struct {
orgID int
teamID int
TeamID int
Name string
Lcuuid string
UuidGenerate string
Expand Down Expand Up @@ -179,7 +179,7 @@ func NewKubernetesGather(db *mysql.DB, domain *mysql.Domain, subDomain *mysql.Su
Lcuuid: lcuuid,
UuidGenerate: displayName,
ClusterID: clusterID,
teamID: teamID,
TeamID: teamID,
orgID: db.ORGID,
db: db.DB,
RegionUUID: configJson.Get("region_uuid").MustString(),
Expand Down Expand Up @@ -235,7 +235,7 @@ func (k *KubernetesGather) GetStatter() statsd.StatsdStatter {

return statsd.StatsdStatter{
OrgID: k.orgID,
TeamID: k.teamID,
TeamID: k.TeamID,
GlobalTags: globalTags,
Element: statsd.GetCloudStatsd(k.cloudStatsd),
}
Expand Down
4 changes: 3 additions & 1 deletion server/controller/cloud/kubernetes_gather/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package model

import (
"github.com/deepflowio/deepflow/server/controller/cloud/model"
"time"

"github.com/deepflowio/deepflow/server/controller/cloud/model"
)

type KubernetesGatherResource struct {
Expand Down Expand Up @@ -59,6 +60,7 @@ type KubernetesGatherBasicInfo struct {
Name string `json:"name"`
ClusterID string `json:"cluster_id"`
PortNameRegex string `json:"port_name_regex"`
TeamID int `json:"team_id"`
PodNetIPv4CIDRMaxMask int `json:"pod_net_ipv4_cidr_max_mask"`
PodNetIPv6CIDRMaxMask int `json:"pod_net_ipv6_cidr_max_mask"`
Interval time.Duration `json:"interval"`
Expand Down
1 change: 1 addition & 0 deletions server/controller/cloud/kubernetes_gather_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func NewKubernetesGatherTask(
return &KubernetesGatherTask{
basicInfo: kmodel.KubernetesGatherBasicInfo{
Name: kubernetesGather.Name,
TeamID: kubernetesGather.TeamID,
Lcuuid: kubernetesGather.Lcuuid,
ClusterID: kubernetesGather.ClusterID,
PortNameRegex: kubernetesGather.PortNameRegex,
Expand Down
55 changes: 37 additions & 18 deletions server/controller/http/service/permission_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,32 +177,51 @@ func (ra *ResourceAccess) CanUpdateSubDomainResource(domainTeamID, subDomainTeam
if err := PermitVerify(url, ra.userInfo, subDomainTeamID); err != nil {
return err
}

if resourceUp == nil || len(resourceUp) == 0 {
return nil
}

if newOwnerID, ok := resourceUp["owner_user_id"]; ok {
body := map[string]interface{}{
"new_team_id": subDomainTeamID,
"new_owner_id": newOwnerID,
"resource_type": common.SET_RESOURCE_TYPE_SUB_DOMAIN,
"resource_id": resourceUUID,
}
url = fmt.Sprintf(urlUGCPermission, ra.fpermit.Host, ra.fpermit.Port, ra.userInfo.ORGID)
if err := ugcPermission(url, ra.userInfo, body); err != nil {
var newTeamID int = subDomainTeamID
teamID, tOK := resourceUp["team_id"]
if tOK {
newTeamID = int(teamID.(float64))
url := fmt.Sprintf(urlPermitVerify, ra.fpermit.Host, ra.fpermit.Port, ra.userInfo.ORGID, AccessAdd)
url += fmt.Sprintf("&parent_team_id=%d&team_id=%d", domainTeamID, newTeamID)
if err := PermitVerify(url, ra.userInfo, newTeamID); err != nil {
return err
}
}
return nil

url = fmt.Sprintf(urlResource, ra.fpermit.Host, ra.fpermit.Port, ra.userInfo.ORGID)
body := map[string]interface{}{
"resource_where": map[string]interface{}{
"resource_type": common.SET_RESOURCE_TYPE_SUB_DOMAIN,
"resource_id": resourceUUID,
},
"resource_up": resourceUp,
}
return resourceVerify(url, http.MethodPatch, ra.userInfo, domainTeamID, body)
// TODO: support update
// var newOwnerID int = ra.userInfo.ID
// userID, uOK := resourceUp["owner_user_id"]
// if uOK {
// newOwnerID = int(userID.(float64))
// }
// if tOK || uOK {
// body := map[string]interface{}{
// "new_team_id": newTeamID,
// "new_owner_id": newOwnerID,
// "resource_type": common.SET_RESOURCE_TYPE_SUB_DOMAIN,
// "resource_id": resourceUUID,
// }
// url = fmt.Sprintf(urlUGCPermission, ra.fpermit.Host, ra.fpermit.Port, ra.userInfo.ORGID)
// if err := ugcPermission(url, ra.userInfo, body); err != nil {
// return err
// }
// }

// url = fmt.Sprintf(urlResource, ra.fpermit.Host, ra.fpermit.Port, ra.userInfo.ORGID)
// body := map[string]interface{}{
// "resource_where": map[string]interface{}{
// "resource_type": common.SET_RESOURCE_TYPE_SUB_DOMAIN,
// "resource_id": resourceUUID,
// },
// "resource_up": resourceUp,
// }
// return resourceVerify(url, http.MethodPatch, ra.userInfo, domainTeamID, body)
}

func (ra *ResourceAccess) CanDeleteSubDomainResource(domainTeamID, subDomainTeamID int, resourceUUID string) error {
Expand Down
10 changes: 7 additions & 3 deletions server/controller/http/service/resource/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,9 +888,13 @@ func UpdateSubDomain(lcuuid string, db *mysql.DB, userInfo *httpcommon.UserInfo,
var subDomain mysql.SubDomain
var dbUpdateMap = make(map[string]interface{})
var resourceUp = make(map[string]interface{})
if userID, ok := subDomainUpdate["USER_ID"]; ok {
dbUpdateMap["user_id"] = userID
resourceUp["owner_user_id"] = userID
// if userID, ok := subDomainUpdate["USER_ID"]; ok {
// dbUpdateMap["user_id"] = userID
// resourceUp["owner_user_id"] = userID
// }
if teamID, ok := subDomainUpdate["TEAM_ID"]; ok {
dbUpdateMap["team_id"] = teamID
resourceUp["team_id"] = teamID
}

if ret := db.Where("lcuuid = ?", lcuuid).First(&subDomain); ret.Error != nil {
Expand Down
1 change: 1 addition & 0 deletions server/controller/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ type SubDomainCreate struct {
}

type SubDomainUpdate struct {
TeamID int `json:"TEAM_ID"`
UserID int `json:"USER_ID"`
Config map[string]interface{} `json:"CONFIG"`
}
Expand Down

0 comments on commit e37a88d

Please sign in to comment.