MCPcopy
hub / github.com/cyclops-ui/cyclops / DownloadLogs

Method DownloadLogs

cyclops-ctrl/internal/controller/modules.go:913–952  ·  view source on GitHub ↗
(ctx *gin.Context)

Source from the content-addressed store, hash-verified

911}
912
913func (m *Modules) DownloadLogs(ctx *gin.Context) {
914 ctx.Header("Access-Control-Allow-Origin", "*")
915
916 namespace := ctx.Param("namespace")
917 container := ctx.Param("container")
918 name := ctx.Param("name")
919
920 logs, err := m.kubernetesClient.GetPodLogs(
921 namespace,
922 container,
923 name,
924 nil,
925 )
926 if err != nil {
927 fmt.Println(err)
928 ctx.JSON(http.StatusInternalServerError, dto.NewError("Error fetching logs", err.Error()))
929 return
930 }
931
932 tempFile, err := os.CreateTemp("", fmt.Sprintf("%v-%v-*.txt", name, container))
933 if err != nil {
934 ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create file"})
935 return
936 }
937 defer tempFile.Close()
938
939 for _, log := range logs {
940 _, err = tempFile.WriteString(log + "\n")
941 if err != nil {
942 ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to write to file"})
943 return
944 }
945 }
946
947 ctx.Header("Content-Description", "File Transfer")
948 ctx.Header("Content-Disposition", "attachment; filename="+fmt.Sprintf("%v-%v.txt", name, container))
949 ctx.Header("Content-Type", "application/octet-stream")
950 ctx.Header("Content-Transfer-Encoding", "binary")
951 ctx.File(tempFile.Name())
952}
953
954func (m *Modules) GetManifest(ctx *gin.Context) {
955 ctx.Header("Access-Control-Allow-Origin", "*")

Callers

nothing calls this directly

Calls 3

PrintlnMethod · 0.80
ErrorMethod · 0.80
GetPodLogsMethod · 0.65

Tested by

no test coverage detected