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

Update AccessRules to allow for IPv6.

Open a904guy opened this issue 3 years ago • 8 comments

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 avatar May 14 '21 15:05 a904guy

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 avatar May 14 '21 15:05 a904guy

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

In ToolInfo.php line 50:
                         
  Undefined index: name  

Please advise.

a904guy avatar May 14 '21 16:05 a904guy

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

jacobbednarz avatar Jun 20 '21 23:06 jacobbednarz

@jacobbednarz Done.

a904guy avatar Jun 21 '21 10:06 a904guy

I've pulled the upstream changes down.

a904guy avatar Jun 21 '21 11:06 a904guy

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

jacobbednarz avatar Jun 22 '21 08:06 jacobbednarz

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

a904guy avatar Jun 22 '21 11:06 a904guy

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.

jacobbednarz avatar Jun 23 '21 00:06 jacobbednarz