import { ensureTrailingSlash } from "../../../util/url.js";
import { ExternalHostError } from "../../../types/errors/external-host-error.js";
import { withCache } from "../../../util/cache/package/with-cache.js";
import { Datasource } from "../datasource.js";
//#region lib/modules/datasource/terraform-module/base.ts
const terraformId = "terraform";
var TerraformDatasource = class TerraformDatasource extends Datasource {
	static id = terraformId;
	async _getTerraformServiceDiscoveryResult(registryUrl) {
		const discoveryURL = TerraformDatasource.getDiscoveryUrl(registryUrl);
		return (await this.http.getJsonUnchecked(discoveryURL)).body;
	}
	getTerraformServiceDiscoveryResult(registryUrl) {
		return withCache({
			namespace: `datasource-${terraformId}`,
			key: TerraformDatasource.getDiscoveryUrl(registryUrl),
			ttlMinutes: 1440
		}, () => this._getTerraformServiceDiscoveryResult(registryUrl));
	}
	static getDiscoveryUrl(registryUrl) {
		return `${ensureTrailingSlash(registryUrl)}.well-known/terraform.json`;
	}
	handleHttpErrors(err) {
		// istanbul ignore if
		if (["EAI_AGAIN"].includes(err.code)) throw new ExternalHostError(err);
		// istanbul ignore if
		if (err.response?.statusCode === 503) throw new ExternalHostError(err);
	}
};
//#endregion
export { TerraformDatasource };

//# sourceMappingURL=base.js.map