Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analogsea::firewall_create doesnt work anymore #223

Open
Sade154 opened this issue Nov 6, 2024 · 2 comments
Open

analogsea::firewall_create doesnt work anymore #223

Sade154 opened this issue Nov 6, 2024 · 2 comments
Labels

Comments

@Sade154
Copy link

Sade154 commented Nov 6, 2024

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

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
Copy link
Owner

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

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
Copy link

stadbern commented Nov 8, 2024

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants