MCPcopy
hub / github.com/koderover/zadig / GetContainerLogsSSE

Function GetContainerLogsSSE

pkg/microservice/aslan/core/log/handler/sse.go:62–134  ·  view source on GitHub ↗

GetContainerLogsSSE streams container logs via SSE. Query params: envName, projectName, tails (default 10), since (optional, e.g. 5m, 1h; Go duration). @Param since query string false "Only logs from the last duration, e.g. 5m, 1h (time.ParseDuration format)"

(c *gin.Context)

Source from the content-addressed store, hash-verified

60// Query params: envName, projectName, tails (default 10), since (optional, e.g. 5m, 1h; Go duration).
61// @Param since query string false "Only logs from the last duration, e.g. 5m, 1h (time.ParseDuration format)"
62func GetContainerLogsSSE(c *gin.Context) {
63 logger := ginzap.WithContext(c).Sugar()
64
65 ctx, err := internalhandler.NewContextWithAuthorization(c)
66 if err != nil {
67 ctx.RespErr = fmt.Errorf("authorization Info Generation failed: err %s", err)
68 ctx.UnAuthorized = true
69 internalhandler.JSONResponse(c, ctx)
70 return
71 }
72
73 tails, err := strconv.ParseInt(c.Query("tails"), 10, 64)
74 if err != nil {
75 tails = int64(10)
76 }
77 sinceSeconds, err := parseSinceSeconds(c.Query("since"))
78 if err != nil {
79 ctx.RespErr = e.ErrInvalidParam.AddDesc(err.Error())
80 internalhandler.JSONResponse(c, ctx)
81 return
82 }
83
84 envName := c.Query("envName")
85 productName := c.Query("projectName")
86 isProduction := c.Query("production") == "true"
87
88 if !isProduction {
89 // authorization checks
90 if !ctx.Resources.IsSystemAdmin {
91 if _, ok := ctx.Resources.ProjectAuthInfo[productName]; !ok {
92 ctx.UnAuthorized = true
93 internalhandler.JSONResponse(c, ctx)
94 return
95 }
96 if !ctx.Resources.ProjectAuthInfo[productName].Env.View &&
97 !ctx.Resources.ProjectAuthInfo[productName].IsProjectAdmin {
98 permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, productName, types.ResourceTypeEnvironment, envName, types.EnvActionView)
99 if err != nil || !permitted {
100 ctx.UnAuthorized = true
101 internalhandler.JSONResponse(c, ctx)
102 return
103 }
104 }
105 }
106
107 internalhandler.Stream(c, func(ctx context.Context, streamChan chan interface{}) {
108 logservice.ContainerLogStream(ctx, streamChan, envName, productName, c.Param("podName"), c.Param("containerName"), true, tails, sinceSeconds, logger)
109 }, logger)
110 } else {
111 // authorization checks
112 if !ctx.Resources.IsSystemAdmin {
113 if _, ok := ctx.Resources.ProjectAuthInfo[productName]; !ok {
114 ctx.UnAuthorized = true
115 internalhandler.JSONResponse(c, ctx)
116 return
117 }
118 if !ctx.Resources.ProjectAuthInfo[productName].ProductionEnv.View &&
119 !ctx.Resources.ProjectAuthInfo[productName].IsProjectAdmin {

Callers

nothing calls this directly

Calls 5

WithContextFunction · 0.92
parseSinceSecondsFunction · 0.85
AddDescMethod · 0.80
ErrorMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected