Skip to content

Commit

Permalink
Fix bug on fetching guardrail rules to scope resources to organization (
Browse files Browse the repository at this point in the history
#536)

[gateway] Update openapi docs
[gateway] Add description attribute to guardrails resource
  • Loading branch information
sandromello authored Nov 6, 2024
1 parent 333cab1 commit f728cdd
Show file tree
Hide file tree
Showing 11 changed files with 727 additions and 105 deletions.
10 changes: 5 additions & 5 deletions gateway/api/connections/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ func Delete(c *gin.Context) {
// @Description List all connections.
// @Tags Core
// @Produce json
// @Param agent_id query string false "Filter by agent id" Format(uuid)
// @Param tags query array false "Filter by tags" Format(array)
// @Param type query string false "Filter by type" Format(string)
// @Param subtype query string false "Filter by subtype" Format(string)
// @Param managed_by query string false "Filter by managed by" Format(string)
// @Param agent_id query string false "Filter by agent id" Format(uuid)
// @Param tags query string false "Filter by tags, separated by comma" Format(string)
// @Param type query string false "Filter by type" Format(string)
// @Param subtype query string false "Filter by subtype" Format(string)
// @Param managed_by query string false "Filter by managed by" Format(string)
// @Success 200 {array} openapi.Connection
// @Failure 422,500 {object} openapi.HTTPError
// @Router /connections [get]
Expand Down
110 changes: 57 additions & 53 deletions gateway/api/guardrails/guardrails.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
// @Tags Core
// @Accept json
// @Produce json
// @Param request body openapi.GuardRailRule true "The request body resource"
// @Success 201 {object} openapi.GuardRailRule
// @Param request body openapi.GuardRailRuleRequest true "The request body resource"
// @Success 201 {object} openapi.GuardRailRuleResponse
// @Failure 400,409,500 {object} openapi.HTTPError
// @Router /guardrail-rules [post]
// @Router /guardrails [post]
func Post(c *gin.Context) {
ctx := storagev2.ParseContext(c)
req := parseRequestPayload(c)
Expand All @@ -31,26 +31,28 @@ func Post(c *gin.Context) {
}

rule := &models.GuardRailRules{
ID: uuid.NewString(),
OrgID: ctx.GetOrgID(),
Name: req.Name,
Input: req.Input,
Output: req.Output,
CreatedAt: time.Now().UTC(),
UpdatedAt: time.Now().UTC(),
ID: uuid.NewString(),
OrgID: ctx.GetOrgID(),
Name: req.Name,
Description: req.Description,
Input: req.Input,
Output: req.Output,
CreatedAt: time.Now().UTC(),
UpdatedAt: time.Now().UTC(),
}
err := models.CreateGuardRailRules(rule)
switch err {
case models.ErrAlreadyExists:
c.JSON(http.StatusConflict, gin.H{"message": err.Error()})
case nil:
c.JSON(http.StatusOK, &openapi.GuardRailRuleResponse{
ID: rule.ID,
Name: rule.Name,
Input: rule.Input,
Output: rule.Output,
CreatedAt: rule.CreatedAt,
UpdatedAt: rule.UpdatedAt,
ID: rule.ID,
Name: rule.Name,
Description: rule.Description,
Input: rule.Input,
Output: rule.Output,
CreatedAt: rule.CreatedAt,
UpdatedAt: rule.UpdatedAt,
})
default:
log.Errorf("failed creting guard rail rule, reason=%v, err=%T", err, err)
Expand All @@ -65,23 +67,24 @@ func Post(c *gin.Context) {
// @Tags Core
// @Accept json
// @Produce json
// @Param request body openapi.GuardRailRule true "The request body resource"
// @Success 200 {object} openapi.GuardRailRule
// @Param request body openapi.GuardRailRuleRequest true "The request body resource"
// @Success 200 {object} openapi.GuardRailRuleResponse
// @Failure 400,500 {object} openapi.HTTPError
// @Router /guardrail-rules/{id} [put]
// @Router /guardrails/{id} [put]
func Put(c *gin.Context) {
ctx := storagev2.ParseContext(c)
req := parseRequestPayload(c)
if req == nil {
return
}
rule := &models.GuardRailRules{
OrgID: ctx.GetOrgID(),
ID: c.Param("id"),
Name: req.Name,
Input: req.Input,
Output: req.Output,
UpdatedAt: time.Now().UTC(),
OrgID: ctx.GetOrgID(),
ID: c.Param("id"),
Name: req.Name,
Description: req.Description,
Input: req.Input,
Output: req.Output,
UpdatedAt: time.Now().UTC(),
}
err := models.UpdateGuardRailRules(rule)
switch err {
Expand All @@ -90,12 +93,13 @@ func Put(c *gin.Context) {
return
case nil:
c.JSON(http.StatusOK, &openapi.GuardRailRuleResponse{
ID: rule.ID,
Name: rule.Name,
Input: rule.Input,
Output: rule.Output,
CreatedAt: rule.CreatedAt,
UpdatedAt: rule.UpdatedAt,
ID: rule.ID,
Name: rule.Name,
Description: rule.Description,
Input: rule.Input,
Output: rule.Output,
CreatedAt: rule.CreatedAt,
UpdatedAt: rule.UpdatedAt,
})
default:
log.Errorf("failed updating guard rail rule, reason=%v", err)
Expand All @@ -110,10 +114,9 @@ func Put(c *gin.Context) {
// @Tags Core
// @Accept json
// @Produce json
// @Param request body openapi.GuardRailRule true "The request body resource"
// @Success 200 {array} openapi.GuardRailRule
// @Failure 500 {object} openapi.HTTPError
// @Router /guardrail-rules [get]
// @Success 200 {array} openapi.GuardRailRuleResponse
// @Failure 500 {object} openapi.HTTPError
// @Router /guardrails [get]
func List(c *gin.Context) {
ctx := storagev2.ParseContext(c)
ruleList, err := models.ListGuardRailRules(ctx.GetOrgID())
Expand All @@ -122,15 +125,16 @@ func List(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
return
}
var rules []openapi.GuardRailRuleResponse
rules := []openapi.GuardRailRuleResponse{}
for _, rule := range ruleList {
rules = append(rules, openapi.GuardRailRuleResponse{
ID: rule.ID,
Name: rule.Name,
Input: rule.Input,
Output: rule.Output,
CreatedAt: rule.CreatedAt,
UpdatedAt: rule.UpdatedAt,
ID: rule.ID,
Name: rule.Name,
Description: rule.Description,
Input: rule.Input,
Output: rule.Output,
CreatedAt: rule.CreatedAt,
UpdatedAt: rule.UpdatedAt,
})
}
c.JSON(http.StatusOK, rules)
Expand All @@ -143,11 +147,10 @@ func List(c *gin.Context) {
// @Tags Core
// @Accept json
// @Produce json
// @Param id path string true "The unique identifier of the resource"
// @Param request body openapi.GuardRailRule true "The request body resource"
// @Success 200 {object} openapi.GuardRailRule
// @Param id path string true "The unique identifier of the resource"
// @Success 200 {object} openapi.GuardRailRuleResponse
// @Failure 400,404,500 {object} openapi.HTTPError
// @Router /guardrail-rules/{id} [get]
// @Router /guardrails/{id} [get]
func Get(c *gin.Context) {
ctx := storagev2.ParseContext(c)
rule, err := models.GetGuardRailRules(ctx.GetOrgID(), c.Param("id"))
Expand All @@ -156,12 +159,13 @@ func Get(c *gin.Context) {
c.JSON(http.StatusNotFound, gin.H{"message": "resource not found"})
case nil:
c.JSON(http.StatusOK, &openapi.GuardRailRuleResponse{
ID: rule.ID,
Name: rule.Name,
Input: rule.Input,
Output: rule.Output,
CreatedAt: rule.CreatedAt,
UpdatedAt: rule.UpdatedAt,
ID: rule.ID,
Name: rule.Name,
Description: rule.Description,
Input: rule.Input,
Output: rule.Output,
CreatedAt: rule.CreatedAt,
UpdatedAt: rule.UpdatedAt,
})
default:
log.Errorf("failed listing guard rail rules, reason=%v", err)
Expand All @@ -178,7 +182,7 @@ func Get(c *gin.Context) {
// @Param id path string true "The unique identifier of the resource"
// @Success 204
// @Failure 404,500 {object} openapi.HTTPError
// @Router /guardrail-rules/{id} [delete]
// @Router /guardrails/{id} [delete]
func Delete(c *gin.Context) {
ctx := storagev2.ParseContext(c)
err := models.DeleteGuardRailRules(ctx.GetOrgID(), c.Param("id"))
Expand Down
6 changes: 3 additions & 3 deletions gateway/api/integrations/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// @Produce json
// @Success 200 {object} openapi.JiraIntegration
// @Failure 404,500 {object} openapi.HTTPError
// @Router /jira-integration [get]
// @Router /integrations/jira [get]
func Get(c *gin.Context) {
ctx := storagev2.ParseContext(c)
dbJiraIntegration, err := models.GetJiraIntegration(ctx.OrgID)
Expand Down Expand Up @@ -57,7 +57,7 @@ func Get(c *gin.Context) {
// @Param request body openapi.JiraIntegration true "The request body resource"
// @Success 201 {object} openapi.JiraIntegration
// @Failure 400,409,500 {object} openapi.HTTPError
// @Router /jira-integration [post]
// @Router /integrations/jira [post]
func Post(c *gin.Context) {
ctx := storagev2.ParseContext(c)
var req openapi.JiraIntegration
Expand Down Expand Up @@ -109,7 +109,7 @@ func Post(c *gin.Context) {
// @Param request body openapi.JiraIntegration true "The request body resource"
// @Success 200 {object} openapi.JiraIntegration
// @Failure 400,404,500 {object} openapi.HTTPError
// @Router /jira-integration [put]
// @Router /integrations/jira [put]
func Put(c *gin.Context) {
ctx := storagev2.ParseContext(c)
var req openapi.JiraIntegration
Expand Down
Loading

0 comments on commit f728cdd

Please sign in to comment.