Python (SDK)
import latitudesh_python_sdk
from latitudesh_python_sdk import Latitudesh
import os
with Latitudesh(
bearer=os.getenv("LATITUDESH_BEARER", ""),
) as latitudesh:
res = latitudesh.firewalls.create(data={
"type": latitudesh_python_sdk.CreateFirewallFirewallsType.FIREWALLS,
"attributes": {
"name": "my-firewall",
"project": "heavy-duty-copper-watch",
"rules": [
{
"from_": "192.168.42.73",
"to": "192.168.43.51",
"protocol": latitudesh_python_sdk.CreateFirewallProtocol.TCP,
"port": "80",
"description": "Allow HTTP traffic",
},
{
"from_": "192.168.1.16",
"to": "192.168.1.30",
"protocol": latitudesh_python_sdk.CreateFirewallProtocol.TCP,
"port": "80",
},
{
"from_": "192.168.1.10",
"to": "192.168.1.20",
"protocol": latitudesh_python_sdk.CreateFirewallProtocol.UDP,
"port": "3000-4000",
"description": "Application ports",
},
],
},
})
# Handle response
print(res)package main
import(
"context"
"os"
latitudeshgosdk "github.com/latitudesh/latitudesh-go-sdk"
"github.com/latitudesh/latitudesh-go-sdk/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := latitudeshgosdk.New(
latitudeshgosdk.WithSecurity(os.Getenv("LATITUDESH_BEARER")),
)
res, err := s.Firewalls.Create(ctx, operations.CreateFirewallFirewallsRequestBody{
Data: operations.CreateFirewallData{
Type: operations.CreateFirewallTypeFirewalls,
Attributes: &operations.CreateFirewallAttributes{
Name: "my-firewall",
Project: "heavy-duty-copper-watch",
Rules: []operations.CreateFirewallRules{
operations.CreateFirewallRules{
From: latitudeshgosdk.Pointer("192.168.42.73"),
To: latitudeshgosdk.Pointer("192.168.43.51"),
Protocol: operations.CreateFirewallProtocolTCP.ToPointer(),
Port: latitudeshgosdk.Pointer("80"),
Description: latitudeshgosdk.Pointer("Allow HTTP traffic"),
},
operations.CreateFirewallRules{
From: latitudeshgosdk.Pointer("192.168.1.16"),
To: latitudeshgosdk.Pointer("192.168.1.30"),
Protocol: operations.CreateFirewallProtocolTCP.ToPointer(),
Port: latitudeshgosdk.Pointer("80"),
},
operations.CreateFirewallRules{
From: latitudeshgosdk.Pointer("192.168.1.10"),
To: latitudeshgosdk.Pointer("192.168.1.20"),
Protocol: operations.CreateFirewallProtocolUDP.ToPointer(),
Port: latitudeshgosdk.Pointer("3000-4000"),
Description: latitudeshgosdk.Pointer("Application ports"),
},
},
},
},
})
if err != nil {
log.Fatal(err)
}
if res.Firewall != nil {
// handle response
}
}import { Latitudesh } from "latitudesh-typescript-sdk";
const latitudesh = new Latitudesh({
bearer: process.env["LATITUDESH_BEARER"] ?? "",
});
async function run() {
const result = await latitudesh.firewalls.create({
data: {
type: "firewalls",
attributes: {
name: "my-firewall",
project: "heavy-duty-copper-watch",
rules: [
{
from: "192.168.42.73",
to: "192.168.43.51",
protocol: "TCP",
port: "80",
description: "Allow HTTP traffic",
},
{
from: "192.168.1.16",
to: "192.168.1.30",
protocol: "TCP",
port: "80",
},
{
from: "192.168.1.10",
to: "192.168.1.20",
protocol: "UDP",
port: "3000-4000",
description: "Application ports",
},
],
},
},
});
console.log(result);
}
run();curl --request POST \
--url https://api.latitude.sh/firewalls \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"data": {
"type": "firewalls",
"attributes": {
"name": "my-firewall",
"project": "heavy-duty-copper-watch",
"rules": [
{
"from": "192.168.42.73",
"to": "192.168.43.51",
"port": 80,
"protocol": "TCP",
"description": "Allow HTTP traffic"
},
{
"from": "192.168.1.16",
"to": "192.168.1.30",
"port": "80",
"protocol": "TCP"
},
{
"from": "192.168.1.10",
"to": "192.168.1.20",
"port": "3000-4000",
"protocol": "UDP",
"description": "Application ports"
}
]
}
}
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
data: {
type: 'firewalls',
attributes: {
name: 'my-firewall',
project: 'heavy-duty-copper-watch',
rules: [
{
from: '192.168.42.73',
to: '192.168.43.51',
port: 80,
protocol: 'TCP',
description: 'Allow HTTP traffic'
},
{from: '192.168.1.16', to: '192.168.1.30', port: '80', protocol: 'TCP'},
{
from: '192.168.1.10',
to: '192.168.1.20',
port: '3000-4000',
protocol: 'UDP',
description: 'Application ports'
}
]
}
}
})
};
fetch('https://api.latitude.sh/firewalls', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.latitude.sh/firewalls",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'data' => [
'type' => 'firewalls',
'attributes' => [
'name' => 'my-firewall',
'project' => 'heavy-duty-copper-watch',
'rules' => [
[
'from' => '192.168.42.73',
'to' => '192.168.43.51',
'port' => 80,
'protocol' => 'TCP',
'description' => 'Allow HTTP traffic'
],
[
'from' => '192.168.1.16',
'to' => '192.168.1.30',
'port' => '80',
'protocol' => 'TCP'
],
[
'from' => '192.168.1.10',
'to' => '192.168.1.20',
'port' => '3000-4000',
'protocol' => 'UDP',
'description' => 'Application ports'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.latitude.sh/firewalls")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"data\": {\n \"type\": \"firewalls\",\n \"attributes\": {\n \"name\": \"my-firewall\",\n \"project\": \"heavy-duty-copper-watch\",\n \"rules\": [\n {\n \"from\": \"192.168.42.73\",\n \"to\": \"192.168.43.51\",\n \"port\": 80,\n \"protocol\": \"TCP\",\n \"description\": \"Allow HTTP traffic\"\n },\n {\n \"from\": \"192.168.1.16\",\n \"to\": \"192.168.1.30\",\n \"port\": \"80\",\n \"protocol\": \"TCP\"\n },\n {\n \"from\": \"192.168.1.10\",\n \"to\": \"192.168.1.20\",\n \"port\": \"3000-4000\",\n \"protocol\": \"UDP\",\n \"description\": \"Application ports\"\n }\n ]\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.latitude.sh/firewalls")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"data\": {\n \"type\": \"firewalls\",\n \"attributes\": {\n \"name\": \"my-firewall\",\n \"project\": \"heavy-duty-copper-watch\",\n \"rules\": [\n {\n \"from\": \"192.168.42.73\",\n \"to\": \"192.168.43.51\",\n \"port\": 80,\n \"protocol\": \"TCP\",\n \"description\": \"Allow HTTP traffic\"\n },\n {\n \"from\": \"192.168.1.16\",\n \"to\": \"192.168.1.30\",\n \"port\": \"80\",\n \"protocol\": \"TCP\"\n },\n {\n \"from\": \"192.168.1.10\",\n \"to\": \"192.168.1.20\",\n \"port\": \"3000-4000\",\n \"protocol\": \"UDP\",\n \"description\": \"Application ports\"\n }\n ]\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "fw_w5AEmq7XDBkWX",
"type": "firewalls",
"attributes": {
"name": "my-firewall",
"project": {
"id": "proj_RLYV8DZ2D5QoE",
"name": "Heavy Duty Copper Watch",
"slug": "heavy-duty-copper-watch"
},
"rules": [
{
"from": "ANY",
"to": "ANY",
"port": "22",
"protocol": "TCP",
"default": true
},
{
"from": "192.168.42.73",
"to": "192.168.43.51",
"port": "80",
"protocol": "TCP",
"default": false
},
{
"from": "192.168.1.16",
"to": "192.168.1.30",
"port": "80",
"protocol": "TCP",
"default": false
},
{
"from": "192.168.1.10",
"to": "192.168.1.20",
"port": "3000-4000",
"protocol": "UDP",
"default": false
}
]
}
}
}Firewalls
Create firewall
Create a firewall
POST
/
firewalls
Python (SDK)
import latitudesh_python_sdk
from latitudesh_python_sdk import Latitudesh
import os
with Latitudesh(
bearer=os.getenv("LATITUDESH_BEARER", ""),
) as latitudesh:
res = latitudesh.firewalls.create(data={
"type": latitudesh_python_sdk.CreateFirewallFirewallsType.FIREWALLS,
"attributes": {
"name": "my-firewall",
"project": "heavy-duty-copper-watch",
"rules": [
{
"from_": "192.168.42.73",
"to": "192.168.43.51",
"protocol": latitudesh_python_sdk.CreateFirewallProtocol.TCP,
"port": "80",
"description": "Allow HTTP traffic",
},
{
"from_": "192.168.1.16",
"to": "192.168.1.30",
"protocol": latitudesh_python_sdk.CreateFirewallProtocol.TCP,
"port": "80",
},
{
"from_": "192.168.1.10",
"to": "192.168.1.20",
"protocol": latitudesh_python_sdk.CreateFirewallProtocol.UDP,
"port": "3000-4000",
"description": "Application ports",
},
],
},
})
# Handle response
print(res)package main
import(
"context"
"os"
latitudeshgosdk "github.com/latitudesh/latitudesh-go-sdk"
"github.com/latitudesh/latitudesh-go-sdk/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := latitudeshgosdk.New(
latitudeshgosdk.WithSecurity(os.Getenv("LATITUDESH_BEARER")),
)
res, err := s.Firewalls.Create(ctx, operations.CreateFirewallFirewallsRequestBody{
Data: operations.CreateFirewallData{
Type: operations.CreateFirewallTypeFirewalls,
Attributes: &operations.CreateFirewallAttributes{
Name: "my-firewall",
Project: "heavy-duty-copper-watch",
Rules: []operations.CreateFirewallRules{
operations.CreateFirewallRules{
From: latitudeshgosdk.Pointer("192.168.42.73"),
To: latitudeshgosdk.Pointer("192.168.43.51"),
Protocol: operations.CreateFirewallProtocolTCP.ToPointer(),
Port: latitudeshgosdk.Pointer("80"),
Description: latitudeshgosdk.Pointer("Allow HTTP traffic"),
},
operations.CreateFirewallRules{
From: latitudeshgosdk.Pointer("192.168.1.16"),
To: latitudeshgosdk.Pointer("192.168.1.30"),
Protocol: operations.CreateFirewallProtocolTCP.ToPointer(),
Port: latitudeshgosdk.Pointer("80"),
},
operations.CreateFirewallRules{
From: latitudeshgosdk.Pointer("192.168.1.10"),
To: latitudeshgosdk.Pointer("192.168.1.20"),
Protocol: operations.CreateFirewallProtocolUDP.ToPointer(),
Port: latitudeshgosdk.Pointer("3000-4000"),
Description: latitudeshgosdk.Pointer("Application ports"),
},
},
},
},
})
if err != nil {
log.Fatal(err)
}
if res.Firewall != nil {
// handle response
}
}import { Latitudesh } from "latitudesh-typescript-sdk";
const latitudesh = new Latitudesh({
bearer: process.env["LATITUDESH_BEARER"] ?? "",
});
async function run() {
const result = await latitudesh.firewalls.create({
data: {
type: "firewalls",
attributes: {
name: "my-firewall",
project: "heavy-duty-copper-watch",
rules: [
{
from: "192.168.42.73",
to: "192.168.43.51",
protocol: "TCP",
port: "80",
description: "Allow HTTP traffic",
},
{
from: "192.168.1.16",
to: "192.168.1.30",
protocol: "TCP",
port: "80",
},
{
from: "192.168.1.10",
to: "192.168.1.20",
protocol: "UDP",
port: "3000-4000",
description: "Application ports",
},
],
},
},
});
console.log(result);
}
run();curl --request POST \
--url https://api.latitude.sh/firewalls \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"data": {
"type": "firewalls",
"attributes": {
"name": "my-firewall",
"project": "heavy-duty-copper-watch",
"rules": [
{
"from": "192.168.42.73",
"to": "192.168.43.51",
"port": 80,
"protocol": "TCP",
"description": "Allow HTTP traffic"
},
{
"from": "192.168.1.16",
"to": "192.168.1.30",
"port": "80",
"protocol": "TCP"
},
{
"from": "192.168.1.10",
"to": "192.168.1.20",
"port": "3000-4000",
"protocol": "UDP",
"description": "Application ports"
}
]
}
}
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
data: {
type: 'firewalls',
attributes: {
name: 'my-firewall',
project: 'heavy-duty-copper-watch',
rules: [
{
from: '192.168.42.73',
to: '192.168.43.51',
port: 80,
protocol: 'TCP',
description: 'Allow HTTP traffic'
},
{from: '192.168.1.16', to: '192.168.1.30', port: '80', protocol: 'TCP'},
{
from: '192.168.1.10',
to: '192.168.1.20',
port: '3000-4000',
protocol: 'UDP',
description: 'Application ports'
}
]
}
}
})
};
fetch('https://api.latitude.sh/firewalls', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.latitude.sh/firewalls",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'data' => [
'type' => 'firewalls',
'attributes' => [
'name' => 'my-firewall',
'project' => 'heavy-duty-copper-watch',
'rules' => [
[
'from' => '192.168.42.73',
'to' => '192.168.43.51',
'port' => 80,
'protocol' => 'TCP',
'description' => 'Allow HTTP traffic'
],
[
'from' => '192.168.1.16',
'to' => '192.168.1.30',
'port' => '80',
'protocol' => 'TCP'
],
[
'from' => '192.168.1.10',
'to' => '192.168.1.20',
'port' => '3000-4000',
'protocol' => 'UDP',
'description' => 'Application ports'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.latitude.sh/firewalls")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"data\": {\n \"type\": \"firewalls\",\n \"attributes\": {\n \"name\": \"my-firewall\",\n \"project\": \"heavy-duty-copper-watch\",\n \"rules\": [\n {\n \"from\": \"192.168.42.73\",\n \"to\": \"192.168.43.51\",\n \"port\": 80,\n \"protocol\": \"TCP\",\n \"description\": \"Allow HTTP traffic\"\n },\n {\n \"from\": \"192.168.1.16\",\n \"to\": \"192.168.1.30\",\n \"port\": \"80\",\n \"protocol\": \"TCP\"\n },\n {\n \"from\": \"192.168.1.10\",\n \"to\": \"192.168.1.20\",\n \"port\": \"3000-4000\",\n \"protocol\": \"UDP\",\n \"description\": \"Application ports\"\n }\n ]\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.latitude.sh/firewalls")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"data\": {\n \"type\": \"firewalls\",\n \"attributes\": {\n \"name\": \"my-firewall\",\n \"project\": \"heavy-duty-copper-watch\",\n \"rules\": [\n {\n \"from\": \"192.168.42.73\",\n \"to\": \"192.168.43.51\",\n \"port\": 80,\n \"protocol\": \"TCP\",\n \"description\": \"Allow HTTP traffic\"\n },\n {\n \"from\": \"192.168.1.16\",\n \"to\": \"192.168.1.30\",\n \"port\": \"80\",\n \"protocol\": \"TCP\"\n },\n {\n \"from\": \"192.168.1.10\",\n \"to\": \"192.168.1.20\",\n \"port\": \"3000-4000\",\n \"protocol\": \"UDP\",\n \"description\": \"Application ports\"\n }\n ]\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "fw_w5AEmq7XDBkWX",
"type": "firewalls",
"attributes": {
"name": "my-firewall",
"project": {
"id": "proj_RLYV8DZ2D5QoE",
"name": "Heavy Duty Copper Watch",
"slug": "heavy-duty-copper-watch"
},
"rules": [
{
"from": "ANY",
"to": "ANY",
"port": "22",
"protocol": "TCP",
"default": true
},
{
"from": "192.168.42.73",
"to": "192.168.43.51",
"port": "80",
"protocol": "TCP",
"default": false
},
{
"from": "192.168.1.16",
"to": "192.168.1.30",
"port": "80",
"protocol": "TCP",
"default": false
},
{
"from": "192.168.1.10",
"to": "192.168.1.20",
"port": "3000-4000",
"protocol": "UDP",
"default": false
}
]
}
}
}Was this page helpful?
⌘I