Created
October 14, 2023 11:17
-
-
Save matthewgream/df2569e30d7d82ac2ac96a389eeddb53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ----------------------------------------------------------------------------------------------------------------------------------------- | |
// ----------------------------------------------------------------------------------------------------------------------------------------- | |
function gcloud_network_test () { __TEST_SETUP (); | |
debugLog (gcloud_dns_zone_info ()); | |
gcloud_dns_zone_record_list ().forEach (r => debugLog (util_obj_strNiceOrdered (r, ['kind', 'name', 'type', 'ttl', 'rrdatas' ]))); | |
// debugLog (gcloud_dns_zone_record_insert ('vps5.msmv2.gfic.limited.', 'A', '185.126.69.231')); | |
// var x = __gcloud_request ('https://domains.googleapis.com/v1/projects/gfic-website/locations/us-central1'); | |
// debugLog (x); | |
} | |
// ----------------------------------------------------------------------------------------------------------------------------------------- | |
const GDNS_PROJECT = 'gfic-website'; | |
const GDNS_ZONE = 'gfic-limited'; | |
function gcloud_dns_zone_info () { | |
return __gcloud_dns_request (GDNS_PROJECT, GDNS_ZONE); | |
} | |
function gcloud_dns_zone_record_list () { | |
return __gcloud_dns_request (GDNS_PROJECT, GDNS_ZONE, 'rrsets')?.rrsets || Array (); | |
} | |
function gcloud_dns_zone_record_find (name) { | |
return gcloud_dns_zone_record_list ().find (r => r.name.toLowerCase () == name.toLowerCase ()); | |
} | |
function gcloud_dns_zone_record_update (name, type, address) { | |
return __gcloud_dns_request (GDNS_PROJECT, GDNS_ZONE, 'rrsets' + `/${name}/${type}`, 'PATCH', __gcloud_dns_rrset_basic (name, type, 3600, [ address ])); | |
} | |
function gcloud_dns_zone_record_insert (name, type, address) { | |
return __gcloud_dns_request (GDNS_PROJECT, GDNS_ZONE, 'rrsets', 'POST', __gcloud_dns_rrset_basic (name, type, 3600, [ address ])); | |
} | |
// ----------------------------------------------------------------------------------------------------------------------------------------- | |
// https://cloud.google.com/dns/docs/reference/v1 | |
const __gcloud_dns_rrset_basic = (name, type, ttl, rrdatas) => ({ 'kind': 'dns#resourceRecordSet', name, type, ttl, rrdatas }); | |
const __gcloud_dns_api = (project, zone) => `https://dns.googleapis.com/dns/v1/projects/${project}/managedZones/${zone}/`; | |
const __gcloud_dns_request = (project, zone, request = '', method = 'GET', payload = undefined) => __gcloud_request (__gcloud_dns_api (project, zone) + request, method, payload); | |
// ----------------------------------------------------------------------------------------------------------------------------------------- | |
// ----------------------------------------------------------------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment