Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Eliminate Global Variable to Enhance Testability #4685

Open
wants to merge 107 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
f79695d
--- (#4664)
dependabot[bot] May 21, 2024
963e7b1
chore(deps): Bump github.com/vektah/gqlparser/v2 (#4660)
dependabot[bot] May 21, 2024
08a877f
Updating email id of Oum kale (#4658)
oumkale May 23, 2024
1f1d36d
fixed nil pointer issue with default chaoshubs (#4683)
Saranya-jena Jun 1, 2024
a13ed01
fix(logs): fix the rank warning in logs (#4682)
ispeakc0de Jun 1, 2024
f10da7b
Refactor: Eliminate Global Variable to Enhance Testability
andoriyaprashant Jun 3, 2024
b251240
checks
andoriyaprashant Jun 4, 2024
1ea0aa0
backend-checks
andoriyaprashant Jun 4, 2024
5df950f
Upgrade go version in all the modules (#4669)
Saranya-jena Jun 4, 2024
4852d87
Added env support to enable/disable gql introspection (#4672)
Saranya-jena Jun 6, 2024
e4ef8c9
Hide 'Cluster-Wide' Access in namespace scoped ChaosCentre (#4615)
Baalekshan Jun 7, 2024
3f75be6
chore: update experiment docs (#4641)
namkyu1999 Jun 7, 2024
c100633
update README.md (#4671)
namkyu1999 Jun 7, 2024
c4793f5
chore(deps): Bump golang.org/x/crypto in /chaoscenter/graphql/server …
dependabot[bot] Jun 7, 2024
a6b3689
chore(deps): Bump golang.org/x/crypto in /chaoscenter/authentication …
dependabot[bot] Jun 7, 2024
ca4a109
Update
andoriyaprashant Jun 8, 2024
77bda8b
golang imports
andoriyaprashant Jun 9, 2024
3cfde71
Upgrade go version in all the modules (#4669)
Saranya-jena Jun 4, 2024
3899946
chore(deps): Bump google.golang.org/protobuf (#4700)
dependabot[bot] Jun 12, 2024
d5e3825
chore(deps): Bump google.golang.org/protobuf (#4701)
dependabot[bot] Jun 12, 2024
3ac7d3b
Temporarily removing version check for Database in 3.x (#4703)
Jonsy13 Jun 12, 2024
d058bef
fix: Updated Edit Probe button to RBACButton (#4710)
hrishavjha Jun 14, 2024
7e68175
Added installation manifest for 3.8.0 (#4709)
Saranya-jena Jun 14, 2024
729893d
chore(3.8.0): Adding the installation manifest for 3.8.0 (#4711)
ispeakc0de Jun 14, 2024
96c60c2
chore(deps): Bump github.com/gorilla/websocket (#4714)
dependabot[bot] Jun 17, 2024
f7d662e
chore(deps): Bump github.com/gorilla/websocket (#4713)
dependabot[bot] Jun 17, 2024
dc035fd
chore(schedule): update the scheduler crd (#4721)
ispeakc0de Jun 20, 2024
854c508
chore(deps): Bump go.mongodb.org/mongo-driver (#4715)
dependabot[bot] Jun 24, 2024
fef51ac
Added necessary rbacs for invite_users and get_project_members API (#…
Saranya-jena Jun 24, 2024
0224976
chore(deps): Bump ws from 7.5.7 to 7.5.10 in /chaoscenter/web (#4716)
dependabot[bot] Jun 24, 2024
ba57ac6
Added mandatory checks for default password reset (#4720)
Saranya-jena Jun 24, 2024
82ba0e8
add cors check (#4725)
shovanmaity Jun 25, 2024
b2a2d90
Added nil check for token validation (#4727)
Saranya-jena Jun 25, 2024
b380405
feat: Added reset password as a mandatory step if new user logs in (#…
hrishavjha Jun 26, 2024
fa94310
update allowed origins list and nginx config (#4730)
shovanmaity Jun 27, 2024
bf7cfe6
Added strict validation for username and password in backend. (#4670)
aryan-bhokare Jun 27, 2024
fe79e4c
Executor role implementation. (#4737)
aryan-bhokare Jul 2, 2024
a9e3057
Added enhacements in password mandate logic (#4741)
Saranya-jena Jul 4, 2024
db79af5
feat: Added password reset as a route to manage initial login case (#…
hrishavjha Jul 5, 2024
0c45558
Added support for jwt secret creation of each user upon user login (#…
Saranya-jena Jul 5, 2024
4e1439e
Removed k8s client go dependencies from graphql (#4747)
Saranya-jena Jul 8, 2024
3a73441
Added env based support for HTTPS connection (#4706)
Saranya-jena Jul 8, 2024
f4136d3
add network policy yamls (#4745)
shovanmaity Jul 8, 2024
4efe858
feat: Updated login and update password APIs (#4751)
hrishavjha Jul 9, 2024
6f9b6a4
Fixed issues with go routines (#4754)
Saranya-jena Jul 9, 2024
524cc18
chore(deps): Bump google.golang.org/grpc in /chaoscenter/graphql/serv…
dependabot[bot] Jul 10, 2024
123549e
Updated litmus installation yaml (#4757)
Saranya-jena Jul 10, 2024
dae716b
added installation manifest for 3.9.0 (#4763)
Saranya-jena Jul 15, 2024
003c60b
Prepended colon in the ports env (#4760)
Saranya-jena Jul 15, 2024
c8dce10
updated dex deployment yaml (#4764)
Saranya-jena Jul 15, 2024
c7ea7b9
added experimentID in response of saveChaosExperiment API (#4765)
SarthakJain26 Jul 15, 2024
a240388
Fix not getting experiment pod logs in the UI and format logs (#4732)
Baalekshan Jul 15, 2024
4efbaa2
Removed envs for jwt secret (#4767)
Saranya-jena Jul 15, 2024
e43bc74
chore(3.9.0): Adding the installation manifest for 3.9.0 (#4770)
ispeakc0de Jul 16, 2024
4687627
chore(deps): Bump golang.org/x/crypto in /chaoscenter/authentication …
dependabot[bot] Jul 16, 2024
362174c
docs(install): spelling, grammar (#4755)
beejiujitsu Jul 16, 2024
5e8b8e2
chore(deps): Bump google.golang.org/grpc in /chaoscenter/authenticati…
dependabot[bot] Jul 16, 2024
82a96ae
UBI migration of Images - chaoscenter (#4753)
dusdjhyeon Jul 17, 2024
e182bb2
Changing trivy exit code to 1 (#4772)
dusdjhyeon Jul 17, 2024
997d6fc
fix cannot read properties of undefined in ChaosFaultController (#4668)
JanhaviAlekar Jul 22, 2024
6e46d7c
Fixes #4673 Improvements in user management screen (#4674)
JanhaviAlekar Jul 22, 2024
97afd21
Adding gitops support for all git repositories (#4743)
JanhaviAlekar Jul 22, 2024
72082b0
Multiple project owner backend (#4774)
aryan-bhokare Jul 22, 2024
ffe5463
Feat: Added support for multiple project owners (#4597)
aryan-bhokare Jul 22, 2024
ad34e0c
Added architecture and proposal. (#4525)
aryan-bhokare Aug 1, 2024
5de89f2
fix ususual space around project selection card (#4676)
JanhaviAlekar Aug 2, 2024
09d4bc0
Updated error codes to be geenric in login api (#4801)
Saranya-jena Aug 2, 2024
ee2a17a
Added installation manifest for 3.9.2 (#4804)
Saranya-jena Aug 2, 2024
cf12621
Updated release guidelines (#4819)
Saranya-jena Aug 8, 2024
ba99e81
Update README-ko.md file (#4781)
suhyenim Aug 9, 2024
65f9fd4
[Security] Added 'eq' operation when querying entitiy (#4820)
sukkyun2 Aug 9, 2024
d7cf766
feat: Change Connect Hub button to display a loading state (#4797)
leeeeeyeon Aug 9, 2024
fbf3078
[Security] Refactor gitMutex key naming in chaoscenter/graphql/server…
ParkChangSun Aug 9, 2024
8c2b862
Version up github action workflow that is working with node12 or node…
BaeJi77 Aug 13, 2024
5fda8c6
all repo support in chaoshub (#4748)
JanhaviAlekar Aug 14, 2024
d8eb81b
Apply golang code review comments to `chaoscenter/graphql/server/serv…
BaeJi77 Aug 14, 2024
53335b7
Subscriber reconnect (#4776)
ledbruno Aug 14, 2024
d18aeeb
Fixing RBACs of RunChaosExperiment function (#4822)
aryan-bhokare Aug 14, 2024
a5df784
fix: Fixed routing issues with project switcher (#4828)
hrishavjha Aug 14, 2024
6042dc3
Added installation manifests for 3.10.0 (#4827)
Saranya-jena Aug 14, 2024
f832f95
Fix image links in README (#4811)
jongwooo Aug 14, 2024
6c33724
Rename env to EC2_INSTANCE_TAG (#4815)
jongwooo Aug 14, 2024
1bc1285
chore(3.10.0): Adding the installation manifest for 3.10.0 (#4830)
ispeakc0de Aug 19, 2024
6620d93
fixes #4665 Invalid version details in backend. (#4666)
JanhaviAlekar Aug 23, 2024
03bf77d
e2e.yml fixed (#4696)
andoriyaprashant Aug 23, 2024
1c7830b
chore(deps): Bump github.com/99designs/gqlgen (#4708)
dependabot[bot] Aug 23, 2024
96130d5
Fix Horizontal Scroll Bar in "Enable Chaos Environments" Pop-up (#4692)
andoriyaprashant Aug 23, 2024
28d75cc
Improved documentation with spelling and grammar corrections (#4762)
Denish3436 Aug 23, 2024
bba4df4
improvement in pagination component (#4832)
JanhaviAlekar Aug 23, 2024
c24a654
chore(deps): Bump golang.org/x/crypto in /chaoscenter/authentication …
dependabot[bot] Aug 23, 2024
b8d9b96
chore(deps): Bump go.mongodb.org/mongo-driver (#4817)
dependabot[bot] Aug 23, 2024
f791ded
Allow older infras to connect with chaos centre (#4823)
Baalekshan Aug 23, 2024
26b0157
fix: Correct swagger.json file versions (#4838)
suyeon-jung-dev Aug 23, 2024
64c746f
chore(deps): Bump go.mongodb.org/mongo-driver (#4818)
dependabot[bot] Aug 23, 2024
6ff3eb5
Create wingie-enuygun.md (#4861)
hursit Sep 4, 2024
0753bb6
Changed schema chaoshub (#4842)
JanhaviAlekar Sep 6, 2024
eab3f3b
added '#' as valid Password Character (#4833)
JanhaviAlekar Sep 6, 2024
f41c158
feat : Group chaos infra in infrastructure selection modal (#4779)
JanhaviAlekar Sep 6, 2024
0cac03f
add fuzz test(#4795) (#4816)
inpyu Sep 6, 2024
4e5bc4f
Comment response invalidCredentials status has changed from 400 to 40…
kwx4957 Sep 6, 2024
af2c7e5
chore(deps): Bump github.com/tidwall/gjson (#4847)
dependabot[bot] Sep 6, 2024
c98cfc0
test: add fuzz test in chaoshub/handler (#4857)
sypark9646 Sep 6, 2024
0e44b72
add fuzz test in chaos_experiment_run (#4834)
weeeeestern Sep 6, 2024
30cea9a
Seperate call to retrieve namespace list and retrieve KubeObject for …
Calvinaud Sep 6, 2024
c8b7184
Merge branch 'master' into branch1
andoriyaprashant Sep 7, 2024
ab65c75
Merge branch 'master' into branch1
namkyu1999 Nov 15, 2024
65b33ff
Merge branch 'master' into branch1
andoriyaprashant Nov 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chaoscenter/authentication/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn5
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *Operator) UpdateChaosHub(ctx context.Context, query bson.D, update bson

// GetAggregateChaosHubs takes a mongo pipeline to retrieve the project details from the database
func (c *Operator) GetAggregateChaosHubs(ctx context.Context, pipeline mongo.Pipeline) (*mongo.Cursor, error) {
results, err := mongodb.Operator.Aggregate(ctx, mongodb.ChaosHubCollection, pipeline)
results, err := c.operator.Aggregate(ctx, mongodb.ChaosHubCollection, pipeline)
if err != nil {
return nil, fmt.Errorf("error on getting the chaos hubs : %v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,31 @@ import (
"go.mongodb.org/mongo-driver/mongo"
)

type Operator struct {
operator mongodb.MongoOperator
}

func NewConfigOperator(mongodbOperator mongodb.MongoOperator) *Operator {
return &Operator{
operator: mongodbOperator,
}
}

// CreateConfig creates a new server config with unique key
func CreateConfig(ctx context.Context, config *ServerConfig) error {
err := mongodb.Operator.Create(ctx, mongodb.ServerConfigCollection, config)
func (o *Operator) CreateConfig(ctx context.Context, config *ServerConfig) error {
err := o.operator.Create(ctx, mongodb.ServerConfigCollection, config)
if err != nil {
return err
}
return nil
}

// GetConfig returns the requested server config
func GetConfig(ctx context.Context, key string) (*ServerConfig, error) {
func (o *Operator) GetConfig(ctx context.Context, key string) (*ServerConfig, error) {
query := bson.D{
{"key", key},
}
results, err := mongodb.Operator.Get(ctx, mongodb.ServerConfigCollection, query)
results, err := o.operator.Get(ctx, mongodb.ServerConfigCollection, query)
if err != nil {
return nil, err
}
Expand All @@ -39,14 +49,14 @@ func GetConfig(ctx context.Context, key string) (*ServerConfig, error) {
}

// UpdateConfig updates the required server config
func UpdateConfig(ctx context.Context, key string, value interface{}) error {
func (o *Operator) UpdateConfig(ctx context.Context, key string, value interface{}) error {
query := bson.D{
{"key", key},
}
update := bson.D{{"$set", bson.D{{
"value", value}},
}}
_, err := mongodb.Operator.Update(ctx, mongodb.ServerConfigCollection, query, update)
_, err := o.operator.Update(ctx, mongodb.ServerConfigCollection, query, update)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (e *Operator) GetEnvironmentWithProjectID(projectID string) ([]*Environment
defer cancel()

var environments []*Environment
results, err := mongodb.Operator.List(ctx, mongodb.EnvironmentCollection, query)
results, err := e.operator.List(ctx, mongodb.EnvironmentCollection, query)
if err != nil {
return []*Environment{}, err
}
Expand Down
5 changes: 0 additions & 5 deletions chaoscenter/graphql/server/pkg/database/mongodb/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ type MongoOperations struct {
MongoClient *MongoClient
}

var (
// Operator contains all the CRUD operations of the mongo database
Operator MongoOperator = &MongoOperations{}
)

func NewMongoOperations(mongoClient *MongoClient) *MongoOperations {
return &MongoOperations{
MongoClient: mongoClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"go.mongodb.org/mongo-driver/mongo"
)

// Operator is the model for probe collection
// Operator is the model for probe operations and collection
type Operator struct {
operator mongodb.MongoOperator
}

// NewChaosProbeOperator returns a new instance of Operator
func NewChaosProbeOperator(mongodbOperator mongodb.MongoOperator) *Operator {
// NewProbeOperator returns a new instance of Operator
func NewProbeOperator(mongodbOperator mongodb.MongoOperator) *Operator {
return &Operator{
operator: mongodbOperator,
}
Expand Down
19 changes: 16 additions & 3 deletions chaoscenter/graphql/server/pkg/handlers/readiness_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ import (
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb"
)

// Operator encapsulates the MongoDB operations
type Operator struct {
mongoOperator mongodb.MongoOperator
}

// NewOperator returns a new instance of Operator
func NewOperator(mongoOperator mongodb.MongoOperator) *Operator {
return &Operator{
mongoOperator: mongoOperator,
}
}

// ReadinessAPIStatus represents the readiness status of the API
type ReadinessAPIStatus struct {
DataBase string `json:"database"`
Collections string `json:"collections"`
Expand All @@ -20,14 +33,14 @@ func contains(s []string, str string) bool {
return true
}
}

return false
}

func ReadinessHandler() gin.HandlerFunc {
// ReadinessHandler returns a handler function for readiness checks
func (r *Operator) ReadinessHandler() gin.HandlerFunc {
return func(c *gin.Context) {
var dbFlag = "up"
dbs, err := mongodb.Operator.ListDataBase(context.Background(), mongodb.MgoClient)
dbs, err := r.mongoOperator.ListDataBase(context.Background(), mongodb.MgoClient)
if err != nil {
dbFlag = "down"
}
Expand Down
14 changes: 13 additions & 1 deletion chaoscenter/graphql/server/pkg/probe/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ type probeService struct {
probeOperator *dbSchemaProbe.Operator
}

type Operator struct {
operator mongodb.MongoOperator
}

// NewProbeOperator returns a new instance of Operator
func NewProbeOperator(mongodbOperator mongodb.MongoOperator) *Operator {
return &Operator{
operator: mongodbOperator,
}
}

// NewProbeService returns a new instance of probeService
func NewProbeService(probeOperator *dbSchemaProbe.Operator) Service {
return &probeService{
probeOperator: probeOperator,
Expand Down Expand Up @@ -405,7 +417,7 @@ func GetProbeExecutionHistoryInExperimentRuns(projectID string, probeName string
pipeline = append(pipeline, matchIdentifierStage)

// Call aggregation on pipeline
experimentRunOperator := dbChaosExperimentRun.NewChaosExperimentRunOperator(mongodb.Operator)
experimentRunOperator := dbChaosExperimentRun.NewChaosExperimentRunOperator(NewProbeOperator.operator)
expRunCursor, err := experimentRunOperator.GetAggregateExperimentRuns(pipeline)
if err != nil {
return nil, errors.New("DB aggregate stage error: " + err.Error())
Expand Down
1 change: 0 additions & 1 deletion chaoscenter/graphql/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func main() {
mongoClient := mongodb.Client.Initialize(mongodb.MgoClient)

var mongodbOperator mongodb.MongoOperator = mongodb.NewMongoOperations(mongoClient)
mongodb.Operator = mongodbOperator

if err := validateVersion(); err != nil {
log.Fatal(err)
Expand Down
Loading