Skip to content

Commit

Permalink
[Controller] additional resource support org
Browse files Browse the repository at this point in the history
  • Loading branch information
askyrie authored and SongZhen0704 committed May 31, 2024
1 parent 01ed7c2 commit b2217a8
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 65 deletions.
4 changes: 2 additions & 2 deletions cli/ctl/domain_additional_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func applyDomainAdditionalResource(cmd *cobra.Command, args []string, filename s

server := common.GetServerInfo(cmd)
url := fmt.Sprintf("http://%s:%d/v1/domain-additional-resources/", server.IP, server.Port)
_, err = common.CURLPerform("PUT", url, body, "", []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd))}...)
_, err = common.CURLPerform("PUT", url, body, "", []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd)), common.WithORGID(common.GetORGID(cmd))}...)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
Expand Down Expand Up @@ -227,7 +227,7 @@ peer_connections:{{ range .PEER_CONNECTIONS }}
func listDomainAdditionalResource(cmd *cobra.Command, resourceType, resourceName string) {
server := common.GetServerInfo(cmd)
url := fmt.Sprintf("http://%s:%d/v1/domain-additional-resources/?type=%s&name=%s", server.IP, server.Port, resourceType, resourceName)
response, err := common.CURLPerform("GET", url, nil, "", []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd))}...)
response, err := common.CURLPerform("GET", url, nil, "", []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd)), common.WithORGID(common.GetORGID(cmd))}...)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
Expand Down
2 changes: 1 addition & 1 deletion server/controller/cloud/sub_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (c *Cloud) getOwnDomainResource() model.Resource {
log.Error(err.Error())
continue
}
mask := net.IPMask(net.ParseIP("s.Netmask").To4())
mask := net.IPMask(net.ParseIP(s.Netmask).To4())
maskSize, _ := mask.Size()
if maskSize == 0 {
log.Errorf("parse netmask (%s) failed", s.Netmask)
Expand Down
36 changes: 30 additions & 6 deletions server/controller/http/router/resource/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,13 @@ func applyDomainAddtionalResource(c *gin.Context) {
return
}

err = resource.ApplyDomainAddtionalResource(data)
db, err := common.GetContextOrgDB(c)
if err != nil {
common.BadRequestResponse(c, httpcommon.GET_ORG_DB_FAIL, err.Error())
return
}

err = resource.ApplyDomainAddtionalResource(data, db)
common.JsonResponse(c, map[string]interface{}{}, err)
}

Expand All @@ -399,7 +405,13 @@ func listDomainAddtionalResource(c *gin.Context) {
return
}

data, err := resource.ListDomainAdditionalResource(resourceType, resourceName)
db, err := common.GetContextOrgDB(c)
if err != nil {
common.BadRequestResponse(c, httpcommon.GET_ORG_DB_FAIL, err.Error())
return
}

data, err := resource.ListDomainAdditionalResource(resourceType, resourceName, db)
common.JsonResponse(c, data, err)
}

Expand All @@ -409,14 +421,20 @@ func GetDomainAdditionalResourceExample(c *gin.Context) {
}

func updateDomainAddtionalResourceAdvanced(c *gin.Context) {
db, err := common.GetContextOrgDB(c)
if err != nil {
common.BadRequestResponse(c, httpcommon.GET_ORG_DB_FAIL, err.Error())
return
}

data := &model.AdditionalResource{}
err := c.ShouldBindBodyWith(&data, binding.YAML)
err = c.ShouldBindBodyWith(&data, binding.YAML)
if err == nil || err == io.EOF {
if err = resource.ApplyDomainAddtionalResource(*data); err != nil {
if err = resource.ApplyDomainAddtionalResource(*data, db); err != nil {
common.JsonResponse(c, httpcommon.SERVER_ERROR, err)
return
}
d, err := resource.GetDomainAdditionalResource("", "")
d, err := resource.GetDomainAdditionalResource("", "", db)
if err != nil {
common.JsonResponse(c, httpcommon.SERVER_ERROR, err)
return
Expand All @@ -434,7 +452,13 @@ func updateDomainAddtionalResourceAdvanced(c *gin.Context) {
}

func getDomainAddtionalResourceAdvanced(c *gin.Context) {
d, err := resource.GetDomainAdditionalResource("", "")
db, err := common.GetContextOrgDB(c)
if err != nil {
common.BadRequestResponse(c, httpcommon.GET_ORG_DB_FAIL, err.Error())
return
}

d, err := resource.GetDomainAdditionalResource("", "", db)
if err != nil {
common.JsonResponse(c, httpcommon.SERVER_ERROR, err)
return
Expand Down
Loading

0 comments on commit b2217a8

Please sign in to comment.