diff --git a/services/inventory/client/inventory.go b/services/inventory/client/inventory.go index 378982a17..157c78a69 100644 --- a/services/inventory/client/inventory.go +++ b/services/inventory/client/inventory.go @@ -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 { @@ -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 +} diff --git a/services/tasks/worker/consts/baseurl.go b/services/tasks/worker/consts/baseurl.go new file mode 100644 index 000000000..f370834be --- /dev/null +++ b/services/tasks/worker/consts/baseurl.go @@ -0,0 +1,5 @@ +package consts + +const ( + InventoryBaseURL = "INVENTORY_BASEURL" +) diff --git a/services/tasks/worker/worker.go b/services/tasks/worker/worker.go index 869582415..af6d5defa 100644 --- a/services/tasks/worker/worker.go +++ b/services/tasks/worker/worker.go @@ -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 { @@ -188,5 +190,9 @@ func defaultEnvs(cfg config.Config, taskConfig *Task) []corev1.EnvVar { Name: consts.ElasticSearchAssumeRoleArnEnv, Value: "", }, + { + Name: consts.InventoryBaseURL, + Value: InventoryBaseURL, + }, } }