Skip to content

Commit

Permalink
wrong type for method DeleteProbe and AddRemoteChaosHub
Browse files Browse the repository at this point in the history
  • Loading branch information
andoriyaprashant committed Jan 18, 2025
1 parent c783ef7 commit 21a3c8d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 82 deletions.
12 changes: 6 additions & 6 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.

26 changes: 17 additions & 9 deletions chaoscenter/graphql/server/pkg/chaos_infrastructure/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
132 changes: 66 additions & 66 deletions chaoscenter/graphql/server/pkg/chaoshub/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/graphql/server/pkg/probe/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 21a3c8d

Please sign in to comment.