Skip to content

Commit

Permalink
Wire deps to data source machinery
Browse files Browse the repository at this point in the history
This commit wires the deps data source through the service machinery.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
  • Loading branch information
puerco committed Dec 2, 2024
1 parent 8f46b68 commit 009624f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/datasources/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package datasources
import (
"fmt"

"github.com/mindersec/minder/internal/datasources/deps"
"github.com/mindersec/minder/internal/datasources/rest"
minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
v1datasources "github.com/mindersec/minder/pkg/datasources/v1"
Expand All @@ -26,6 +27,8 @@ func BuildFromProtobuf(ds *minderv1.DataSource) (v1datasources.DataSource, error
switch ds.GetDriver().(type) {
case *minderv1.DataSource_Rest:
return rest.NewRestDataSource(ds.GetRest())
case *minderv1.DataSource_Deps:
return deps.NewDepsDataSource(ds.GetDeps())
default:
return nil, fmt.Errorf("unknown data source type: %T", ds)
}
Expand Down
22 changes: 22 additions & 0 deletions internal/datasources/service/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func dataSourceDBToProtobuf(ds db.DataSource, dsfuncs []db.DataSourcesFunction)
switch dsfType {
case v1datasources.DataSourceDriverRest:
return dataSourceRestDBToProtobuf(outds, dsfuncs)
case v1datasources.DataSourceDriverDeps:
return dataSourceRestDBToProtobuf(outds, dsfuncs)
default:
return nil, fmt.Errorf("unknown data source type: %s", dsfType)
}
Expand All @@ -60,3 +62,23 @@ func dataSourceRestDBToProtobuf(ds *minderv1.DataSource, dsfuncs []db.DataSource

return ds, nil
}

func dataSourceDepsDBToProtobuf(ds *minderv1.DataSource, dsfuncs []db.DataSourcesFunction) (*minderv1.DataSource, error) {
ds.Driver = &minderv1.DataSource_Deps{
Deps: &minderv1.DepsDataSource{
Def: make(map[string]*minderv1.DepsDataSource_Def, len(dsfuncs)),
},
}

for _, dsf := range dsfuncs {
key := dsf.Name
dsfToParse := &minderv1.DepsDataSource_Def{}
if err := protojson.Unmarshal(dsf.Definition, dsfToParse); err != nil {
return nil, fmt.Errorf("failed to unmarshal data source definition for %s: %w", key, err)
}

ds.GetDeps().Def[key] = dsfToParse
}

return ds, nil
}
17 changes: 17 additions & 0 deletions internal/datasources/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,23 @@ func addDataSourceFunctions(
return fmt.Errorf("failed to create data source function: %w", err)
}
}
case *minderv1.DataSource_Deps:
for name, def := range drv.Deps.GetDef() {
defBytes, err := protojson.Marshal(def)
if err != nil {
return fmt.Errorf("failed to marshal REST definition: %w", err)
}

if _, err := tx.AddDataSourceFunction(ctx, db.AddDataSourceFunctionParams{
DataSourceID: dsID,
ProjectID: projectID,
Name: name,
Type: v1datasources.DataSourceDriverDeps,
Definition: defBytes,
}); err != nil {
return fmt.Errorf("failed to create data source function: %w", err)
}
}
default:
return fmt.Errorf("unsupported data source driver type: %T", drv)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/datasources/v1/datasources.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
const (
// DataSourceDriverRest is the driver type for a REST data source.
DataSourceDriverRest = "rest"

// DataSourceDriverDeps is the driver type for the dependency exctractor.
DataSourceDriverDeps = "deps"
)

// DataSourceFuncKey is the key that uniquely identifies a data source function.
Expand Down

0 comments on commit 009624f

Please sign in to comment.