import { ExternalHostError } from '../../types/errors/external-host-error' ; import { cache } from '../../util/cache/package/decorator' ; import type { HttpError } from '../../util/http/types' ; import { ensureTrailingSlash } from '../../util/url' ; import { Datasource } from '../datasource' ; import type { ServiceDiscoveryResult } from './types' ; export abstract class TerraformDatasource extends Datasource { static id = 'terraform' ; @ cache ( { namespace : `datasource-${ TerraformDatasource . id }` , key : ( registryUrl ) => TerraformDatasource . getDiscoveryUrl ( registryUrl ) , ttlMinutes : 1440 , } ) async getTerraformServiceDiscoveryResult ( registryUrl ) { const discoveryURL = TerraformDatasource . getDiscoveryUrl ( registryUrl ) ; const serviceDiscovery = ( await this . http . getJson < ServiceDiscoveryResult > ( discoveryURL ) ) . body ; return serviceDiscovery ; } private static getDiscoveryUrl ( registryUrl ) { return `${ ensureTrailingSlash ( registryUrl ) }.well-known/terraform.json` ; } override handleSpecificErrors ( err ) { const failureCodes = [ 'EAI_AGAIN' ] ; if ( failureCodes . includes ( err . code ) ) { throw new ExternalHostError ( err ) ; } if ( err . response ?. statusCode === 503 ) { throw new ExternalHostError ( err ) ; } } }