-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#51
- Loading branch information
Showing
8 changed files
with
228 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/natron-io/tenant-api/util" | ||
) | ||
|
||
// GetCPUQuota returns the CPU quota of a tenant by the label at the tenant config namespace | ||
func GetCPUQuota(c *fiber.Ctx) error { | ||
|
||
util.InfoLogger.Printf("%s %s %s", c.IP(), c.Method(), c.Path()) | ||
tenant := c.Params("tenant") | ||
tenants := CheckAuth(c) | ||
if len(tenants) == 0 { | ||
return c.Status(401).JSON(fiber.Map{ | ||
"message": "Unauthorized", | ||
}) | ||
} | ||
if tenant != "" && !util.Contains(tenant, tenants) { | ||
return c.Status(403).JSON(fiber.Map{ | ||
"message": "Forbidden", | ||
}) | ||
} | ||
|
||
cpuQuota, err := util.GetRessourceQuota(tenant, util.QUOTA_NAMESPACE_SUFFIX, util.QUOTA_CPU_LABEL) | ||
if err != nil { | ||
return c.Status(500).JSON(fiber.Map{ | ||
"message": "Internal Server Error", | ||
}) | ||
} | ||
|
||
return c.JSON(cpuQuota) | ||
} | ||
|
||
// GetMemoryQuota returns the Memory quota of a tenant by the label at the tenant config namespace | ||
func GetMemoryQuota(c *fiber.Ctx) error { | ||
|
||
util.InfoLogger.Printf("%s %s %s", c.IP(), c.Method(), c.Path()) | ||
tenant := c.Params("tenant") | ||
tenants := CheckAuth(c) | ||
if len(tenants) == 0 { | ||
return c.Status(401).JSON(fiber.Map{ | ||
"message": "Unauthorized", | ||
}) | ||
} | ||
if tenant != "" && !util.Contains(tenant, tenants) { | ||
return c.Status(403).JSON(fiber.Map{ | ||
"message": "Forbidden", | ||
}) | ||
} | ||
|
||
memoryQuota, err := util.GetRessourceQuota(tenant, util.QUOTA_NAMESPACE_SUFFIX, util.QUOTA_MEMORY_LABEL) | ||
if err != nil { | ||
return c.Status(500).JSON(fiber.Map{ | ||
"message": "Internal Server Error", | ||
}) | ||
} | ||
|
||
return c.JSON(memoryQuota) | ||
} | ||
|
||
// GetStorageQuota returns the Storage quota of a tenant by the label at the tenant config namespace | ||
func GetStorageQuota(c *fiber.Ctx) error { | ||
|
||
util.InfoLogger.Printf("%s %s %s", c.IP(), c.Method(), c.Path()) | ||
tenant := c.Params("tenant") | ||
tenants := CheckAuth(c) | ||
if len(tenants) == 0 { | ||
return c.Status(401).JSON(fiber.Map{ | ||
"message": "Unauthorized", | ||
}) | ||
} | ||
if tenant != "" && !util.Contains(tenant, tenants) { | ||
return c.Status(403).JSON(fiber.Map{ | ||
"message": "Forbidden", | ||
}) | ||
} | ||
|
||
storageQuota := make(map[string]float64) | ||
var err error | ||
|
||
for key, value := range util.QUOTA_STORAGE_LABEL { | ||
storageQuota[key], err = util.GetRessourceQuota(tenant, util.QUOTA_NAMESPACE_SUFFIX, value) | ||
if err != nil { | ||
return c.Status(500).JSON(fiber.Map{ | ||
"message": "Internal Server Error", | ||
}) | ||
} | ||
} | ||
|
||
return c.JSON(storageQuota) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package util | ||
|
||
var ( | ||
QUOTA_NAMESPACE_SUFFIX string | ||
QUOTA_CPU_LABEL string | ||
QUOTA_MEMORY_LABEL string | ||
QUOTA_STORAGE_LABEL map[string]string | ||
) |