refactor: update AS entry handling in API and database to support ASN-only entries. Remove prefix field from AS entry structure and adjust related functions and tests. Enhance OpenAPI specifications and documentation to reflect changes in AS entry representation.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"evobgp/internal/birdfmt"
|
||||
@@ -16,6 +17,11 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// MaterializedASPrefixKey returns the revision snapshot key for an AS-only entry (not a CIDR).
|
||||
func MaterializedASPrefixKey(asn int64) string {
|
||||
return fmt.Sprintf("as:%d", asn)
|
||||
}
|
||||
|
||||
// RefreshModule runs ingest (where applicable) and creates a new rendered revision for the module.
|
||||
func RefreshModule(ctx context.Context, st store.Backend, hc *http.Client, tenantID, moduleID string) (revisionID string, err error) {
|
||||
if hc == nil {
|
||||
@@ -50,7 +56,7 @@ func RefreshModule(ctx context.Context, st store.Backend, hc *http.Client, tenan
|
||||
return "", err
|
||||
}
|
||||
for _, e := range list {
|
||||
if e.Prefix == nil || strings.TrimSpace(*e.Prefix) == "" {
|
||||
if !store.ValidASN(e.ASN) {
|
||||
continue
|
||||
}
|
||||
comm := e.CommunityID
|
||||
@@ -58,7 +64,7 @@ func RefreshModule(ctx context.Context, st store.Backend, hc *http.Client, tenan
|
||||
c := *mod.DefaultCommunityID
|
||||
comm = &c
|
||||
}
|
||||
rows = append(rows, store.PrefixRow{Prefix: strings.TrimSpace(*e.Prefix), CommunityID: comm, Source: "as_entry"})
|
||||
rows = append(rows, store.PrefixRow{Prefix: MaterializedASPrefixKey(e.ASN), CommunityID: comm, Source: "as_entry"})
|
||||
}
|
||||
case "CDN_CIDRS":
|
||||
sources, err := st.ListCDNSources(tenantID, moduleID)
|
||||
@@ -175,8 +181,18 @@ func hashMaterialization(moduleID string, rows []store.PrefixRow) string {
|
||||
|
||||
func buildPreviewFragments(revisionID string, rows []store.PrefixRow) (map[string]string, error) {
|
||||
var v4, v6 []netip.Prefix
|
||||
var pathASNs []int64
|
||||
for _, pr := range rows {
|
||||
pfx, err := netip.ParsePrefix(strings.TrimSpace(pr.Prefix))
|
||||
p := strings.TrimSpace(pr.Prefix)
|
||||
if strings.HasPrefix(p, "as:") {
|
||||
n, err := strconv.ParseInt(strings.TrimPrefix(p, "as:"), 10, 64)
|
||||
if err != nil || !store.ValidASN(n) {
|
||||
continue
|
||||
}
|
||||
pathASNs = append(pathASNs, n)
|
||||
continue
|
||||
}
|
||||
pfx, err := netip.ParsePrefix(p)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@@ -186,11 +202,11 @@ func buildPreviewFragments(revisionID string, rows []store.PrefixRow) (map[strin
|
||||
v6 = append(v6, pfx.Masked())
|
||||
}
|
||||
}
|
||||
f4, err := birdfmt.RenderExportFilterIPv4("evobgp_export_v4", v4)
|
||||
f4, err := birdfmt.RenderExportFilterIPv4("evobgp_export_v4", v4, pathASNs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f6, err := birdfmt.RenderExportFilterIPv6("evobgp_export_v6", v6)
|
||||
f6, err := birdfmt.RenderExportFilterIPv6("evobgp_export_v6", v6, pathASNs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user