Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add inventory base url #2312

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
}
}
Loading