@@ -7,23 +7,57 @@ import { IRuntimeImagesResponse } from '../transmitter/types';
77import { NeedleOptions } from 'needle' ;
88import { Agent as HttpsAgent } from 'https' ;
99
10+ const httpsAgent = new HttpsAgent ( {
11+ keepAlive : true ,
12+ // We agreed with Sysdig to skip TLS certificates validation for HTTPS connection.
13+ rejectUnauthorized : false ,
14+ } ) ;
15+
16+ function getSysdigUrl ( ) : string {
17+ return config . SYSDIG_ENDPOINT + '/v1/runtimeimages' ;
18+ }
19+
20+ function getSysdigAuthHeader ( ) : string {
21+ return `Bearer ${ config . SYSDIG_TOKEN } ` ;
22+ }
23+
1024function isSuccessStatusCode ( statusCode : number | undefined ) : boolean {
1125 return statusCode !== undefined && statusCode >= 200 && statusCode < 300 ;
1226}
1327
28+ /** NOTE: This function can throw, so the caller should handle errors. */
29+ export async function validateConnectivity ( ) : Promise < void > {
30+ const url = getSysdigUrl ( ) ;
31+ const header = getSysdigAuthHeader ( ) ;
32+ const reqOptions : NeedleOptions = {
33+ agent : httpsAgent ,
34+ headers : {
35+ authorization : header ,
36+ } ,
37+ timeout : 10_000 ,
38+ } ;
39+
40+ const limit : number = 1 ;
41+ const cursor : string = '' ;
42+ const { response } = await retryRequest (
43+ 'get' ,
44+ `${ url } ?limit=${ limit } &cursor=${ cursor } ` ,
45+ { } ,
46+ reqOptions ,
47+ ) ;
48+ if ( ! isSuccessStatusCode ( response . statusCode ) ) {
49+ throw new Error ( `${ response . statusCode } ${ response . statusMessage } ` ) ;
50+ }
51+ }
52+
1453export async function scrapeData ( ) : Promise < void > {
15- const base : string = config . SYSDIG_ENDPOINT ;
16- const header : string = `Bearer ${ config . SYSDIG_TOKEN } ` ;
54+ const url = getSysdigUrl ( ) ;
55+ const header = getSysdigAuthHeader ( ) ;
1756
18- const url : string = base + '/v1/runtimeimages' ;
1957 // limit: min 1, max 500, default 250
2058 const limit : number = 10 ;
2159 const reqOptions : NeedleOptions = {
22- agent : new HttpsAgent ( {
23- keepAlive : true ,
24- // We agreed with Sysdig to skip TLS certificates validation for HTTPS connection.
25- rejectUnauthorized : false ,
26- } ) ,
60+ agent : httpsAgent ,
2761 headers : {
2862 authorization : header ,
2963 } ,
0 commit comments