diff --git a/chaoscenter/graphql/server/graph/environment.resolvers.go b/chaoscenter/graphql/server/graph/environment.resolvers.go index 7894d0e6fe1..883bd54b20e 100644 --- a/chaoscenter/graphql/server/graph/environment.resolvers.go +++ b/chaoscenter/graphql/server/graph/environment.resolvers.go @@ -35,7 +35,7 @@ func (r *mutationResolver) CreateEnvironment(ctx context.Context, projectID stri } // UpdateEnvironment is the resolver for the updateEnvironment field. -func (r *mutationResolver) UpdateEnvironment(ctx context.Context, projectID string, request *model.UpdateEnvironmentRequest, authOperator *authorization.Operator) (string, error) { +func (r *mutationResolver) UpdateEnvironment(ctx context.Context, projectID string, request *model.UpdateEnvironmentRequest, authConfigOperator *authorization.Operator) (string, error) { logFields := logrus.Fields{ "projectId": projectID, "environmentId": request.EnvironmentID, @@ -49,7 +49,7 @@ func (r *mutationResolver) UpdateEnvironment(ctx context.Context, projectID stri } tkn := ctx.Value(authorization.AuthKey).(string) - username, err := authOperator.GetUsername(tkn) + username, err := authConfigOperator.GetUsername(tkn) if err != nil { return "", err } @@ -58,7 +58,7 @@ func (r *mutationResolver) UpdateEnvironment(ctx context.Context, projectID stri } // DeleteEnvironment is the resolver for the deleteEnvironment field. -func (r *mutationResolver) DeleteEnvironment(ctx context.Context, projectID string, environmentID string, authOperator *authorization.Operator) (string, error) { +func (r *mutationResolver) DeleteEnvironment(ctx context.Context, projectID string, environmentID string, authConfigOperator *authorization.Operator) (string, error) { logFields := logrus.Fields{ "projectId": projectID, "environmentId": environmentID, @@ -72,7 +72,7 @@ func (r *mutationResolver) DeleteEnvironment(ctx context.Context, projectID stri } tkn := ctx.Value(authorization.AuthKey).(string) - username, err := authOperator.GetUsername(tkn) + username, err := authConfigOperator.GetUsername(tkn) if err != nil { return "", err } @@ -81,7 +81,7 @@ func (r *mutationResolver) DeleteEnvironment(ctx context.Context, projectID stri } // GetEnvironment is the resolver for the getEnvironment field. -func (r *queryResolver) GetEnvironment(ctx context.Context, projectID string, environmentID string, authOperator *authorization.Operator) (*model.Environment, error) { +func (r *queryResolver) GetEnvironment(ctx context.Context, projectID string, environmentID string) (*model.Environment, error) { logFields := logrus.Fields{ "projectId": projectID, "environmentId": environmentID, @@ -97,7 +97,7 @@ func (r *queryResolver) GetEnvironment(ctx context.Context, projectID string, en } // ListEnvironments is the resolver for the listEnvironments field. -func (r *queryResolver) ListEnvironments(ctx context.Context, projectID string, request *model.ListEnvironmentRequest, authOperator *authorization.Operator) (*model.ListEnvironmentResponse, error) { +func (r *queryResolver) ListEnvironments(ctx context.Context, projectID string, request *model.ListEnvironmentRequest) (*model.ListEnvironmentResponse, error) { logFields := logrus.Fields{ "projectId": projectID, } diff --git a/chaoscenter/graphql/server/pkg/chaos_infrastructure/service.go b/chaoscenter/graphql/server/pkg/chaos_infrastructure/service.go index f5a847fdcea..88ba5fb934f 100644 --- a/chaoscenter/graphql/server/pkg/chaos_infrastructure/service.go +++ b/chaoscenter/graphql/server/pkg/chaos_infrastructure/service.go @@ -107,7 +107,11 @@ func (in *infraService) RegisterInfra(c context.Context, projectID string, input return nil, err } - token, err := InfraCreateJWT(infraID) + var mongodbOperator mongodb.MongoOperator + + operator := NewChaosInfrastructureOperator(mongodbOperator) + + token, err := operator.InfraCreateJWT(infraID) if err != nil { return &model.RegisterInfraResponse{}, err } @@ -952,14 +956,18 @@ func updateVersionFormat(str string) (int, error) { // QueryServerVersion is used to fetch the version of the server func (in *infraService) QueryServerVersion(ctx context.Context) (*model.ServerVersionResponse, error) { - dbVersion, err := config.GetConfig(ctx, "version") - if err != nil { - return nil, err - } - return &model.ServerVersionResponse{ - Key: dbVersion.Key, - Value: dbVersion.Value.(string), - }, nil + var mongodbOperator mongodb.MongoOperator + + configOperator := config.NewConfigOperator(mongodbOperator) + + dbVersion, err := configOperator.GetConfig(ctx, "version") + if err != nil { + return nil, err + } + return &model.ServerVersionResponse{ + Key: dbVersion.Key, + Value: dbVersion.Value.(string), + }, nil } // PodLog receives logs from the workflow-agent and publishes to frontend clients diff --git a/chaoscenter/graphql/server/pkg/chaoshub/service.go b/chaoscenter/graphql/server/pkg/chaoshub/service.go index 9ec8ff1412a..7162796e682 100644 --- a/chaoscenter/graphql/server/pkg/chaoshub/service.go +++ b/chaoscenter/graphql/server/pkg/chaoshub/service.go @@ -131,72 +131,72 @@ func (c *chaosHubService) AddChaosHub(ctx context.Context, chaosHub model.Create return newHub.GetOutputChaosHub(), nil } -func (c *chaosHubService) AddRemoteChaosHub(ctx context.Context, chaosHub model.CreateRemoteChaosHub, projectID string, authConfigOperator *authorization.Operator) (*model.ChaosHub, error) { - IsExist, err := c.IsChaosHubAvailable(ctx, chaosHub.Name, projectID) - if err != nil { - return nil, err - } - if IsExist == true { - return nil, errors.New("name already exists") - } - description := "" - if chaosHub.Description != nil { - description = *chaosHub.Description - } - currentTime := time.Now() - - tkn := ctx.Value(authorization.AuthKey).(string) - username, err := c.authConfigOperator.GetUsername(tkn) - - if err != nil { - log.Error("error getting userID: ", err) - return nil, err - } - - newHub := &dbSchemaChaosHub.ChaosHub{ - ID: uuid.New().String(), - ProjectID: projectID, - RepoURL: chaosHub.RepoURL, - RepoBranch: "", - RemoteHub: chaosHub.RemoteHub, - ResourceDetails: mongodb.ResourceDetails{ - Name: chaosHub.Name, - Description: description, - Tags: chaosHub.Tags, - }, - IsPrivate: false, - HubType: string(model.HubTypeRemote), - AuthType: string(model.AuthTypeNone), - Audit: mongodb.Audit{ - CreatedAt: currentTime.UnixMilli(), - UpdatedAt: currentTime.UnixMilli(), - IsRemoved: false, - CreatedBy: mongodb.UserDetailResponse{ - Username: username, - }, - UpdatedBy: mongodb.UserDetailResponse{ - Username: username, - }, - }, - LastSyncedAt: time.Now().UnixMilli(), - IsDefault: false, - } - - // Adding the new hub into database with the given name. - err = c.chaosHubOperator.CreateChaosHub(ctx, newHub) - if err != nil { - log.Error(err) - return nil, err - } - - err = handler.DownloadRemoteHub(chaosHub, projectID) - if err != nil { - err = fmt.Errorf("Hub configurations saved successfully. Failed to connect the remote repo: " + err.Error()) - log.Error(err) - return nil, err - } - - return newHub.GetOutputChaosHub(), nil +func (c *chaosHubService) AddRemoteChaosHub(ctx context.Context, chaosHub model.CreateRemoteChaosHub, projectID string) (*model.ChaosHub, error) { + IsExist, err := c.IsChaosHubAvailable(ctx, chaosHub.Name, projectID) + if err != nil { + return nil, err + } + if IsExist == true { + return nil, errors.New("name already exists") + } + description := "" + if chaosHub.Description != nil { + description = *chaosHub.Description + } + currentTime := time.Now() + + tkn := ctx.Value(authorization.AuthKey).(string) + username, err := c.authConfigOperator.GetUsername(tkn) + + if err != nil { + log.Error("error getting userID: ", err) + return nil, err + } + + newHub := &dbSchemaChaosHub.ChaosHub{ + ID: uuid.New().String(), + ProjectID: projectID, + RepoURL: chaosHub.RepoURL, + RepoBranch: "", + RemoteHub: chaosHub.RemoteHub, + ResourceDetails: mongodb.ResourceDetails{ + Name: chaosHub.Name, + Description: description, + Tags: chaosHub.Tags, + }, + IsPrivate: false, + HubType: string(model.HubTypeRemote), + AuthType: string(model.AuthTypeNone), + Audit: mongodb.Audit{ + CreatedAt: currentTime.UnixMilli(), + UpdatedAt: currentTime.UnixMilli(), + IsRemoved: false, + CreatedBy: mongodb.UserDetailResponse{ + Username: username, + }, + UpdatedBy: mongodb.UserDetailResponse{ + Username: username, + }, + }, + LastSyncedAt: time.Now().UnixMilli(), + IsDefault: false, + } + + // Adding the new hub into database with the given name. + err = c.chaosHubOperator.CreateChaosHub(ctx, newHub) + if err != nil { + log.Error(err) + return nil, err + } + + err = handler.DownloadRemoteHub(chaosHub, projectID) + if err != nil { + err = fmt.Errorf("Hub configurations saved successfully. Failed to connect the remote repo: " + err.Error()) + log.Error(err) + return nil, err + } + + return newHub.GetOutputChaosHub(), nil } // SaveChaosHub is used for Adding a new ChaosHub diff --git a/chaoscenter/graphql/server/pkg/probe/handler/handler.go b/chaoscenter/graphql/server/pkg/probe/handler/handler.go index 7ce5026783c..862d5ab8f9d 100644 --- a/chaoscenter/graphql/server/pkg/probe/handler/handler.go +++ b/chaoscenter/graphql/server/pkg/probe/handler/handler.go @@ -507,7 +507,7 @@ func (p *probeService) DeleteProbe(ctx context.Context, probeName, projectID str return false, err } tkn := ctx.Value(authorization.AuthKey).(string) - username, err := authOperator.GetUsername(tkn) + username, err := p.authConfigOperator.GetUsername(tkn) Time := time.Now().UnixMilli()