Skip to content

Commit

Permalink
[ChaosCenter]: Migrating graphql-server from Gorilla mux to Gin (#3923)
Browse files Browse the repository at this point in the history
* Migrate from Gorilla mux to Gin

Signed-off-by: Namkyu Park <lak9348@gmail.com>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

* Linting & Ordering codes

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

* fix: remove duplicated code

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

* fix: adopt go fmt

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

* Move to using interface for better mocking at chaoshub package (#3933)

* fix: Move to using interface for better mocking at chaoshub

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

* fix: delete operator interface and linting codes

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

* fix: change db instance to local variable

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

* fix: passing operator interface for better mocking

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

---------

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

* fix: status code to constant variable

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

* fix: add logs when encounterd error

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

* fix: rename pkg name

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

* fix: rename pkg, graphql_server to rest_handlers

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

* fix: resolve codeql issue

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

* fix: add replacer value

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>

---------

Signed-off-by: Namkyu Park <lak9348@gmail.com>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
  • Loading branch information
namkyu1999 committed Apr 7, 2023
1 parent ae9aeb2 commit c6cda32
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 186 deletions.
4 changes: 2 additions & 2 deletions litmus-portal/graphql-server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ require (
github.com/99designs/gqlgen v0.11.3
github.com/argoproj/argo-workflows/v3 v3.3.1
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.7.7
github.com/go-git/go-git/v5 v5.4.2
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/protobuf v1.5.2
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.5.0
github.com/jinzhu/copier v0.3.5
github.com/kelseyhightower/envconfig v1.4.0
Expand All @@ -20,7 +21,6 @@ require (
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/common v0.32.1
github.com/rs/cors v1.8.2
github.com/sirupsen/logrus v1.8.1
github.com/tidwall/gjson v1.14.0
github.com/tidwall/sjson v1.2.4
Expand Down
30 changes: 27 additions & 3 deletions litmus-portal/graphql-server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,13 @@ github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2H
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew=
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
github.com/gin-contrib/cors v1.3.1 h1:doAsuITavI4IOcd0Y19U4B+O0dNWihRyX//nn4sEmgA=
github.com/gin-contrib/cors v1.3.1/go.mod h1:jjEJ4268OPZUcU7k9Pm653S7lXUGcqMADzFA61xsmDk=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
github.com/gizak/termui/v3 v3.1.0/go.mod h1:bXQEBkJpzxUAKf0+xq9MSWAvWZlE7c+aidmyFlkYTrY=
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
Expand Down Expand Up @@ -716,6 +723,16 @@ github.com/go-openapi/validate v0.19.15/go.mod h1:tbn/fdOwYHgrhPBzidZfJC2MIVvs9G
github.com/go-openapi/validate v0.20.1/go.mod h1:b60iJT+xNNLfaQJUqLI7946tYiFEOuE9E4k54HpKcJ0=
github.com/go-openapi/validate v0.20.3/go.mod h1:goDdqVGiigM3jChcrYJxD2joalke3ZXeftD16byIjA4=
github.com/go-ozzo/ozzo-validation v3.5.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
Expand Down Expand Up @@ -962,7 +979,6 @@ github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z
github.com/gorilla/mux v1.7.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
Expand Down Expand Up @@ -1204,6 +1220,9 @@ github.com/labstack/gommon v0.2.7/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFY
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
github.com/leanovate/gopter v0.2.4/go.mod h1:gNcbPWNEWRe4lm+bycKqxUYoH5uoVje5SkOJ3uoLer8=
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
Expand Down Expand Up @@ -1276,6 +1295,7 @@ github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2y
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
Expand Down Expand Up @@ -1604,8 +1624,6 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rubenv/sql-migrate v0.0.0-20191025130928-9355dd04f4b3/go.mod h1:WS0rl9eEliYI8DPnr3TOwz4439pay+qNgzJoVya/DmY=
github.com/rubenv/sql-migrate v0.0.0-20200212082348-64f95ea68aa3/go.mod h1:rtQlpHw+eR6UrqaS3kX1VYeaCxzCVdimDS7g5Ln4pPc=
Expand Down Expand Up @@ -1755,7 +1773,11 @@ github.com/uber/jaeger-client-go v2.30.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMW
github.com/uber/jaeger-lib v2.2.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ultraware/funlen v0.0.1/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA=
github.com/ultraware/funlen v0.0.2/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA=
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
Expand Down Expand Up @@ -2642,6 +2664,8 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
gopkg.in/fsnotify/fsnotify.v1 v1.4.7/go.mod h1:Fyux9zXlo4rWoMSIzpn9fDAYjalPqJ/K1qJ27s+7ltE=
gopkg.in/gcfg.v1 v1.2.0/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
gopkg.in/go-playground/webhooks.v5 v5.17.0/go.mod h1:LZbya/qLVdbqDR1aKrGuWV6qbia2zCYSR5dpom2SInQ=
gopkg.in/gorp.v1 v1.7.2/go.mod h1:Wo3h+DBQZIxATwftsglhdD/62zRFPhGhTiu5jUJmCaw=
gopkg.in/imdario/mergo.v0 v0.3.7/go.mod h1:9qPP6AGrlC1G2PTNXko614FwGZvorN7MiBU0Eppok+U=
Expand Down
20 changes: 10 additions & 10 deletions litmus-portal/graphql-server/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 22 additions & 20 deletions litmus-portal/graphql-server/pkg/authorization/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"net/http"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

Expand All @@ -15,50 +16,51 @@ const (
CookieName = "litmus-cc-token"
)

func Middleware(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Middleware verifies jwt and checks if user has enough privilege to access route (no roles' info needed)
func Middleware(handler http.Handler) gin.HandlerFunc {
return func(c *gin.Context) {
jwt := ""
auth, err := r.Cookie(CookieName)
auth, err := c.Request.Cookie(CookieName)
if err == nil {
jwt = auth.Value
} else if r.Header.Get("Authorization") != "" {
jwt = r.Header.Get("Authorization")
} else if c.Request.Header.Get("Authorization") != "" {
jwt = c.Request.Header.Get("Authorization")
}

ctx := context.WithValue(r.Context(), AuthKey, jwt)
r = r.WithContext(ctx)
handler.ServeHTTP(w, r)
})
ctx := context.WithValue(c.Request.Context(), AuthKey, jwt)
c.Request = c.Request.WithContext(ctx)
handler.ServeHTTP(c.Writer, c.Request)
}
}

// RestMiddlewareWithRole verifies jwt and checks if user has enough privilege to access route
func RestMiddlewareWithRole(handler http.Handler, roles []string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
func RestMiddlewareWithRole(handler gin.HandlerFunc, roles []string) gin.HandlerFunc {
return func(c *gin.Context) {
jwt := ""
auth, err := r.Cookie(CookieName)
auth, err := c.Request.Cookie(CookieName)
if err == nil {
jwt = auth.Value
} else if r.Header.Get("Authorization") != "" {
jwt = r.Header.Get("Authorization")
} else if c.Request.Header.Get("Authorization") != "" {
jwt = c.Request.Header.Get("Authorization")
}
user, err := UserValidateJWT(jwt)
if err != nil {
logrus.WithError(err).Error("Invalid Auth Cookie")
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte("Error verifying JWT token: " + err.Error()))
c.Writer.WriteHeader(http.StatusUnauthorized)
c.Writer.Write([]byte("Error verifying JWT token: " + err.Error()))
return
}
if len(roles) == 0 {
handler.ServeHTTP(w, r)
handler(c)
return
}
for _, role := range roles {
if role == user["role"] {
handler.ServeHTTP(w, r)
handler(c)
return
}
}
w.WriteHeader(http.StatusUnauthorized)
c.Writer.WriteHeader(http.StatusUnauthorized)
return
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func ProcessCompletedWorkflowRun(execData types.ExecutionData, wfID string) (typ
if value.ChaosExp == nil {
continue
}
for expName, _ := range weightMap {
for expName := range weightMap {
if strings.Contains(value.ChaosExp.EngineName, expName) {
experimentName = expName
}
Expand Down
50 changes: 27 additions & 23 deletions litmus-portal/graphql-server/pkg/chaoshub/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"strings"
"time"

"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/gorilla/mux"
"github.com/jinzhu/copier"
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/graph/model"
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/chaoshub/handler"
Expand Down Expand Up @@ -529,31 +529,35 @@ func (c *chaosHubService) GetAllHubs(ctx context.Context) ([]*model.ChaosHub, er
}

// GetIconHandler ...
var GetIconHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
var img *os.File
var err error
var responseStatusCode int
if strings.ToLower(vars["ChartName"]) == "predefined" {
img, err = os.Open("/tmp/version/" + vars["ProjectID"] + "/" + vars["HubName"] + "/workflows/icons/" + vars["IconName"])
responseStatusCode = 200
if err != nil {
responseStatusCode = 500
fmt.Fprint(w, "icon cannot be fetched, err : "+err.Error())
}
var GetIconHandler = gin.HandlerFunc(func(c *gin.Context) {
replacer := strings.NewReplacer("../", "", "./", "", "/", "", "..", "")
var (
projectID = replacer.Replace(c.Param("ProjectID"))
hubName = replacer.Replace(c.Param("HubName"))
chartName = replacer.Replace(c.Param("ChartName"))
iconName = replacer.Replace(c.Param("IconName"))
img *os.File
err error
responseStatusCode = http.StatusOK
)

if strings.ToLower(chartName) == "predefined" {
img, err = os.Open("/tmp/version/" + projectID + "/" + hubName + "/workflows/icons/" + iconName)
} else {
img, err = os.Open("/tmp/version/" + vars["ProjectID"] + "/" + vars["HubName"] + "/charts/" + vars["ChartName"] + "/icons/" + vars["IconName"])
responseStatusCode = 200
if err != nil {
responseStatusCode = 500
fmt.Fprint(w, "icon cannot be fetched, err : "+err.Error())
}
img, err = os.Open("/tmp/version/" + projectID + "/" + hubName + "/charts/" + chartName + "/icons/" + iconName)
}

if err != nil {
responseStatusCode = http.StatusInternalServerError
fmt.Fprint(c.Writer, "icon cannot be fetched, err : "+err.Error())
}

defer img.Close()
w.Header().Set("Access-Control-Allow-Origin", "*")
w.WriteHeader(responseStatusCode)
w.Header().Set("Content-Type", "image/png") // <-- set the content-type header
io.Copy(w, img)

c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.WriteHeader(responseStatusCode)
c.Writer.Header().Set("Content-Type", "image/png") // <-- set the content-type header
io.Copy(c.Writer, img)
})

// RecurringHubSync is used for syncing
Expand Down
2 changes: 1 addition & 1 deletion litmus-portal/graphql-server/pkg/gitops/handler/handler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GQL handlers and other external functions to facilitate gitops
// GQL graphql_server and other external functions to facilitate gitops
package handler

import (
Expand Down
Loading

0 comments on commit c6cda32

Please sign in to comment.