Skip to content

Commit

Permalink
fix: reload views after migrator run
Browse files Browse the repository at this point in the history
  • Loading branch information
artaasadi committed Dec 29, 2024
1 parent e9bad08 commit 9125153
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions jobs/post-install-job/job/migrations/compliance/populate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package compliance
import (
"context"
"fmt"
authApi "github.com/opengovern/og-util/pkg/api"
"github.com/opengovern/og-util/pkg/httpclient"
"github.com/opengovern/opencomply/jobs/post-install-job/job/migrations/inventory"
metadataClient "github.com/opengovern/opencomply/services/metadata/client"
"github.com/opengovern/opencomply/services/metadata/models"

"github.com/opengovern/og-util/pkg/postgres"
Expand Down Expand Up @@ -284,5 +287,12 @@ func (m Migration) Run(ctx context.Context, conf config.MigratorConfig, logger *
return err
}

mClient := metadataClient.NewMetadataServiceClient(conf.Metadata.BaseURL)
err = mClient.ReloadViews(&httpclient.Context{Ctx: ctx, UserRole: authApi.AdminRole})
if err != nil {
logger.Error("failed to reload views", zap.Error(err))
return fmt.Errorf("failed to reload views: %s", err.Error())
}

return nil
}
13 changes: 13 additions & 0 deletions services/metadata/client/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type MetadataServiceClient interface {
SetQueryParameter(ctx *httpclient.Context, request api.SetQueryParameterRequest) error
VaultConfigured(ctx *httpclient.Context) (*string, error)
GetViewsCheckpoint(ctx *httpclient.Context) (*api.GetViewsCheckpointResponse, error)
ReloadViews(ctx *httpclient.Context) error
GetAbout(ctx *httpclient.Context) (*api.About, error)
}

Expand Down Expand Up @@ -150,6 +151,18 @@ func (s *metadataClient) VaultConfigured(ctx *httpclient.Context) (*string, erro
return &status, nil
}

func (s *metadataClient) ReloadViews(ctx *httpclient.Context) error {
url := fmt.Sprintf("%s/api/v1/views/reload", s.baseURL)

if statusCode, err := httpclient.DoRequest(ctx.Ctx, http.MethodPut, url, ctx.ToHeaders(), nil, nil); err != nil {
if 400 <= statusCode && statusCode < 500 {
return echo.NewHTTPError(statusCode, err.Error())
}
return err
}
return nil
}

func (s *metadataClient) GetViewsCheckpoint(ctx *httpclient.Context) (*api.GetViewsCheckpointResponse, error) {
url := fmt.Sprintf("%s/api/v1/views/checkpoint", s.baseURL)
var resp api.GetViewsCheckpointResponse
Expand Down

0 comments on commit 9125153

Please sign in to comment.