Files
Arnaud Dezandee 914c55b03c refactor(terraform-module): replace interfaces with zod schemas and inline fixtures (#42399)
* refactor(terraform-module): extract getRegistryRepository to utils

* refactor(terraform-module): add zod schemas and validate service discovery

* refactor(terraform-module): use zod schemas in query methods and inline fixtures

* fix(terraform): update hash test to use valid service discovery response

* refactor(terraform-module): address review feedback

* style: biome lint fix

* refactor(terraform-module): address review feedback
2026-04-15 13:41:28 +00:00

44 lines
1.2 KiB
TypeScript

import { regEx } from '../../../util/regex.ts';
import { coerceString } from '../../../util/string.ts';
import { isHttpUrl, joinUrlParts } from '../../../util/url.ts';
import type {
ServiceDiscoveryEndpointType,
ServiceDiscoveryResponse,
} from './schema.ts';
import type { RegistryRepository } from './types.ts';
export function createSDBackendURL(
registryURL: string,
sdType: ServiceDiscoveryEndpointType,
sdResult: ServiceDiscoveryResponse,
subPath: string,
): string {
const sdEndpoint = sdResult[sdType] ?? '';
const fullPath = joinUrlParts(sdEndpoint, subPath);
if (isHttpUrl(fullPath)) {
return fullPath;
}
return joinUrlParts(registryURL, fullPath);
}
export function getRegistryRepository(
packageName: string,
registryUrl: string | undefined,
): RegistryRepository {
let registry: string;
const split = packageName.split('/');
if (split.length > 3 && split[0].includes('.')) {
registry = split.shift()!;
} else {
registry = coerceString(registryUrl);
}
if (!regEx(/^https?:\/\//).test(registry)) {
registry = `https://${registry}`;
}
const repository = split.join('/');
return {
registry,
repository,
};
}