Better file api (#30)

* Better file api
This commit is contained in:
Jonas Plum
2022-01-23 04:27:31 +01:00
committed by GitHub
parent 8ca57c14d9
commit 2d817318f2
17 changed files with 105 additions and 521 deletions

View File

@@ -68,7 +68,6 @@ type Service interface {
RunArtifact(context.Context, int64, string, string) error
AddComment(context.Context, int64, *model.CommentForm) (*model.TicketWithTickets, error)
RemoveComment(context.Context, int64, int) (*model.TicketWithTickets, error)
LinkFiles(context.Context, int64, []*model.File) (*model.TicketWithTickets, error)
AddTicketPlaybook(context.Context, int64, *model.PlaybookTemplateForm) (*model.TicketWithTickets, error)
RemoveTicketPlaybook(context.Context, int64, string) (*model.TicketWithTickets, error)
SetTask(context.Context, int64, string, string, *model.Task) (*model.TicketWithTickets, error)
@@ -139,7 +138,6 @@ func NewServer(service Service, roleAuth func([]string) func(http.Handler) http.
r.With(roleAuth([]string{"ticket:write"})).Post("/tickets/{id}/artifacts/{name}/run/{automation}", s.runArtifactHandler)
r.With(roleAuth([]string{"ticket:write"})).Post("/tickets/{id}/comments", s.addCommentHandler)
r.With(roleAuth([]string{"ticket:write"})).Delete("/tickets/{id}/comments/{commentID}", s.removeCommentHandler)
r.With(roleAuth([]string{"ticket:write"})).Put("/tickets/{id}/files", s.linkFilesHandler)
r.With(roleAuth([]string{"ticket:write"})).Post("/tickets/{id}/playbooks", s.addTicketPlaybookHandler)
r.With(roleAuth([]string{"ticket:write"})).Delete("/tickets/{id}/playbooks/{playbookID}", s.removeTicketPlaybookHandler)
r.With(roleAuth([]string{"ticket:write"})).Put("/tickets/{id}/playbooks/{playbookID}/task/{taskID}", s.setTaskHandler)
@@ -642,26 +640,6 @@ func (s *server) removeCommentHandler(w http.ResponseWriter, r *http.Request) {
response(w, result, err)
}
func (s *server) linkFilesHandler(w http.ResponseWriter, r *http.Request) {
idP, err := parseURLInt64(r, "id")
if err != nil {
JSONError(w, err)
return
}
// jl, _ := gojsonschema.NewReaderLoader(r.Body)
// []*model.FileSchema.Validate(jl)
var filesP []*model.File
if err := parseBody(r, &filesP); err != nil {
JSONError(w, err)
return
}
result, err := s.service.LinkFiles(r.Context(), idP, filesP)
response(w, result, err)
}
func (s *server) addTicketPlaybookHandler(w http.ResponseWriter, r *http.Request) {
idP, err := parseURLInt64(r, "id")
if err != nil {

View File

@@ -378,15 +378,6 @@ var Tests = []struct {
},
},
{
Name: "LinkFiles",
Args: Args{Method: "Put", URL: "/tickets/8125/files", Data: []interface{}{map[string]interface{}{"key": "myfile", "name": "document.doc"}}},
Want: Want{
Status: 200,
Body: map[string]interface{}{"created": time.Date(2021, time.October, 2, 16, 4, 59, 78186000, time.UTC), "files": []interface{}{map[string]interface{}{"key": "myfile", "name": "document.doc"}}, "id": 8125, "modified": time.Date(2021, time.December, 12, 12, 12, 12, 12, time.UTC), "name": "phishing from selenafadel@von.com detected", "owner": "demo", "references": []interface{}{map[string]interface{}{"href": "https://www.seniorleading-edge.name/users/efficient", "name": "recovery"}, map[string]interface{}{"href": "http://www.dynamicseamless.com/clicks-and-mortar", "name": "force"}, map[string]interface{}{"href": "http://www.leadscalable.biz/envisioneer", "name": "fund"}}, "schema": "{}", "status": "closed", "tickets": []interface{}{map[string]interface{}{"created": time.Date(2021, time.October, 2, 16, 4, 59, 78186000, time.UTC), "id": 8126, "modified": time.Date(2021, time.October, 2, 16, 4, 59, 78186000, time.UTC), "name": "Surfaceintroduce virus detected", "owner": "demo", "references": []interface{}{map[string]interface{}{"href": "http://www.centralworld-class.io/synthesize", "name": "university"}, map[string]interface{}{"href": "https://www.futurevirtual.org/supply-chains/markets/sticky/iterate", "name": "goal"}, map[string]interface{}{"href": "http://www.chiefsyndicate.io/action-items", "name": "unemployment"}}, "schema": "{}", "status": "closed", "type": "alert"}}, "type": "alert"},
},
},
{
Name: "AddTicketPlaybook",
Args: Args{Method: "Post", URL: "/tickets/8125/playbooks", Data: map[string]interface{}{"yaml": "name: Simple\ntasks:\n input:\n name: Upload malware if possible\n type: input\n schema:\n title: Malware\n type: object\n properties:\n malware:\n type: string\n title: Select malware\n default: \"\"\n next:\n hash: \"malware != ''\"\n\n hash:\n name: Hash the malware\n type: automation\n automation: hash.sha1\n payload:\n default: \"playbook.tasks['input'].data['malware']\"\n next:\n escalate:\n\n escalate:\n name: Escalate to malware team\n type: task\n"}},

View File

@@ -3189,101 +3189,6 @@
"tags" : [ "tickets" ]
}
},
"/tickets/{id}/files" : {
"put" : {
"description" : "Link files to an ticket. The files themself will be stored in object storage.",
"operationId" : "linkFiles",
"parameters" : [ {
"description" : "Ticket ID",
"example" : 8125,
"in" : "path",
"name" : "id",
"required" : true,
"schema" : {
"format" : "int64",
"type" : "integer"
}
} ],
"requestBody" : {
"content" : {
"application/json" : {
"schema" : {
"items" : {
"$ref" : "#/components/schemas/File"
},
"type" : "array"
}
}
},
"description" : "Added files",
"required" : true
},
"responses" : {
"200" : {
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/TicketWithTickets"
}
},
"test" : {
"example" : {
"created" : "2021-10-02T16:04:59.078+0000",
"files" : [ {
"key" : "myfile",
"name" : "document.doc"
} ],
"id" : 8125,
"modified" : "2021-12-12T12:12:12.000+0000",
"name" : "phishing from selenafadel@von.com detected",
"owner" : "demo",
"references" : [ {
"href" : "https://www.seniorleading-edge.name/users/efficient",
"name" : "recovery"
}, {
"href" : "http://www.dynamicseamless.com/clicks-and-mortar",
"name" : "force"
}, {
"href" : "http://www.leadscalable.biz/envisioneer",
"name" : "fund"
} ],
"schema" : "{}",
"status" : "closed",
"tickets" : [ {
"created" : "2021-10-02T16:04:59.078+0000",
"id" : 8126,
"modified" : "2021-10-02T16:04:59.078+0000",
"name" : "Surfaceintroduce virus detected",
"owner" : "demo",
"references" : [ {
"href" : "http://www.centralworld-class.io/synthesize",
"name" : "university"
}, {
"href" : "https://www.futurevirtual.org/supply-chains/markets/sticky/iterate",
"name" : "goal"
}, {
"href" : "http://www.chiefsyndicate.io/action-items",
"name" : "unemployment"
} ],
"schema" : "{}",
"status" : "closed",
"type" : "alert"
} ],
"type" : "alert"
}
}
},
"description" : "successful operation"
}
},
"security" : [ {
"roles" : [ "ticket:write" ]
} ],
"summary" : "Link files to an ticket",
"tags" : [ "tickets" ],
"x-codegen-request-body-name" : "files"
}
},
"/tickets/{id}/playbooks" : {
"post" : {
"operationId" : "addTicketPlaybook",

View File

@@ -5190,77 +5190,6 @@ paths:
summary: Remove an comment from an ticket
tags:
- tickets
/tickets/{id}/files:
put:
description: Link files to an ticket. The files themself will be stored in object
storage.
operationId: linkFiles
parameters:
- description: Ticket ID
format: int64
in: path
name: id
required: true
type: integer
x-example: 8125
- description: Added files
in: body
name: files
required: true
schema:
items:
$ref: '#/definitions/File'
type: array
x-example:
- key: myfile
name: document.doc
responses:
"200":
description: successful operation
examples:
test:
created: 2021-10-02T16:04:59.078186Z
files:
- key: myfile
name: document.doc
id: 8125
modified: 2021-12-12T12:12:12.000000012Z
name: phishing from selenafadel@von.com detected
owner: demo
references:
- href: https://www.seniorleading-edge.name/users/efficient
name: recovery
- href: http://www.dynamicseamless.com/clicks-and-mortar
name: force
- href: http://www.leadscalable.biz/envisioneer
name: fund
schema: '{}'
status: closed
tickets:
- created: 2021-10-02T16:04:59.078186Z
id: 8126
modified: 2021-10-02T16:04:59.078186Z
name: Surfaceintroduce virus detected
owner: demo
references:
- href: http://www.centralworld-class.io/synthesize
name: university
- href: https://www.futurevirtual.org/supply-chains/markets/sticky/iterate
name: goal
- href: http://www.chiefsyndicate.io/action-items
name: unemployment
schema: '{}'
status: closed
type: alert
type: alert
schema:
$ref: '#/definitions/TicketWithTickets'
security:
- roles:
- ticket:write
summary: Link files to an ticket
tags:
- tickets
/tickets/{id}/playbooks:
post:
operationId: addTicketPlaybook

View File

@@ -2759,101 +2759,6 @@
"tags" : [ "tickets" ]
}
},
"/tickets/{id}/files" : {
"put" : {
"description" : "Link files to an ticket. The files themself will be stored in object storage.",
"operationId" : "linkFiles",
"parameters" : [ {
"description" : "Ticket ID",
"example" : 8125,
"in" : "path",
"name" : "id",
"required" : true,
"schema" : {
"format" : "int64",
"type" : "integer"
}
} ],
"requestBody" : {
"content" : {
"application/json" : {
"schema" : {
"items" : {
"$ref" : "#/components/schemas/File"
},
"type" : "array"
}
}
},
"description" : "Added files",
"required" : true
},
"responses" : {
"200" : {
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/TicketWithTickets"
}
},
"test" : {
"example" : {
"created" : "2021-10-02T16:04:59.078+0000",
"files" : [ {
"key" : "myfile",
"name" : "document.doc"
} ],
"id" : 8125,
"modified" : "2021-12-12T12:12:12.000+0000",
"name" : "phishing from selenafadel@von.com detected",
"owner" : "demo",
"references" : [ {
"href" : "https://www.seniorleading-edge.name/users/efficient",
"name" : "recovery"
}, {
"href" : "http://www.dynamicseamless.com/clicks-and-mortar",
"name" : "force"
}, {
"href" : "http://www.leadscalable.biz/envisioneer",
"name" : "fund"
} ],
"schema" : "{}",
"status" : "closed",
"tickets" : [ {
"created" : "2021-10-02T16:04:59.078+0000",
"id" : 8126,
"modified" : "2021-10-02T16:04:59.078+0000",
"name" : "Surfaceintroduce virus detected",
"owner" : "demo",
"references" : [ {
"href" : "http://www.centralworld-class.io/synthesize",
"name" : "university"
}, {
"href" : "https://www.futurevirtual.org/supply-chains/markets/sticky/iterate",
"name" : "goal"
}, {
"href" : "http://www.chiefsyndicate.io/action-items",
"name" : "unemployment"
} ],
"schema" : "{}",
"status" : "closed",
"type" : "alert"
} ],
"type" : "alert"
}
}
},
"description" : "successful operation"
}
},
"security" : [ {
"roles" : [ "ticket:write" ]
} ],
"summary" : "Link files to an ticket",
"tags" : [ "tickets" ],
"x-codegen-request-body-name" : "files"
}
},
"/tickets/{id}/playbooks" : {
"post" : {
"operationId" : "addTicketPlaybook",

View File

@@ -4778,77 +4778,6 @@ paths:
summary: Remove an comment from an ticket
tags:
- tickets
/tickets/{id}/files:
put:
description: Link files to an ticket. The files themself will be stored in object
storage.
operationId: linkFiles
parameters:
- description: Ticket ID
format: int64
in: path
name: id
required: true
type: integer
x-example: 8125
- description: Added files
in: body
name: files
required: true
schema:
items:
$ref: '#/definitions/File'
type: array
x-example:
- key: myfile
name: document.doc
responses:
"200":
description: successful operation
examples:
test:
created: 2021-10-02T16:04:59.078186Z
files:
- key: myfile
name: document.doc
id: 8125
modified: 2021-12-12T12:12:12.000000012Z
name: phishing from selenafadel@von.com detected
owner: demo
references:
- href: https://www.seniorleading-edge.name/users/efficient
name: recovery
- href: http://www.dynamicseamless.com/clicks-and-mortar
name: force
- href: http://www.leadscalable.biz/envisioneer
name: fund
schema: '{}'
status: closed
tickets:
- created: 2021-10-02T16:04:59.078186Z
id: 8126
modified: 2021-10-02T16:04:59.078186Z
name: Surfaceintroduce virus detected
owner: demo
references:
- href: http://www.centralworld-class.io/synthesize
name: university
- href: https://www.futurevirtual.org/supply-chains/markets/sticky/iterate
name: goal
- href: http://www.chiefsyndicate.io/action-items
name: unemployment
schema: '{}'
status: closed
type: alert
type: alert
schema:
$ref: '#/definitions/TicketWithTickets'
security:
- roles:
- ticket:write
summary: Link files to an ticket
tags:
- tickets
/tickets/{id}/playbooks:
post:
operationId: addTicketPlaybook