gpt4 book ai didi

php - google cloud dns, php api, 添加多个cname

转载 作者:行者123 更新时间:2023-12-05 05:25:01 29 4
gpt4 key购买 nike

我想使用 php api 将额外的 cname 记录添加到 google cloud dns。通过 Web 控制台添加的 sub1.example.com 和 sub2.example.com 的 cname 记录已经存在。但是我收到一个错误

资源记录集“entity.change.additions[0]”无效,因为 DNS 名称“example.com”。可能有一个 CNAME 资源记录集或其他类型的资源记录集,但不能同时有。

<?php
require '../autoload.php';


$client_email = CEMAIL;
$private_key = file_get_contents(PKEY);
$scopes = array('https://www.googleapis.com/auth/ndev.clouddns.readwrite');
$project = PNAME;
$managedZone = "example-com";

$creds = new Google_Auth_AssertionCredentials($client_email,$scopes,$private_key);
$client = new Google_Client();
$client->setAssertionCredentials($creds);

$resource = new Google_Service_Dns_ResourceRecordSet();
$resource->kind = "dns#resourceRecordSet";
$resource->name = "example.com.";
$resource->rrdatas[] = "sub3.example.com.";
$resource->ttl = 300;
$resource->type = "CNAME";

$dns = new Google_Service_Dns($client);

$change = new Google_Service_Dns_Change();
$change->kind = "dns#change";
$change->setAdditions([$resource]);

$r=$dns->changes->create($project,$managedZone,$change);
echo '<pre>'.print_r($r,true).'</pre>';

?>

我也找不到使用 php api 列出现有 cname 记录的方法,因为这会为我提供此处答案的线索。有谁知道如何检索这些,到目前为止的代码

<?php
//include details from above

$dns = new Google_Service_Dns($client);

$r=$dns->managedZones->listManagedZones($project);
echo '<pre>'.print_r($r,true).'</pre>';

$r=$dns->managedZones->get($project,$managedZone);
echo '<pre>'.print_r($r,true).'</pre>';

?>

没有列出这些 cname 记录,尽管 get 和 listManagedZones 方法采用了一个额外的可选参数,但我找不到关于它的文档

来源:https://github.com/google/google-api-php-client/blob/master/src/Google/Service/Dns.php行:416, 395

继续文章:Google Cloud DNS Services - entity.change parameter is required but missing

-

https://developers.google.com/api-client-library/php/

https://developers.google.com/apis-explorer/#p/dns/v1/

https://support.google.com/cloud/answer/6158849?hl=en

https://cloud.google.com/dns/api/v1/resourceRecordSets#resource

https://cloud.google.com/dns/docs

最佳答案

对于那些以后可能会找到这篇文章的人,我已经根据这篇文章回答了我自己的问题

https://www.zeitgeist.se/2014/05/01/google-cloud-dns-how-to/

我注意到在文章的中间,邮件记录的列表在资源的 rrdatas 字段中有根域,在资源的名称属性中有子域,切换了两轮和 voila

$resource = new Google_Service_Dns_ResourceRecordSet();
$resource->kind = "dns#resourceRecordSet";
$resource->name = "sub3.example.com."; //sub
$resource->rrdatas[] = "example.com."; //root domain

txt 添加:

$del = new Google_Service_Dns_ResourceRecordSet();
$del->kind = "dns#resourceRecordSet";
$del->name = "example.com.";
$del->type = "TXT";
$del->ttl = 300;
$del->rrdatas[] = "\"test=test\"";

$add = new Google_Service_Dns_ResourceRecordSet();
$add->kind = "dns#resourceRecordSet";
$add->name = "example.com.";
$add->type = "TXT";
$add->ttl = 300;
$add->rrdatas[] = "\"test2=test2\"";
$add->rrdatas[] = "\"test3=test3\"";

$change->setAdditions([$add]);
$change->setDeletions([$del]);

$r=$dns->changes->create($project,$managedZone,$change);

https://github.com/google/google-api-php-client/tree/master/examples

还有。

+

Looking up Google Cloud DNS records (nslookup) directly

关于php - google cloud dns, php api, 添加多个cname,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32823671/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com