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: "awesome-granite-chair",
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"),
},
operations.CreateFirewallRules{
From: latitudeshgosdk.Pointer("192.168.1.0/24"),
To: latitudeshgosdk.Pointer("ANY"),
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"),
},
},
},
},
})
if err != nil {
log.Fatal(err)
}
if res.Firewall != nil {
// handle response
}
}{
"data": {
"id": "fw_VLMmAD8EOwop2",
"type": "firewalls",
"attributes": {
"name": "my-firewall",
"project": {
"id": "proj_6A05EdQ1dvKYQ",
"name": "Awesome Granite Chair",
"slug": "awesome-granite-chair"
},
"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.0/24",
"to": "ANY",
"port": "80",
"protocol": "TCP",
"default": false
},
{
"from": "192.168.1.10",
"to": "192.168.1.20",
"port": "3000-4000",
"protocol": "UDP",
"default": false
}
]
}
}
}Create a firewall
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: "awesome-granite-chair",
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"),
},
operations.CreateFirewallRules{
From: latitudeshgosdk.Pointer("192.168.1.0/24"),
To: latitudeshgosdk.Pointer("ANY"),
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"),
},
},
},
},
})
if err != nil {
log.Fatal(err)
}
if res.Firewall != nil {
// handle response
}
}{
"data": {
"id": "fw_VLMmAD8EOwop2",
"type": "firewalls",
"attributes": {
"name": "my-firewall",
"project": {
"id": "proj_6A05EdQ1dvKYQ",
"name": "Awesome Granite Chair",
"slug": "awesome-granite-chair"
},
"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.0/24",
"to": "ANY",
"port": "80",
"protocol": "TCP",
"default": false
},
{
"from": "192.168.1.10",
"to": "192.168.1.20",
"port": "3000-4000",
"protocol": "UDP",
"default": false
}
]
}
}
}Show child attributes
Was this page helpful?