Skip to content

Commit

Permalink
Merge pull request #2482 from opengovern/fix-integration-plugins
Browse files Browse the repository at this point in the history
fix: add integration plugins apis
  • Loading branch information
artaasadi authored Jan 17, 2025
2 parents 925225c + 98b7823 commit 2683f90
Show file tree
Hide file tree
Showing 11 changed files with 532 additions and 44 deletions.
6 changes: 3 additions & 3 deletions jobs/cloudql-init-job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/opengovern/og-util/pkg/httpclient"
"github.com/opengovern/og-util/pkg/postgres"
"github.com/opengovern/og-util/pkg/steampipe"
"github.com/opengovern/opencomply/jobs/post-install-job/job/migrations/integration-type/models"
"github.com/opengovern/opencomply/services/integration/client"
"github.com/opengovern/opencomply/services/integration/models"
"go.uber.org/zap"
"os"
"os/exec"
Expand Down Expand Up @@ -41,13 +41,13 @@ func (j *Job) Run(ctx context.Context) error {
return err
}

var integrations []models.IntegrationTypeBinaries
var integrations []models.IntegrationPlugin
err = db.Find(&integrations).Error
if err != nil {
j.logger.Error("failed to get integration binaries", zap.Error(err))
return err
}
var integrationMap = make(map[string]*models.IntegrationTypeBinaries)
var integrationMap = make(map[string]*models.IntegrationPlugin)
for _, integration := range integrations {
integration := integration
integrationMap[integration.IntegrationType.String()] = &integration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/hashicorp/go-getter"
"github.com/opengovern/og-util/pkg/integration"
"github.com/opengovern/opencomply/jobs/post-install-job/config"
"github.com/opengovern/opencomply/jobs/post-install-job/job/migrations/integration-type/models"
"github.com/opengovern/opencomply/services/integration/models"
"go.uber.org/zap"
"os"
)
Expand Down Expand Up @@ -56,7 +56,7 @@ func (g *GitParser) ExtractIntegrations(logger *zap.Logger) error {
return nil
}

func (g *GitParser) ExtractIntegrationBinaries(logger *zap.Logger, iPlugin IntegrationPlugin) (*models.IntegrationTypeBinaries, error) {
func (g *GitParser) ExtractIntegrationBinaries(logger *zap.Logger, iPlugin IntegrationPlugin) (*models.IntegrationPlugin, error) {
baseDir := "/integration-types"

// create tmp directory if not exists
Expand Down Expand Up @@ -117,7 +117,7 @@ func (g *GitParser) ExtractIntegrationBinaries(logger *zap.Logger, iPlugin Integ
}

logger.Info("done reading files", zap.String("url", url), zap.String("integrationType", iPlugin.IntegrationType.String()), zap.Int("integrationPluginSize", len(integrationPlugin)), zap.Int("cloudqlPluginSize", len(cloudqlPlugin)))
return &models.IntegrationTypeBinaries{
return &models.IntegrationPlugin{
IntegrationType: iPlugin.IntegrationType,
URL: url,
IntegrationPlugin: integrationPlugin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/opengovern/og-util/pkg/postgres"
"github.com/opengovern/opencomply/jobs/post-install-job/config"
"github.com/opengovern/opencomply/jobs/post-install-job/db"
"github.com/opengovern/opencomply/jobs/post-install-job/job/migrations/integration-type/models"
"github.com/opengovern/opencomply/services/integration/models"
"go.uber.org/zap"
"gorm.io/gorm"
"gorm.io/gorm/clause"
Expand Down Expand Up @@ -36,7 +36,7 @@ func (m Migration) Run(ctx context.Context, conf config.MigratorConfig, logger *
}
dbm := db.Database{ORM: orm}

err = dbm.ORM.AutoMigrate(&models.IntegrationTypeBinaries{})
err = dbm.ORM.AutoMigrate(&models.IntegrationPlugin{})
if err != nil {
logger.Error("failed to auto migrate integration binaries", zap.Error(err))
return err
Expand All @@ -49,7 +49,7 @@ func (m Migration) Run(ctx context.Context, conf config.MigratorConfig, logger *
}

err = dbm.ORM.Transaction(func(tx *gorm.DB) error {
err := tx.Model(&models.IntegrationTypeBinaries{}).Where("1 = 1").Unscoped().Delete(&models.IntegrationTypeBinaries{}).Error
err := tx.Model(&models.IntegrationPlugin{}).Where("1 = 1").Unscoped().Delete(&models.IntegrationPlugin{}).Error
if err != nil {
logger.Error("failed to delete integration binaries", zap.Error(err))
return err
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion services/integration/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func New(
func (api *API) Register(e *echo.Echo) {
integrationsApi := integrations.New(api.vault, api.database, api.logger, api.steampipeConn, api.kubeClient, api.typeManager)
cred := credentials.New(api.vault, api.database, api.logger)
integrationType := integration_type2.New(api.logger, api.typeManager)
integrationType := integration_type2.New(api.typeManager, api.database, api.logger)

integrationsApi.Register(e.Group("/api/v1/integrations"))
cred.Register(e.Group("/api/v1/credentials"))
Expand Down
Loading

0 comments on commit 2683f90

Please sign in to comment.