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:
@@ -109,19 +109,22 @@ type CDNSourcePatch struct {
|
||||
}
|
||||
|
||||
type ASEntry struct {
|
||||
ID string
|
||||
ModuleID string
|
||||
ASN *int64
|
||||
Prefix *string
|
||||
CommunityID *string
|
||||
ID string
|
||||
ModuleID string
|
||||
ASN int64
|
||||
CommunityID *string
|
||||
}
|
||||
|
||||
type ASEntryPatch struct {
|
||||
ASN *int64
|
||||
Prefix *string
|
||||
CommunityID *string
|
||||
}
|
||||
|
||||
// ValidASN reports whether n is a usable BGP ASN (1..4294967295).
|
||||
func ValidASN(n int64) bool {
|
||||
return n >= 1 && n <= 4294967295
|
||||
}
|
||||
|
||||
type DomainEntry struct {
|
||||
ID string
|
||||
ModuleID string
|
||||
|
||||
@@ -217,7 +217,7 @@ func (m *Memory) ListASEntries(tenantID, moduleID string) ([]*ASEntry, error) {
|
||||
}
|
||||
|
||||
func (m *Memory) CreateASEntry(tenantID, moduleID string, in *ASEntry) (*ASEntry, error) {
|
||||
if in == nil || (in.ASN == nil && (in.Prefix == nil || strings.TrimSpace(*in.Prefix) == "")) {
|
||||
if in == nil || !ValidASN(in.ASN) {
|
||||
return nil, ErrInvalidInput
|
||||
}
|
||||
m.mu.Lock()
|
||||
@@ -230,7 +230,7 @@ func (m *Memory) CreateASEntry(tenantID, moduleID string, in *ASEntry) (*ASEntry
|
||||
return nil, ErrInvalidInput
|
||||
}
|
||||
id := uuid.NewString()
|
||||
e := &ASEntry{ID: id, ModuleID: moduleID, ASN: in.ASN, Prefix: in.Prefix, CommunityID: in.CommunityID}
|
||||
e := &ASEntry{ID: id, ModuleID: moduleID, ASN: in.ASN, CommunityID: in.CommunityID}
|
||||
m.asEntries[id] = e
|
||||
return e, nil
|
||||
}
|
||||
@@ -249,15 +249,7 @@ func (m *Memory) UpdateASEntry(tenantID, moduleID, entryID string, patch *ASEntr
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
if patch.ASN != nil {
|
||||
e.ASN = patch.ASN
|
||||
}
|
||||
if patch.Prefix != nil {
|
||||
p := strings.TrimSpace(*patch.Prefix)
|
||||
if p == "" {
|
||||
e.Prefix = nil
|
||||
} else {
|
||||
e.Prefix = &p
|
||||
}
|
||||
e.ASN = *patch.ASN
|
||||
}
|
||||
if patch.CommunityID != nil {
|
||||
v := strings.TrimSpace(*patch.CommunityID)
|
||||
@@ -267,6 +259,9 @@ func (m *Memory) UpdateASEntry(tenantID, moduleID, entryID string, patch *ASEntr
|
||||
e.CommunityID = &v
|
||||
}
|
||||
}
|
||||
if !ValidASN(e.ASN) {
|
||||
return nil, ErrInvalidInput
|
||||
}
|
||||
return e, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user