/
closeissue.go
59 lines (48 loc) · 1.34 KB
/
closeissue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package commandcli
import (
"fmt"
"net/http"
avcli "github.com/byuoitav/smee/proto"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"google.golang.org/grpc"
)
func (c *Client) CloseIssueByRoom(ctx *gin.Context) {
id := ctx.Param("id")
if id == "" {
c.log.Warn("no room id provided; cancelling closure...")
ctx.JSON(http.StatusBadRequest, "no room id")
return
}
cookie := ctx.Request.Header.Get("Cookie")
token, err := parseForCookie("smee", cookie)
if err != nil {
c.log.Warn("authorization not found; cancelling closure...")
ctx.JSON(http.StatusBadRequest, "authorization not found")
return
}
netid, err := getUserFromJWT(token)
if err != nil || len(netid) == 0 {
c.log.Warn("no av-user specified; cancelling closure...")
ctx.JSON(http.StatusBadRequest, "no av-user specified")
return
}
c.log.Debug(fmt.Sprintf("closing issue for room: %s", id))
args := &avcli.ID{
Id: id,
Designation: "prd",
}
auth := auth{
token: c.cliToken,
user: netid,
}
var results response
_, err = c.cli.CloseMonitoringIssue(ctx.Request.Context(), args, grpc.PerRPCCredentials(auth))
if err != nil {
c.log.Warn("unable to close issue", zap.Error(err))
ctx.JSON(http.StatusInternalServerError, fmt.Sprintf("unable to close issue for room: %s", id))
return
}
results.successful(id)
ctx.JSON(http.StatusOK, results.report())
}