这是indexloc提供的服务,不要输入任何密码
Skip to content

Add Firewall Config resource #195

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

Merged
merged 19 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions client/firewall_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package client

import (
"context"
"fmt"
)

type FirewallConfig struct {
ProjectID string `json:"-"`
TeamID string `json:"-"`
Enabled bool `json:"firewallEnabled"`
ManagedRulesets map[string]ManagedRule `json:"managedRules,omitempty"`

Rules []FirewallRule `json:"rules,omitempty"`
IPRules []IPRule `json:"ips,omitempty"`
CRS map[string]CoreRuleSet `json:"crs,omitempty"`
}
type ManagedRule struct {
Active bool `json:"active"`
}

type FirewallRule struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Active bool `json:"active"`
ConditionGroup []ConditionGroup `json:"conditionGroup"`
Action Action `json:"action"`
}

type ConditionGroup struct {
Conditions []Condition `json:"conditions"`
}

type Condition struct {
Type string `json:"type"`
Op string `json:"op"`
Neg bool `json:"neg"`
Key string `json:"key"`
Value string `json:"value"`
}

type Action struct {
Mitigate Mitigate `json:"mitigate"`
}
type Mitigate struct {
Action string `json:"action"`
RateLimit *RateLimit `json:"rateLimit,omitempty"`
Redirect *Redirect `json:"redirect,omitempty"`
ActionDuration string `json:"actionDuration,omitempty"`
}

type RateLimit struct {
Algo string `json:"algo" tfsdk:"algo"`
Window int64 `json:"window" tfsdk:"window"`
Limit int64 `json:"limit" tfsdk:"limit"`
Keys []string `json:"keys" tfsdk:"keys"`
Action string `json:"action" tfsdk:"action"`
}

type Redirect struct {
Location string `json:"location" tfsdk:"location"`
Permanent bool `json:"permanent" tfsdk:"permanent"`
}

type IPRule struct {
ID string `json:"id,omitempty"`
Hostname string `json:"hostname"`
IP string `json:"ip"`
Notes string `json:"notes,omitempty"`
Action string `json:"action"`
}

type CoreRuleSet struct {
Active bool `json:"active"`
Action string `json:"action"`
}

func (c *Client) GetFirewallConfig(ctx context.Context, projectId string, teamId string) (FirewallConfig, error) {
teamId = c.teamID(teamId)
url := fmt.Sprintf(
"%s/v1/security/firewall/config/active?projectId=%s&teamId=%s",
c.baseURL,
projectId,
teamId,
)
var res = FirewallConfig{}
err := c.doRequest(clientRequest{
ctx: ctx,
method: "GET",
url: url,
}, &res)
res.TeamID = teamId
return res, err
}

func (c *Client) PutFirewallConfig(ctx context.Context, cfg FirewallConfig) (FirewallConfig, error) {
teamId := c.teamID(cfg.TeamID)
url := fmt.Sprintf(
"%s/v1/security/firewall/config?projectId=%s&teamId=%s",
c.baseURL,
cfg.ProjectID,
teamId,
)

var res struct {
Active FirewallConfig `json:"active"`
Error map[string]string `json:"error,omitempty"`
}
payload := mustMarshal(cfg)

err := c.doRequest(clientRequest{
ctx: ctx,
method: "PUT",
url: url,
body: string(payload),
}, &res)
res.Active.TeamID = teamId
return res.Active, err
}
2 changes: 1 addition & 1 deletion docs/resources/attack_challenge_mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ resource "vercel_attack_challenge_mode" "example" {
### Required

- `enabled` (Boolean) Whether Attack Challenge Mode is enabled or not.
- `project_id` (String) The ID of the Project to adjust the CPU for.
- `project_id` (String) The ID of the Project to toggle Attack Challenge Mode on.

### Optional

Expand Down
Loading
Loading