Skip to content

Commit

Permalink
Merge pull request #2312 from opengovern/fix-tasks
Browse files Browse the repository at this point in the history
fix: add inventory base url
  • Loading branch information
artaasadi authored Dec 27, 2024
2 parents 96e80cb + c05d547 commit d907cba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
19 changes: 19 additions & 0 deletions services/inventory/client/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type InventoryServiceClient interface {
ListResourceCollectionsMetadata(ctx *httpclient.Context, ids []string) ([]api.ResourceCollection, error)
GetTablesResourceCategories(ctx *httpclient.Context, tables []string) ([]api.CategoriesTables, error)
GetResourceCategories(ctx *httpclient.Context, tables []string, categories []string) (*api.GetResourceCategoriesResponse, error)
RunQueryByID(ctx *httpclient.Context, req api.RunQueryByIDRequest) (*api.RunQueryResponse, error)
}

type inventoryClient struct {
Expand Down Expand Up @@ -340,3 +341,21 @@ func (s *inventoryClient) ListResourceCollections(ctx *httpclient.Context) ([]ap
}
return response, nil
}

func (s *inventoryClient) RunQueryByID(ctx *httpclient.Context, req api.RunQueryByIDRequest) (*api.RunQueryResponse, error) {
url := fmt.Sprintf("%s/api/v3/query/run", s.baseURL)

reqBytes, err := json.Marshal(req)
if err != nil {
return nil, err
}

var resp api.RunQueryResponse
if statusCode, err := httpclient.DoRequest(ctx.Ctx, http.MethodPost, url, ctx.ToHeaders(), reqBytes, &resp); err != nil {
if 400 <= statusCode && statusCode < 500 {
return nil, echo.NewHTTPError(statusCode, err.Error())
}
return nil, err
}
return &resp, nil
}
5 changes: 5 additions & 0 deletions services/tasks/worker/consts/baseurl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package consts

const (
InventoryBaseURL = "INVENTORY_BASEURL"
)
6 changes: 6 additions & 0 deletions services/tasks/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var (
ESUsername = os.Getenv("ELASTICSEARCH_USERNAME")
ESPassword = os.Getenv("ELASTICSEARCH_PASSWORD")
ESIsOnAks = os.Getenv("ELASTICSEARCH_ISONAKS")

InventoryBaseURL = os.Getenv("INVENTORY_BASEURL")
)

func CreateWorker(ctx context.Context, cfg config.Config, kubeClient client.Client, taskConfig *Task, namespace string) error {
Expand Down Expand Up @@ -188,5 +190,9 @@ func defaultEnvs(cfg config.Config, taskConfig *Task) []corev1.EnvVar {
Name: consts.ElasticSearchAssumeRoleArnEnv,
Value: "",
},
{
Name: consts.InventoryBaseURL,
Value: InventoryBaseURL,
},
}
}

0 comments on commit d907cba

Please sign in to comment.