Skip to content

Commit

Permalink
datasource :Fix panic in transaction subsystem
Browse files Browse the repository at this point in the history
This commit fixes a panic in the data source transaction subsystem
when options are nil.

Signed-off-by: Adolfo García Veytia (Puerco) <puerco@stacklok.com>
  • Loading branch information
puerco committed Dec 2, 2024
1 parent 5dfc7d0 commit 41792ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/controlplane/handlers_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/mindersec/minder/internal/datasources/service"
"github.com/mindersec/minder/internal/engine/engcontext"
"github.com/mindersec/minder/internal/flags"
minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
Expand Down Expand Up @@ -71,7 +72,7 @@ func (s *Server) GetDataSourceById(ctx context.Context,
}

// Get the data source by ID
ds, err := s.dataSourcesService.GetByID(ctx, dsID, entityCtx.Project.ID, nil)
ds, err := s.dataSourcesService.GetByID(ctx, dsID, entityCtx.Project.ID, &service.ReadOptions{})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -105,7 +106,7 @@ func (s *Server) GetDataSourceByName(ctx context.Context,
}

// Get the data source by name
ds, err := s.dataSourcesService.GetByName(ctx, dsName, entityCtx.Project.ID, nil)
ds, err := s.dataSourcesService.GetByName(ctx, dsName, entityCtx.Project.ID, &service.ReadOptions{})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -133,7 +134,7 @@ func (s *Server) ListDataSources(ctx context.Context,
}

// Get all data sources
ret, err := s.dataSourcesService.List(ctx, entityCtx.Project.ID, nil)
ret, err := s.dataSourcesService.List(ctx, entityCtx.Project.ID, &service.ReadOptions{})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -232,7 +233,7 @@ func (s *Server) DeleteDataSourceByName(ctx context.Context,
}

// Get the data source id by name
ds, err := s.dataSourcesService.GetByName(ctx, dsName, entityCtx.Project.ID, nil)
ds, err := s.dataSourcesService.GetByName(ctx, dsName, entityCtx.Project.ID, &service.ReadOptions{})
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions internal/datasources/service/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type serviceTX interface {
// This is a handy helper function to optionally begin a transaction if we've already
// got one.
func beginTx(d *dataSourceService, opts txGetter) (serviceTX, error) {
if opts == nil {
opts = &Options{}
}
if opts.getTransaction() != nil {
return &externalTX{q: opts.getTransaction()}, nil
}
Expand Down

0 comments on commit 41792ca

Please sign in to comment.