cloudflare / cloudflare-php

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

Update AccessRules to allow for IPv6. #174

Open a904guy opened 3 years ago

a904guy commented 3 years ago

Currently it is impossible to set an IPv6 address to an AccessRule from the API.

This pull will add a new method setIPv6 to match setIP which only supports IPv4.

Thanks, Andy

a904guy commented 3 years ago

Let me know if the method name doesn't fit any guidelines and I'll adjust the request.

I've tested this locally, and made sure the config property was correct and inline with the documentation about cloudflare Access Rules.

Documentation Stated Is Here

image

There was no way to modify the configuration from a user standpoint because it was a private property.

a904guy commented 3 years ago

I don't believe the Travis-CI test failures are related to my code...

In ToolInfo.php line 50:

  Undefined index: name  

Please advise.

jacobbednarz commented 3 years ago

please rebase off the latest master branch, the CI provider has been fixed

a904guy commented 3 years ago

@jacobbednarz Done.

a904guy commented 3 years ago

I've pulled the upstream changes down.

jacobbednarz commented 3 years ago

looks like you've got some lint issues to address and we can merge this.

a904guy commented 3 years ago

I don't have this pulled down to a local machine, been working inside github.

Can you tell me what the lint issue is?

I don't see it being declared in the output.


Loaded config default from ".php_cs".
   1) cloudflare-php/src/Configurations/AccessRules.php

Checked all files in 0.589 seconds, 12.000 MB memory used
make: *** [Makefile:9: lint] Error 8
Error: Process completed with exit code 2.```
jacobbednarz commented 3 years ago

Locally, you would run make fix and it would handle the fix for you. In this case, it's the braces and spacing.

@@ -9,9 +9,9 @@ class AccessRules implements Configurations
     public function setIP(string $value)
     {
         if (strpos($value, ':') !== false) {
-          $this->config = ['target' => 'ip6', 'value' => $value];
+            $this->config = ['target' => 'ip6', 'value' => $value];
         } else {
-          $this->config = ['target' => 'ip', 'value' => $value];
+            $this->config = ['target' => 'ip', 'value' => $value];
         }
     }

PHPMD also wants this to not use else (which I don't agree with) so we can just suppress that by prepending the method with

/**  
 * @SuppressWarnings(PHPMD.ElseExpression)
 */

For best results, I'd recommend pulling this locally and using the tools provided or use something like GitHub codespaces.