{"modulePath":"github.com/hostinger/api-cli","version":"v1.2.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package firewall\n\n## Variables\n\n```go\nvar ActivateCmd = \u0026cobra.Command{\n\tUse:   \"activate \u003cfirewall-id\u003e \u003cvirtual-machine-id\u003e\",\n\tShort: \"Activate firewall\",\n\tLong:  \"Activate a firewall for a specified virtual machine.\\n\\nOnly one firewall can be active for a virtual machine at a time.\\n\\nUse this endpoint to apply firewall rules to VPS instances.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(2)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSActivateFirewallV1WithResponse(context.TODO(), utils.StringToInt(args[0]), utils.StringToInt(args[1]))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar CreateCmd = \u0026cobra.Command{\n\tUse:   \"create\",\n\tShort: \"Create new firewall\",\n\tLong:  \"Create a new firewall.\\n\\nUse this endpoint to set up new firewall configurations for VPS security.\",\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tpayload, err := json.Marshal(createBody(cmd))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\t\tr, err := api.Request().VPSCreateNewFirewallV1WithBodyWithResponse(context.TODO(), \"application/json\", bytes.NewReader(payload))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar CreateRuleCmd = \u0026cobra.Command{\n\tUse:   \"create-rule \u003cfirewall-id\u003e\",\n\tShort: \"Create firewall rule\",\n\tLong:  \"Create new firewall rule for a specified firewall.\\n\\nBy default, the firewall drops all incoming traffic,\\nwhich means you must add accept rules for all ports you want to use.\\n\\nAny virtual machine that has this firewall activated will lose sync with the firewall\\nand will have to be synced again manually.\\n\\nUse this endpoint to add new security rules to firewalls.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tutils.EnumCheck(cmd, \"protocol\", []string{\"TCP\", \"UDP\", \"ICMP\", \"GRE\", \"any\", \"ESP\", \"AH\", \"ICMPv6\", \"SSH\", \"HTTP\", \"HTTPS\", \"MySQL\", \"PostgreSQL\"})\n\t\tutils.EnumCheck(cmd, \"source\", []string{\"any\", \"custom\"})\n\t\tpayload, err := json.Marshal(createRuleBody(cmd))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\t\tr, err := api.Request().VPSCreateFirewallRuleV1WithBodyWithResponse(context.TODO(), utils.StringToInt(args[0]), \"application/json\", bytes.NewReader(payload))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar DeactivateCmd = \u0026cobra.Command{\n\tUse:   \"deactivate \u003cfirewall-id\u003e \u003cvirtual-machine-id\u003e\",\n\tShort: \"Deactivate firewall\",\n\tLong:  \"Deactivate a firewall for a specified virtual machine.\\n\\nUse this endpoint to remove firewall protection from VPS instances.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(2)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSDeactivateFirewallV1WithResponse(context.TODO(), utils.StringToInt(args[0]), utils.StringToInt(args[1]))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar DeleteCmd = \u0026cobra.Command{\n\tUse:   \"delete \u003cfirewall-id\u003e\",\n\tShort: \"Delete firewall\",\n\tLong:  \"Delete a specified firewall.\\n\\nAny virtual machine that has this firewall activated will automatically have it deactivated.\\n\\nUse this endpoint to remove unused firewall configurations.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSDeleteFirewallV1WithResponse(context.TODO(), utils.StringToInt(args[0]))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar DeleteRuleCmd = \u0026cobra.Command{\n\tUse:   \"delete-rule \u003cfirewall-id\u003e \u003crule-id\u003e\",\n\tShort: \"Delete firewall rule\",\n\tLong:  \"Delete a specific firewall rule from a specified firewall.\\n\\nAny virtual machine that has this firewall activated will lose sync with the firewall\\nand will have to be synced again manually.\\n\\nUse this endpoint to remove specific firewall rules.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(2)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSDeleteFirewallRuleV1WithResponse(context.TODO(), utils.StringToInt(args[0]), utils.StringToInt(args[1]))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar GetCmd = \u0026cobra.Command{\n\tUse:   \"get \u003cfirewall-id\u003e\",\n\tShort: \"Get firewall details\",\n\tLong:  \"Retrieve firewall by its ID and rules associated with it.\\n\\nUse this endpoint to view specific firewall configuration and rules.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSGetFirewallDetailsV1WithResponse(context.TODO(), utils.StringToInt(args[0]))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar GroupCmd = \u0026cobra.Command{\n\tUse:   \"firewall\",\n\tShort: \"Firewall commands\",\n}\n```\n\n```go\nvar ListCmd = \u0026cobra.Command{\n\tUse:   \"list\",\n\tShort: \"Get firewall list\",\n\tLong:  \"Retrieve all available firewalls.\\n\\nUse this endpoint to view existing firewall configurations.\",\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSGetFirewallListV1WithResponse(context.TODO(), listParams(cmd))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar SyncCmd = \u0026cobra.Command{\n\tUse:   \"sync \u003cfirewall-id\u003e \u003cvirtual-machine-id\u003e\",\n\tShort: \"Sync firewall\",\n\tLong:  \"Sync a firewall for a specified virtual machine.\\n\\nFirewall can lose sync with virtual machine if the firewall has new rules added, removed or updated.\\n\\nUse this endpoint to apply updated firewall rules to VPS instances.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(2)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSSyncFirewallV1WithResponse(context.TODO(), utils.StringToInt(args[0]), utils.StringToInt(args[1]))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar UpdateRuleCmd = \u0026cobra.Command{\n\tUse:   \"update-rule \u003cfirewall-id\u003e \u003crule-id\u003e\",\n\tShort: \"Update firewall rule\",\n\tLong:  \"Update a specific firewall rule from a specified firewall.\\n\\nAny virtual machine that has this firewall activated will lose sync with the firewall\\nand will have to be synced again manually.\\n\\nUse this endpoint to modify existing firewall rules.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(2)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tutils.EnumCheck(cmd, \"protocol\", []string{\"TCP\", \"UDP\", \"ICMP\", \"GRE\", \"any\", \"ESP\", \"AH\", \"ICMPv6\", \"SSH\", \"HTTP\", \"HTTPS\", \"MySQL\", \"PostgreSQL\"})\n\t\tutils.EnumCheck(cmd, \"source\", []string{\"any\", \"custom\"})\n\t\tpayload, err := json.Marshal(updateRuleBody(cmd))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\t\tr, err := api.Request().VPSUpdateFirewallRuleV1WithBodyWithResponse(context.TODO(), utils.StringToInt(args[0]), utils.StringToInt(args[1]), \"application/json\", bytes.NewReader(payload))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n","path":"github.com/hostinger/api-cli/cmd/vps/firewall","name":"firewall","synopsis":"","isRedistributable":true}
