cloudflare / cloudflare-php

PHP library for the Cloudflare v4 API
BSD 3-Clause "New" or "Revised" License
614 stars 223 forks source link

Support voor SRV records Add/ Update #158

Open BlueRayNL opened 3 years ago

BlueRayNL commented 3 years ago

Hi,

i am missing support for SRV records Add & Update

Klay4 commented 3 years ago

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

Klay4 commented 3 years ago

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);
BlueRayNL commented 3 years ago

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 :)

QuentinWehkamp commented 2 years ago

How is this not included yet?

Klay4 commented 2 years ago

@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.

QuentinWehkamp commented 2 years ago

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