Azure / azure-sdk-for-php

Microsoft Azure SDK for PHP
http://azure.microsoft.com/en-us/develop/php/
Apache License 2.0
415 stars 274 forks source link

Unable to create DNS RecordSet using preview ARM API #904

Open pvasilevich opened 7 years ago

pvasilevich commented 7 years ago

I'm using preview ARM API.

in API you have method:

public function createOrUpdate($resourceGroupName, $zoneName, $relativeRecordSetName, array $recordType, array $parameters, $ifMatch = null, $ifNoneMatch = null, array $customHeaders = [])

in class MicrosoftAzure\Arm\Dns\RecordSets. This method requires that $recordType is an array. This method calls another method

public function createOrUpdateAsync($resourceGroupName, $zoneName, $relativeRecordSetName, array $recordType, array $parameters, $ifMatch = null, $ifNoneMatch = null, array $customHeaders = [])

This method also declares that $recordType is an array.

inside this function we can see:

$path = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/dnszones/{zoneName}/{recordType}/{relativeRecordSetName}';

When I'm trying to use ['NS'] as $recordType argument, then it will be converted to ".../Array/..." and PHP Notice: Array to string conversion is generated. Trying to pass any other object as argument brings an error: PHP : Argument 4 passed to MicrosoftAzure\Arm\Dns\RecordSets::createOrUpdate() must be of the type array, object given ...

in docblock for these functions there is class RecordType.

     * @param RecordType $recordType The type of DNS record. Possible values
     * include: 'A', 'AAAA', 'CNAME', 'MX', 'NS', 'PTR', 'SOA', 'SRV', 'TXT'

But in fact there is no such class declared.

yaqiyang commented 7 years ago

@sergey-shandar , that seems to be a bug in the AutoRest PHP generator which should treat RecordType as a simple type

sergey-shandar commented 7 years ago

@yaqiyang Thanks for the hint, I will have a look.

pvasilevich commented 7 years ago

I have manually removed "array" from functions declaration and checked how it will work for simple string argument. I've faced another issue:

Code: 400
Value: Bad Request
details (if any): {"code":"BadRequest","message":"The domain name '{relativerecordsetname}.domain.example.com' is invalid. The provided record set relative name '{relativerecordsetname}' is invalid."}.

What I see in code is: \Arm\Dns\RecordSets.php

        $path = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/dnszones/{zoneName}/{recordType}/{relativeRecordSetName}';
...
        $path = strtr($path, ['{resourceGroupName}' => $resourceGroupName, '{zoneName}' => $zoneName, '{recordType}' => $recordType, '{subscriptionId}' => $this->_client->getSubscriptionId()]);

there is no replacement for {relativeRecordSetName} placeholder. Should I post another issue for that?

sergey-shandar commented 7 years ago

Should I post another issue for that?

It's not required but it's up to you.

jeliasson commented 6 years ago

The methods still take array $recordType where is should be a string, and '{relativeRecordSetName}' => $relativeRecordSetName is missing in the replacement. Is there any work being done to the arm branch?

Can anyone give an example of the $parameters for creating a A-Record? I have tried different variations, but no TTL or ip-address is set. Record is created without the values.

// Test 1
'TTL' => 3600,
'ARecords' => '123.123.123.123'

// Test 2
'ttl' => 3600,
'ARecords' => ['123.123.123.123']

// Test 3
'Ttl' => 3600,
'ARecords' => [
  'Ipv4Address' => '123.123.123.123'
]

// Test 4
'Ttl' => 3600,
'ARecords' => [
  ['Ipv4Address' => '123.123.123.123']
]

Thanks!

Edit: I have tried the arm2 branch with the same result.