Skip to content

Commit

Permalink
Removed k8s client go dependencies from graphql (#4747)
Browse files Browse the repository at this point in the history
* removed k8s client-go dependencies

Signed-off-by: Saranya-jena <[email protected]>

* Update push.yml

* removed k8s client-go dependencies

Signed-off-by: Saranya-jena <[email protected]>

* removed token issues

Signed-off-by: Saranya-jena <[email protected]>

* removed token issues

Signed-off-by: Saranya-jena <[email protected]>

* removed token issues

Signed-off-by: Saranya-jena <[email protected]>

* removed token issues

Signed-off-by: Saranya-jena <[email protected]>

* removed token issues

Signed-off-by: Saranya-jena <[email protected]>

* removed token issues

Signed-off-by: Saranya-jena <[email protected]>

* fixed imports

Signed-off-by: Saranya-jena <[email protected]>

* reverted changes for push pipeline

Signed-off-by: Saranya-jena <[email protected]>

* updated go mod

Signed-off-by: Saranya-jena <[email protected]>

* updated mocks

Signed-off-by: Saranya-jena <[email protected]>

* updated manifests

Signed-off-by: Saranya-jena <[email protected]>

* updated manifest

Signed-off-by: Saranya-jena <[email protected]>

* updated manifest

Signed-off-by: Saranya-jena <[email protected]>

---------

Signed-off-by: Saranya-jena <[email protected]>
  • Loading branch information
Saranya-jena authored Jul 8, 2024
1 parent 9d58d8b commit a00691f
Show file tree
Hide file tree
Showing 23 changed files with 209 additions and 1,021 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,4 @@ jobs:
source env-vars
FRONTEND_IMAGE=${{ matrix.frontend.image_name }}
timestamp=`date "+%s"`
make push-frontend
make push-frontend
10 changes: 0 additions & 10 deletions chaoscenter/graphql/server/api/middleware/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import (
"regexp"
"strings"

"github.com/sirupsen/logrus"

"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/chaos_infrastructure"

"github.com/gin-gonic/gin"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/utils"
)
Expand All @@ -29,13 +25,7 @@ func ValidateCors() gin.HandlerFunc {
}

validOrigin := false
endpoint, err := chaos_infrastructure.GetEndpoint("external")
if err != nil {
logrus.Error(err)
} else if endpoint != "" {
allowedOrigins = append(allowedOrigins, endpoint)

}
for _, allowedOrigin := range allowedOrigins {
match, err := regexp.MatchString(allowedOrigin, origin)
if err == nil && match {
Expand Down
5 changes: 1 addition & 4 deletions chaoscenter/graphql/server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ require (
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.26.0
k8s.io/apimachinery v0.26.0
k8s.io/client-go v12.0.0+incompatible
sigs.k8s.io/yaml v1.4.0

)
Expand Down Expand Up @@ -69,10 +68,8 @@ require (
github.com/golang/snappy v0.0.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -92,7 +89,6 @@ require (
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/sosodev/duration v1.3.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
Expand All @@ -118,6 +114,7 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/client-go v12.0.0+incompatible // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20220124234850-424119656bbf // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
Expand Down
4 changes: 0 additions & 4 deletions chaoscenter/graphql/server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,6 @@ github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U=
github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4=
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
github.com/fatih/color v1.6.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down Expand Up @@ -622,7 +620,6 @@ github.com/googleapis/gnostic v0.3.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTV
github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU=
github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg=
github.com/googleapis/gnostic v0.5.1/go.mod h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2cUuW7uA/OeU=
github.com/googleapis/gnostic v0.5.5 h1:9fHAtK0uDfpveeqqo1hkEZJcFvYXAiCN3UutL8F9xHw=
github.com/googleapis/gnostic v0.5.5/go.mod h1:7+EbHbldMins07ALC74bsA81Ovc97DwqyJO1AENw9kA=
github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
github.com/gophercloud/gophercloud v0.2.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
Expand Down Expand Up @@ -698,7 +695,6 @@ github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/improbable-eng/thanos v0.3.2/go.mod h1:GZewVGILKuJVPNRn7L4Zw+7X96qzFOwj63b22xYGXBE=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down
40 changes: 35 additions & 5 deletions chaoscenter/graphql/server/graph/chaos_experiment.resolvers.go

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

39 changes: 36 additions & 3 deletions chaoscenter/graphql/server/graph/chaos_infrastructure.resolvers.go

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

1 change: 1 addition & 0 deletions chaoscenter/graphql/server/graph/chaoshub.resolvers.go

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

24 changes: 21 additions & 3 deletions chaoscenter/graphql/server/graph/environment.resolvers.go

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

3 changes: 1 addition & 2 deletions chaoscenter/graphql/server/graph/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@ func NewConfig(mongodbOperator mongodb.MongoOperator) generated.Config {
if err != nil {
return nil, err
}

newCtx := context.WithValue(ctx, authorization.UserClaim, user)
newCtx = context.WithValue(ctx, "username", user["username"])

return next(newCtx)
}

return config
}
4 changes: 3 additions & 1 deletion chaoscenter/graphql/server/pkg/authorization/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ func Middleware(handler http.Handler, mongoClient *mongo.Client) gin.HandlerFunc
c.Writer.Write([]byte("Error verifying JWT token: Token is revoked"))
return
}

ctx := context.WithValue(c.Request.Context(), AuthKey, jwt)
c.Request = c.Request.WithContext(ctx)
ctx1 := context.WithValue(ctx, "request-header", c.Request.Header)
c.Request = c.Request.WithContext(ctx1)
handler.ServeHTTP(c.Writer, c.Request)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"strings"
"time"

"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/authorization"

probeUtils "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/probe/utils"

"github.com/litmuschaos/litmus/chaoscenter/graphql/server/utils"

"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/authorization"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/chaos_infrastructure"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/gitops"
"go.mongodb.org/mongo-driver/mongo/options"
Expand Down Expand Up @@ -793,6 +794,12 @@ func (c *ChaosExperimentRunHandler) RunChaosWorkFlow(ctx context.Context, projec
txnOpts = options.Transaction().SetWriteConcern(wc).SetReadConcern(rc)
)

tkn := ctx.Value(authorization.AuthKey).(string)
username, err := authorization.GetUsername(tkn)
if err != nil {
return nil, err
}

session, err := mongodb.MgoClient.StartSession()
if err != nil {
logrus.Errorf("failed to start mongo session %v", err)
Expand All @@ -815,11 +822,11 @@ func (c *ChaosExperimentRunHandler) RunChaosWorkFlow(ctx context.Context, projec
IsRemoved: false,
CreatedAt: currentTime,
CreatedBy: mongodb.UserDetailResponse{
Username: ctx.Value(authorization.AuthKey).(string),
Username: username,
},
UpdatedAt: currentTime,
UpdatedBy: mongodb.UserDetailResponse{
Username: ctx.Value(authorization.AuthKey).(string),
Username: username,
},
},
},
Expand Down Expand Up @@ -861,11 +868,11 @@ func (c *ChaosExperimentRunHandler) RunChaosWorkFlow(ctx context.Context, projec
IsRemoved: false,
CreatedAt: currentTime,
CreatedBy: mongodb.UserDetailResponse{
Username: ctx.Value(authorization.AuthKey).(string),
Username: username,
},
UpdatedAt: currentTime,
UpdatedBy: mongodb.UserDetailResponse{
Username: ctx.Value(authorization.AuthKey).(string),
Username: username,
},
},
NotifyID: &notifyID,
Expand Down Expand Up @@ -908,7 +915,7 @@ func (c *ChaosExperimentRunHandler) RunChaosWorkFlow(ctx context.Context, projec
if err != nil {
return nil, fmt.Errorf("failed to generate probes in workflow manifest, err: %v", err)
}
username := ctx.Value(authorization.AuthKey).(string)

manifest, err := yaml.Marshal(workflowManifest)
if err != nil {
return nil, err
Expand Down Expand Up @@ -991,7 +998,11 @@ func (c *ChaosExperimentRunHandler) RunCronExperiment(ctx context.Context, proje
return err
}

username := ctx.Value(authorization.AuthKey).(string)
tkn := ctx.Value(authorization.AuthKey).(string)
username, err := authorization.GetUsername(tkn)
if err != nil {
return err
}

if r != nil {
chaos_infrastructure.SendExperimentToSubscriber(projectID, &model.ChaosExperimentRequest{
Expand Down
Loading

0 comments on commit a00691f

Please sign in to comment.