in src/parse-instance-connection-name.ts [95:122]
export function parseInstanceConnectionName(
instanceConnectionName: string | undefined
): InstanceConnectionInfo {
if (!instanceConnectionName) {
throw new CloudSQLConnectorError({
message:
'Missing instance connection name, expected: "PROJECT:REGION:INSTANCE"',
code: 'ENOCONNECTIONNAME',
});
}
const matches = String(instanceConnectionName).match(connectionNameRegex);
if (!matches || !matches.groups) {
throw new CloudSQLConnectorError({
message:
'Malformed instance connection name provided: expected format ' +
`of "PROJECT:REGION:INSTANCE", got ${instanceConnectionName}`,
code: 'EBADCONNECTIONNAME',
});
}
return {
projectId: matches.groups.projectId,
regionId: matches.groups.regionId,
instanceId: matches.groups.instanceId,
domainName: undefined,
};
}