Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/dns/googledns/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,20 @@ export default defineDns<Config>({
const token = await getAccessToken();
const project = config.projectId ?? _secret('GOOGLE_PROJECT_ID');
if (!project) throw new Error('GOOGLE_PROJECT_ID not set');
const [type, name] = recordId.split('/');
const separatorIndex = recordId.indexOf('/');
if (separatorIndex <= 0 || separatorIndex === recordId.length - 1) {
throw new Error(`Google Cloud DNS deleteRecord: invalid record id "${recordId}"`);
}
const type = recordId.slice(0, separatorIndex);
const name = recordId.slice(separatorIndex + 1);
// Need to fetch the rrset to get current rrdatas for the deletion entry.
const existing = (await this.listRecords(zoneId, config)).filter(
r => r.type === type && (r.name === name || r.name === name.replace(/\.$/, '')),
);
if (existing.length === 0) return;
const firstRecord = existing[0];
if (!firstRecord) return;
const fqdn = name.endsWith('.') ? name : `${name}.`;
const ttl = existing[0].ttl;
const ttl = firstRecord.ttl;
const res = await fetch(`${API}/projects/${project}/managedZones/${zoneId}/changes`, {
method: 'POST',
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
Expand Down