Skip to content

Commit

Permalink
feat: add traffic rules to bundled functions config (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo authored Apr 4, 2024
1 parent f5596d7 commit c034c55
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
23 changes: 21 additions & 2 deletions go/porcelain/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,15 +822,34 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep
}
}

hasConfig := function.DisplayName != "" || function.Generator != "" || len(routes) > 0 || len(function.BuildData) > 0 || function.Priority != 0
hasConfig := function.DisplayName != "" || function.Generator != "" || len(routes) > 0 || len(function.BuildData) > 0 || function.Priority != 0 || function.TrafficRules != nil
if hasConfig {
functionsConfig[file.Name] = models.FunctionConfig{
cfg := models.FunctionConfig{
DisplayName: function.DisplayName,
Generator: function.Generator,
Routes: routes,
BuildData: function.BuildData,
Priority: int64(function.Priority),
}

if function.TrafficRules != nil {
cfg.TrafficRules = &models.TrafficRulesConfig{
Action: &models.TrafficRulesConfigAction{
Type: function.TrafficRules.Action.Type,
Config: &models.TrafficRulesConfigActionConfig{
Aggregate: function.TrafficRules.Action.Config.Aggregate,
RateLimitConfig: &models.TrafficRulesRateLimitConfig{
Algorithm: function.TrafficRules.Action.Config.RateLimitConfig.Algorithm,
WindowSize: int64(function.TrafficRules.Action.Config.RateLimitConfig.WindowSize),
WindowLimit: int64(function.TrafficRules.Action.Config.RateLimitConfig.WindowLimit),
},
To: function.TrafficRules.Action.Config.To,
},
},
}
}

functionsConfig[file.Name] = cfg
}

functions.Add(file.Name, file)
Expand Down
18 changes: 18 additions & 0 deletions go/porcelain/functions_manifest.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package porcelain

import "github.com/netlify/open-api/v2/go/models"

// https://github.com/netlify/zip-it-and-ship-it/blob/main/src/manifest.ts
type functionsManifest struct {
Functions []functionsManifestEntry `json:"functions"`
Expand All @@ -19,6 +21,7 @@ type functionsManifestEntry struct {
InvocationMode string `json:"invocationMode"`
Routes []functionRoute `json:"routes"`
Priority int `json:"priority"`
TrafficRules *functionTrafficRules `json:"trafficRules"`
}

type functionRoute struct {
Expand All @@ -28,3 +31,18 @@ type functionRoute struct {
Methods []string `json:"methods"`
PreferStatic bool `json:"prefer_static"`
}

type functionTrafficRules struct {
Action struct {
Type string `json:"type"`
Config struct {
RateLimitConfig struct {
Algorithm string `json:"algorithm"`
WindowSize int `json:"windowSize"`
WindowLimit int `json:"windowLimit"`
}
Aggregate *models.TrafficRulesAggregateConfig
To string `json:"to"`
}
}
}

0 comments on commit c034c55

Please sign in to comment.