Skip to content

Commit

Permalink
fix: update playbook schema
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored and moshloop committed Dec 25, 2024
1 parent 8e76958 commit 79ebc04
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 1,038 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ migrate-test: hack/migrate/go.mod
cd hack/migrate && go run ./main.go

cp-playbook-schema:
cp ../mission-control/config/schemas/playbook-spec.schema.json schema/
cp ../mission-control/config/schemas/playbook-spec.schema.json schema/openapi/

fmt_json:
ls fixtures/expectations/*.json | while read -r jf; do \
Expand Down
27 changes: 15 additions & 12 deletions query/config_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ import (
"gorm.io/gorm/clause"
)

type ChangeRelationDirection string

const (
CatalogChangeRecursiveUpstream = "upstream"
CatalogChangeRecursiveDownstream = "downstream"
CatalogChangeRecursiveNone = "none"
CatalogChangeRecursiveAll = "all"
CatalogChangeRecursiveUpstream ChangeRelationDirection = "upstream"
CatalogChangeRecursiveDownstream ChangeRelationDirection = "downstream"
CatalogChangeRecursiveNone ChangeRelationDirection = "none"
CatalogChangeRecursiveAll ChangeRelationDirection = "all"
)

var allRecursiveOptions = []string{CatalogChangeRecursiveUpstream, CatalogChangeRecursiveDownstream, CatalogChangeRecursiveNone, CatalogChangeRecursiveAll}
var allRecursiveOptions = []ChangeRelationDirection{CatalogChangeRecursiveUpstream, CatalogChangeRecursiveDownstream, CatalogChangeRecursiveNone, CatalogChangeRecursiveAll}

var allowedConfigChangesSortColumns = []string{"name", "change_type", "summary", "source", "created_at", "count"}

Expand Down Expand Up @@ -57,7 +59,8 @@ type CatalogChangesSearchRequest struct {
sortOrder string

// upstream | downstream | both
Recursive string `query:"recursive" json:"recursive"`
Recursive ChangeRelationDirection `query:"recursive" json:"recursive"`

// FIXME: Soft toggle does not work with Recursive=both
// In that case, soft relations are always returned
// It also returns ALL soft relations throughout the tree
Expand Down Expand Up @@ -152,7 +155,7 @@ func (t *CatalogChangesSearchRequest) SetDefaults() {

func (t *CatalogChangesSearchRequest) Validate() error {
if !lo.Contains(allRecursiveOptions, t.Recursive) {
return fmt.Errorf("'recursive' must be one of %s", strings.Join(allRecursiveOptions, ", "))
return fmt.Errorf("'recursive' must be one of %v", allRecursiveOptions)
}

if t.From != "" {
Expand Down Expand Up @@ -298,31 +301,31 @@ func FindCatalogChanges(ctx context.Context, req CatalogChangesSearchRequest) (*
if req.Severity != "" {
clause, err := parseAndBuildFilteringQuery(formSeverityQuery(req.Severity), "severity", false)
if err != nil {
return nil, api.Errorf(api.EINVALID, fmt.Sprintf("failed to parse severity: %v", err))
return nil, api.Errorf(api.EINVALID, "failed to parse severity: %v", err)
}
clauses = append(clauses, clause...)
}

if req.Summary != "" {
clause, err := parseAndBuildFilteringQuery(req.Summary, "summary", true)
if err != nil {
return nil, api.Errorf(api.EINVALID, fmt.Sprintf("failed to parse summary: %v", err))
return nil, api.Errorf(api.EINVALID, "failed to parse summary: %v", err)
}
clauses = append(clauses, clause...)
}

if req.Source != "" {
clause, err := parseAndBuildFilteringQuery(req.Source, "source", true)
if err != nil {
return nil, api.Errorf(api.EINVALID, fmt.Sprintf("failed to parse source: %v", err))
return nil, api.Errorf(api.EINVALID, "failed to parse source: %v", err)
}
clauses = append(clauses, clause...)
}

if req.Tags != "" {
parsedLabelSelector, err := labels.Parse(req.Tags)
if err != nil {
return nil, api.Errorf(api.EINVALID, fmt.Sprintf("failed to parse label selector: %v", err))
return nil, api.Errorf(api.EINVALID, "failed to parse label selector: %v", err)
}
requirements, _ := parsedLabelSelector.Requirements()
for _, r := range requirements {
Expand All @@ -345,7 +348,7 @@ func FindCatalogChanges(ctx context.Context, req CatalogChangesSearchRequest) (*
if req.externalCreatedBy != "" {
clause, err := parseAndBuildFilteringQuery(req.externalCreatedBy, "external_created_by", true)
if err != nil {
return nil, api.Errorf(api.EINVALID, fmt.Sprintf("failed to parse external createdby: %v", err))
return nil, api.Errorf(api.EINVALID, "failed to parse external createdby: %v", err)
}
clauses = append(clauses, clause...)
}
Expand Down
31 changes: 24 additions & 7 deletions query/config_relations.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ type RelatedConfig struct {
Path string `json:"path"`
}

type RelationType string
type RelationDirection string

type RelationQuery struct {
ID uuid.UUID
Relation RelationDirection
Expand All @@ -46,13 +43,33 @@ type RelationQuery struct {
MaxDepth *int
}

type RelationDirection string

const (
All RelationDirection = "all"
Incoming RelationDirection = "incoming"
Outgoing RelationDirection = "outgoing"
Both RelationType = "both"
Hard RelationType = "hard"
Soft RelationType = "soft"
All RelationDirection = "all"
)

func (t RelationDirection) ToChangeDirection() ChangeRelationDirection {
switch t {
case All:
return CatalogChangeRecursiveAll
case Incoming:
return CatalogChangeRecursiveUpstream
case Outgoing:
return CatalogChangeRecursiveDownstream
}

return CatalogChangeRecursiveNone
}

type RelationType string

const (
Both RelationType = "both"
Hard RelationType = "hard"
Soft RelationType = "soft"
)

func GetRelatedConfigs(ctx context.Context, query RelationQuery) ([]RelatedConfig, error) {
Expand Down
84 changes: 78 additions & 6 deletions schema/openapi/playbook-spec.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,63 @@
"$id": "https://github.com/flanksource/incident-commander/api/v1/playbook-spec",
"$ref": "#/$defs/PlaybookSpec",
"$defs": {
"AIAction": {
"properties": {
"apiKey": {
"$ref": "#/$defs/EnvVar"
},
"backend": {
"type": "string"
},
"model": {
"type": "string"
},
"apiURL": {
"type": "string"
},
"config": {
"type": "string"
},
"changes": {
"$ref": "#/$defs/TimeMetadata"
},
"analysis": {
"$ref": "#/$defs/TimeMetadata"
},
"relationships": {
"items": {
"$ref": "#/$defs/AIActionRelationship"
},
"type": "array"
},
"prompt": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object",
"required": [
"prompt"
]
},
"AIActionRelationship": {
"properties": {
"depth": {
"type": "integer"
},
"direction": {
"type": "string"
},
"changes": {
"$ref": "#/$defs/TimeMetadata"
},
"analysis": {
"$ref": "#/$defs/TimeMetadata"
}
},
"additionalProperties": false,
"type": "object"
},
"AWSConnection": {
"properties": {
"connection": {
Expand Down Expand Up @@ -582,6 +639,9 @@
"templatesOn": {
"type": "string"
},
"ai": {
"$ref": "#/$defs/AIAction"
},
"exec": {
"$ref": "#/$defs/ExecAction"
},
Expand Down Expand Up @@ -943,12 +1003,6 @@
"namespace": {
"type": "string"
},
"types": {
"$ref": "#/$defs/Items"
},
"statuses": {
"$ref": "#/$defs/Items"
},
"tagSelector": {
"type": "string"
},
Expand All @@ -957,6 +1011,12 @@
},
"fieldSelector": {
"type": "string"
},
"types": {
"$ref": "#/$defs/Items"
},
"statuses": {
"$ref": "#/$defs/Items"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -1004,6 +1064,18 @@
"required": [
"key"
]
},
"TimeMetadata": {
"properties": {
"since": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object",
"required": [
"since"
]
}
}
}
Loading

0 comments on commit 79ebc04

Please sign in to comment.