@@ -19,6 +19,7 @@ import useAsync from 'react-use/lib/useAsync';
1919import Alert from '@material-ui/lab/Alert' ;
2020import { useEntity } from '@backstage/plugin-catalog-react' ;
2121import { useApi , configApiRef } from '@backstage/core-plugin-api' ;
22+ import { sysdigApiRef } from '../../api' ;
2223
2324import {
2425 // annotations
@@ -56,9 +57,6 @@ import {
5657 getScope ,
5758 getResourceName ,
5859 getTitleWithBacklink ,
59-
60- API_PROXY_BASE_PATH ,
61- API_INVENTORY ,
6260 getBacklink
6361} from '../../lib'
6462
@@ -212,20 +210,20 @@ export const DenseTable = ({ postureScans, title }: DenseTableProps) => {
212210export const SysdigPostureFetchComponent = ( ) => {
213211 const { entity } = useEntity ( ) ;
214212 const backendUrl = useApi ( configApiRef ) . getString ( 'backend.baseUrl' ) ;
213+ const sysdigApiClient = useApi ( sysdigApiRef ) ;
215214 let endpoint : string | undefined = useApi ( configApiRef ) . getOptionalString ( "sysdig.endpoint" ) ;
216215 let backlink_config : string | undefined = useApi ( configApiRef ) . getOptionalString ( "sysdig.backlink" ) ;
217216
218217 var backlink = getBacklink ( endpoint , backlink_config , "inventory" ) ;
219218 const annotations = entity . metadata . annotations ;
220219
221- let uri = backendUrl + API_PROXY_BASE_PATH + API_INVENTORY ;
222220 let filter = '?filter=' ;
223221 var name ;
224222
225223 if ( annotations ) {
226224
227225 if ( SYSDIG_CUSTOM_FILTER_ANNOTATION in annotations ) {
228- uri += '? filter=' + annotations [ SYSDIG_CUSTOM_FILTER_ANNOTATION ]
226+ filter += annotations [ SYSDIG_CUSTOM_FILTER_ANNOTATION ]
229227 } else {
230228
231229 var filters = [ ]
@@ -355,17 +353,11 @@ export const SysdigPostureFetchComponent = () => {
355353 }
356354
357355 filter += filters . join ( ' and ' ) ;
358- uri += filter ;
359356 backlink += filter ;
360357 }
361358
362359 const { value, loading, error } = useAsync ( async ( ) : Promise < PostureScan [ ] > => {
363- const requestOptions = {
364- method : 'GET' ,
365- } ;
366-
367- const response = await fetch ( uri , requestOptions ) ;
368- const data = await response . json ( ) ;
360+ const data = await sysdigApiClient . fetchInventory ( filter )
369361 return data . data ;
370362 } , [ ] ) ;
371363
@@ -380,4 +372,4 @@ export const SysdigPostureFetchComponent = () => {
380372 } else {
381373 return < Alert severity = "warning" > Please, add annotations to the entity.</ Alert > ;
382374 }
383- } ;
375+ } ;
0 commit comments