pachadotdev / analogsea

Digital Ocean R client
https://pacha.dev/analogsea/
Apache License 2.0
155 stars 24 forks source link

analogsea::firewall_create doesnt work anymore #223

Open Sade154 opened 6 days ago

Sade154 commented 6 days ago

I encountered an issue with the example code below provided in the documentation for the firewall_createfunction.

Code from Documentation:

library(analogsea)
inbound <- list(list(protocol = "tcp", ports = "80", 
                     sources = list(addresses = "18.0.0.0/8")))
outbound <- list(list(protocol = "tcp", ports = "80", 
                      destinations = list(addresses = "0.0.0.0/0")))
res <- firewall_create("myfirewall", inbound, outbound)
res

Error received:

Error: missing name

Also, the message error is weird as the name is provided in the first argument.

pachadotdev commented 5 days ago

I encountered an issue with the example code below provided in the documentation for the firewall_createfunction.

Code from Documentation:

library(analogsea)
inbound <- list(list(protocol = "tcp", ports = "80", 
                     sources = list(addresses = "18.0.0.0/8")))
outbound <- list(list(protocol = "tcp", ports = "80", 
                      destinations = list(addresses = "0.0.0.0/0")))
res <- firewall_create("myfirewall", inbound, outbound)
res

Error received:

Error: missing name

Also, the message error is weird as the name is provided in the first argument.

this seems to be a change in the API, let me ask Digital Ocean

stadbern commented 5 days ago

Hello,

same problem here.

if it's of any help, this function works using httr2:

library(httr2)

api_token = "kshjqlf"

create_firewall = function(droplet_ids, firewall_name, authorized_IPs){

Define the request body

body <- list( name = firewall_name, droplet_ids = droplet_ids, inbound_rules = list(

Allowing specific IPs to communicate over SSH

  list(
    protocol = "tcp",
    ports = "22",  
    sources = list(
      addresses = authorized_IPs # Add 
    )
  ),
  # Allowing specific IPs to communicate over HTTP
  list(
    protocol = "tcp",
    ports = "80",
    sources = list(
      addresses = authorized_IPs
    )
  ),
  # Allow ICMP for ping
  list(
    protocol = "icmp",  
    sources = list(
      #addresses = list("0.0.0.0/0")  # Allow from all sources or specify your source IP
      addresses = authorized_IPs
    )
  )
)

)

URL = "https://api.digitalocean.com/v2/firewalls" resp = request(URL) %>% req_headers( "Content-Type" = "application/json", "Authorization" = paste("Bearer", api_token) ) %>% req_body_json(body) |> req_perform() resp$status_code }