cloudflare-php icon indicating copy to clipboard operation
cloudflare-php copied to clipboard

Support voor SRV records Add/ Update

Open BlueRayNL opened this issue 4 years ago • 6 comments

Hi,

i am missing support for SRV records Add & Update

BlueRayNL avatar Jan 18 '21 18:01 BlueRayNL

Same problem, i have tried to create an SRV record but it isn't working.

Klay4 avatar Jan 28 '21 08:01 Klay4

Add this function on vendor/cloudflare/sdk/src/Endpoints/DNS.PHP

public function addRecordSRV(
        string $zoneID,
        array $data = []
    ): bool {
        $options = [
            'type' => 'SRV'
        ];
        
        if (!empty($data)) {
            $options['data'] = $data;
        }

        $user = $this->adapter->post('zones/' . $zoneID . '/dns_records', $options);

        $this->body = json_decode($user->getBody());

        if (isset($this->body->result->id)) {
            return true;
        }

        return false;
    }

In your php file:

$query = [
    'service' => '_exemple', // Service name
    'proto' => '_tcp', // _tcp or _udp
    'name' => 'exemple', // Record name
    'priority' => 10, // Set your priority
    'weight' => 10, // Set your weight
    'port' => 64738, // Set your port
    'target' => 's1.exemple.com'

];

$dns->addRecordSRV($zoneID, $query);

Klay4 avatar Jan 28 '21 08:01 Klay4

Add this function on vendor/cloudflare/sdk/src/Endpoints/DNS.PHP

public function addRecordSRV(
        string $zoneID,
        array $data = []
    ): bool {
        $options = [
            'type' => 'SRV'
        ];
        
        if (!empty($data)) {
            $options['data'] = $data;
        }

        $user = $this->adapter->post('zones/' . $zoneID . '/dns_records', $options);

        $this->body = json_decode($user->getBody());

        if (isset($this->body->result->id)) {
            return true;
        }

        return false;
    }

In your php file:

$query = [
    'service' => '_exemple', // Service name
    'proto' => '_tcp', // _tcp or _udp
    'name' => 'exemple', // Record name
    'priority' => 10, // Set your priority
    'weight' => 10, // Set your weight
    'port' => 64738, // Set your port
    'target' => 's1.exemple.com'

];

$dns->addRecordSRV($zoneID, $query);

Open a Merge request so its ending up in the master as well :)

BlueRayNL avatar Jan 28 '21 18:01 BlueRayNL

How is this not included yet?

QuentinWehkamp avatar Jan 18 '22 10:01 QuentinWehkamp

@QuentinWehkamp I really don't know why Travis CI can't build the pull https://github.com/cloudflare/cloudflare-php/pull/160 So, probably that's why it hasn't been alerady merged.

Klay4 avatar Jan 18 '22 10:01 Klay4

Oh well, I'm glad a fix at least exists.

QuentinWehkamp avatar Jan 18 '22 12:01 QuentinWehkamp