diff --git a/cmd/cli/app/datasource/common.go b/cmd/cli/app/datasource/common.go index 522c513fd1..2a137c8934 100644 --- a/cmd/cli/app/datasource/common.go +++ b/cmd/cli/app/datasource/common.go @@ -122,7 +122,7 @@ func appendDataSourcePropertiesToName(ds *minderv1.DataSource) string { name := ds.Name properties := []string{} // add the type property if it is present - dType := getDataSourceType(ds) + dType := ds.GetDriverType() if dType != "" { properties = append(properties, fmt.Sprintf("type: %s", dType)) } @@ -138,14 +138,6 @@ func appendDataSourcePropertiesToName(ds *minderv1.DataSource) string { return name } -// getDataSourceType returns the type of data source -func getDataSourceType(ds *minderv1.DataSource) string { - if ds.GetRest() != nil { - return "REST" - } - return "Unknown" -} - // initializeTableForList initializes the table for listing data sources func initializeTableForList() table.Table { return table.New(table.Simple, layouts.DataSourceList, nil) diff --git a/cmd/cli/app/datasource/get.go b/cmd/cli/app/datasource/get.go index 904324d8ca..bc37c8e48f 100644 --- a/cmd/cli/app/datasource/get.go +++ b/cmd/cli/app/datasource/get.go @@ -90,7 +90,7 @@ func outputDataSource(cmd *cobra.Command, format string, ds *minderv1.DataSource cmd.Println(out) case app.Table: t := table.New(table.Simple, layouts.Default, []string{"ID", "Name", "Type"}) - t.AddRow(ds.Id, ds.Name, getDataSourceType(ds)) + t.AddRow(ds.Id, ds.Name, ds.GetDriverType()) t.Render() default: return fmt.Errorf("unsupported output format: %s", format) diff --git a/cmd/cli/app/datasource/list.go b/cmd/cli/app/datasource/list.go index 3cf24c588a..3dd7db10af 100644 --- a/cmd/cli/app/datasource/list.go +++ b/cmd/cli/app/datasource/list.go @@ -63,7 +63,7 @@ func listCommand(ctx context.Context, cmd *cobra.Command, _ []string, conn *grpc case app.Table: t := table.New(table.Simple, layouts.Default, []string{"ID", "Name", "Type"}) for _, ds := range resp.GetDataSources() { - t.AddRow(ds.Id, ds.Name, getDataSourceType(ds)) + t.AddRow(ds.Id, ds.Name, ds.GetDriverType()) } t.Render() default: diff --git a/pkg/api/protobuf/go/minder/v1/datasources.go b/pkg/api/protobuf/go/minder/v1/datasources.go index 0c1a7389d4..82560220f7 100644 --- a/pkg/api/protobuf/go/minder/v1/datasources.go +++ b/pkg/api/protobuf/go/minder/v1/datasources.go @@ -3,6 +3,8 @@ package v1 +import v1datasources "github.com/mindersec/minder/pkg/datasources/v1" + // GetContext returns the v2 context from the CreateDataSourceRequest data source. func (r *CreateDataSourceRequest) GetContext() *ContextV2 { return r.DataSource.GetContext() @@ -13,3 +15,17 @@ func (r *CreateDataSourceRequest) GetContext() *ContextV2 { func (r *UpdateDataSourceRequest) GetContext() *ContextV2 { return r.DataSource.GetContext() } + +// GetDriverType returns the string representation of the driver type of the data source. +func (ds *DataSource) GetDriverType() string { + if ds == nil { + return "" + } + + switch ds.GetDriver().(type) { + case *DataSource_Rest: + return v1datasources.DataSourceDriverRest + default: + return "unknown" + } +}