Refactor IPAM model classes to use records for Address, Subnetwork, Vlan, Vrf, Section, Tag, Domain, Nameserver, and Session; enhance documentation and implement value equality for records.
This commit is contained in:
@@ -1,77 +1,35 @@
|
||||
namespace PS.IPAM;
|
||||
namespace PS.IPAM;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an IP address entry in phpIPAM.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Address {
|
||||
public int Id { get; }
|
||||
public int SubnetId { get; }
|
||||
public string Ip { get; }
|
||||
public bool IsGateway { get; }
|
||||
public string Description { get; }
|
||||
public string Hostname { get; }
|
||||
public string MAC { get; }
|
||||
public string Owner { get; }
|
||||
public int TagId { get; }
|
||||
public int DeviceId { get; }
|
||||
public string Location { get; }
|
||||
public string Port { get; }
|
||||
public string Note { get; }
|
||||
public DateTime? LastSeen { get; }
|
||||
public bool ExcludePing { get; }
|
||||
public bool PTRignore { get; }
|
||||
public int PTR { get; }
|
||||
public string FirewallAddressObject { get; }
|
||||
public DateTime? EditDate { get; }
|
||||
public int CustomerId { get; }
|
||||
public Object? ExtendedData { get; }
|
||||
|
||||
public Address(
|
||||
int id,
|
||||
int subnetId,
|
||||
string ip,
|
||||
bool is_gateway,
|
||||
string description,
|
||||
string hostname,
|
||||
string mac,
|
||||
string owner,
|
||||
int tag,
|
||||
int deviceId,
|
||||
string location,
|
||||
string port,
|
||||
string note,
|
||||
DateTime? lastSeen,
|
||||
bool excludePing,
|
||||
bool PTRignore,
|
||||
int PTR,
|
||||
string firewallAddressObject,
|
||||
DateTime? editDate,
|
||||
int customer_id,
|
||||
Object? extendedData
|
||||
) {
|
||||
this.Id = id;
|
||||
this.SubnetId = subnetId;
|
||||
this.Ip = ip;
|
||||
this.IsGateway = is_gateway;
|
||||
this.Description = description;
|
||||
this.Hostname = hostname;
|
||||
this.MAC = mac;
|
||||
this.Owner = owner;
|
||||
this.TagId = tag;
|
||||
this.DeviceId = deviceId;
|
||||
this.Location = location;
|
||||
this.Port = port;
|
||||
this.Note = note;
|
||||
this.LastSeen = lastSeen;
|
||||
this.ExcludePing = excludePing;
|
||||
this.PTRignore = PTRignore;
|
||||
this.PTR = PTR;
|
||||
this.FirewallAddressObject = firewallAddressObject;
|
||||
this.EditDate = editDate;
|
||||
this.CustomerId = customer_id;
|
||||
this.ExtendedData = extendedData;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return this.Ip;
|
||||
}
|
||||
}
|
||||
public sealed record Address(
|
||||
int Id,
|
||||
int SubnetId,
|
||||
string Ip,
|
||||
bool IsGateway,
|
||||
string Description,
|
||||
string Hostname,
|
||||
string MAC,
|
||||
string Owner,
|
||||
int TagId,
|
||||
int DeviceId,
|
||||
string Location,
|
||||
string Port,
|
||||
string Note,
|
||||
DateTime? LastSeen,
|
||||
bool ExcludePing,
|
||||
bool PTRIgnore,
|
||||
int PTR,
|
||||
string FirewallAddressObject,
|
||||
DateTime? EditDate,
|
||||
int CustomerId,
|
||||
Dictionary<string, object>? ExtendedData = null
|
||||
)
|
||||
{
|
||||
public override string ToString() => Ip;
|
||||
}
|
||||
|
||||
@@ -1,27 +1,17 @@
|
||||
namespace PS.IPAM;
|
||||
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an L2 domain in phpIPAM.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Domain {
|
||||
public int Id { get; }
|
||||
public string Name { get; }
|
||||
public string Description { get; }
|
||||
public string Sections { get; }
|
||||
|
||||
public Domain (
|
||||
int id,
|
||||
string name,
|
||||
string description,
|
||||
string sections
|
||||
) {
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
this.Description = description;
|
||||
this.Sections = sections;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Name;
|
||||
}
|
||||
}
|
||||
public sealed record Domain(
|
||||
int Id,
|
||||
string Name,
|
||||
string Description,
|
||||
string Sections
|
||||
)
|
||||
{
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
namespace PS.IPAM;
|
||||
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a nameserver configuration in phpIPAM.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Nameserver {
|
||||
public sealed record Nameserver
|
||||
{
|
||||
public int Id { get; }
|
||||
public string Name { get; }
|
||||
public string[] NameServers { get; }
|
||||
@@ -16,13 +21,15 @@ public class Nameserver {
|
||||
string nameServers,
|
||||
string description,
|
||||
string permissions,
|
||||
DateTime? editDate
|
||||
) {
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
this.NameServers = nameServers.Split(new char[] {';'});
|
||||
this.Description = description;
|
||||
this.Permissions = permissions;
|
||||
this.EditDate = editDate;
|
||||
DateTime? editDate)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
NameServers = nameServers?.Split(';', StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
|
||||
Description = description;
|
||||
Permissions = permissions;
|
||||
EditDate = editDate;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
@@ -1,57 +1,27 @@
|
||||
namespace PS.IPAM;
|
||||
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a section in phpIPAM that organizes subnets.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Section {
|
||||
public int Id { get; }
|
||||
public string Name { get; }
|
||||
public string Description { get; }
|
||||
public int MasterSectionId { get; }
|
||||
public string Permissions { get; }
|
||||
public bool StrictMode { get; }
|
||||
public string SubnetOrdering { get; }
|
||||
public int Order { get; }
|
||||
public DateTime? EditDate { get; }
|
||||
public bool ShowSubnet { get; }
|
||||
public bool ShowVlan { get; }
|
||||
public bool ShowVRF { get; }
|
||||
public bool ShowSupernetOnly { get; }
|
||||
public int DNSId { get; }
|
||||
|
||||
public Section (
|
||||
int id,
|
||||
string name,
|
||||
string description,
|
||||
int masterSectionId,
|
||||
string permissions,
|
||||
bool strictMode,
|
||||
string subnetOrdering,
|
||||
int order,
|
||||
DateTime? editDate,
|
||||
bool showSubnet,
|
||||
bool showVlan,
|
||||
bool showVRF,
|
||||
bool showSupernetOnly,
|
||||
int dnsId
|
||||
) {
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
this.Description = description;
|
||||
this.MasterSectionId = masterSectionId;
|
||||
this.Permissions = permissions;
|
||||
this.StrictMode = strictMode;
|
||||
this.SubnetOrdering = subnetOrdering;
|
||||
this.Order = order;
|
||||
this.EditDate = editDate;
|
||||
this.ShowSubnet = showSubnet;
|
||||
this.ShowVlan = showVlan;
|
||||
this.ShowVRF = showVRF;
|
||||
this.ShowSupernetOnly = showSupernetOnly;
|
||||
this.DNSId = dnsId;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Name;
|
||||
}
|
||||
}
|
||||
public sealed record Section(
|
||||
int Id,
|
||||
string Name,
|
||||
string Description,
|
||||
int MasterSectionId,
|
||||
string Permissions,
|
||||
bool StrictMode,
|
||||
string SubnetOrdering,
|
||||
int Order,
|
||||
DateTime? EditDate,
|
||||
bool ShowSubnet,
|
||||
bool ShowVlan,
|
||||
bool ShowVRF,
|
||||
bool ShowSupernetOnly,
|
||||
int DNSId
|
||||
)
|
||||
{
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
@@ -1,33 +1,27 @@
|
||||
namespace PS.IPAM;
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an authenticated session with phpIPAM API.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Session {
|
||||
public AuthType AuthType { get; }
|
||||
public string Token { get; set; }
|
||||
public string AppID { get; }
|
||||
public string URL { get; }
|
||||
public DateTime? Expires { get; set; }
|
||||
public object? Credentials { get; }
|
||||
public Session(
|
||||
AuthType authType,
|
||||
string token,
|
||||
string appId,
|
||||
string url,
|
||||
DateTime? expires,
|
||||
object? credentials
|
||||
) {
|
||||
AuthType = authType;
|
||||
Token = token;
|
||||
AppID = appId;
|
||||
URL = url;
|
||||
Expires = expires;
|
||||
Credentials = credentials;
|
||||
}
|
||||
public sealed record Session(
|
||||
AuthType AuthType,
|
||||
string Token,
|
||||
string AppID,
|
||||
string URL,
|
||||
DateTime? Expires,
|
||||
object? Credentials
|
||||
)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the current authentication token.
|
||||
/// </summary>
|
||||
public string Token { get; set; } = Token;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return base.ToString();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets the token expiration time.
|
||||
/// </summary>
|
||||
public DateTime? Expires { get; set; } = Expires;
|
||||
}
|
||||
|
||||
@@ -1,114 +1,51 @@
|
||||
namespace PS.IPAM;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a subnet/network in phpIPAM.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Subnetwork {
|
||||
public int Id { get; }
|
||||
public string Subnet { get; }
|
||||
public int Mask { get; }
|
||||
public int SectionId { get; }
|
||||
public string Description { get; }
|
||||
public string LinkedSubnet { get; }
|
||||
public string FirewallAddressObject { get; }
|
||||
public int VrfId { get; }
|
||||
public int MasterSubnetId { get; }
|
||||
public bool AllowRequests { get; }
|
||||
public int VlanId { get; }
|
||||
public bool ShowName { get; }
|
||||
public int DeviceId { get; }
|
||||
public string Permissions { get; }
|
||||
public bool PingSubnet { get; }
|
||||
public bool DiscoverSubnet { get; }
|
||||
public bool ResolveDNS { get; }
|
||||
public bool DNSRecursive { get; }
|
||||
public bool DNSRecords { get; }
|
||||
public int NameserverId { get; }
|
||||
public bool ScanAgent { get; }
|
||||
public bool IsFolder { get; }
|
||||
public bool IsFull { get; }
|
||||
public bool IsPool { get; }
|
||||
public int TagId { get; }
|
||||
public int Threshold { get; }
|
||||
public int LocationId { get; }
|
||||
public DateTime? EditDate { get; }
|
||||
public DateTime? LastScan { get; }
|
||||
public DateTime? LastDiscovery { get; }
|
||||
public Object Calculation { get; }
|
||||
public Object? ExtendedData { get; }
|
||||
public Subnetwork(
|
||||
int id,
|
||||
string subnet,
|
||||
int mask,
|
||||
int sectionId,
|
||||
string description,
|
||||
string linkedSubnet,
|
||||
string firewallAddressObject,
|
||||
int vrfId,
|
||||
int masterSubnetId,
|
||||
bool allowRequests,
|
||||
int vlanId,
|
||||
bool showName,
|
||||
int deviceId,
|
||||
string permissions,
|
||||
bool pingSubnet,
|
||||
bool discoverSubnet,
|
||||
bool resolveDNS,
|
||||
bool dnsRecursive,
|
||||
bool dnsRecords,
|
||||
int nameserverId,
|
||||
bool scanAgent,
|
||||
bool isFolder,
|
||||
bool isFull,
|
||||
bool isPool,
|
||||
int tagId,
|
||||
int threshold,
|
||||
int locationId,
|
||||
DateTime? editDate,
|
||||
DateTime? lastScan,
|
||||
DateTime? lastDiscovery,
|
||||
Object calculation,
|
||||
Object? custom_fields
|
||||
) {
|
||||
this.Id = id;
|
||||
this.Subnet = subnet;
|
||||
this.Mask = mask;
|
||||
this.SectionId = sectionId;
|
||||
this.Description = description;
|
||||
this.LinkedSubnet = linkedSubnet;
|
||||
this.FirewallAddressObject = firewallAddressObject;
|
||||
this.VrfId = vrfId;
|
||||
this.MasterSubnetId = masterSubnetId;
|
||||
this.AllowRequests = allowRequests;
|
||||
this.VlanId = vlanId;
|
||||
this.ShowName = showName;
|
||||
this.DeviceId = deviceId;
|
||||
this.Permissions = permissions;
|
||||
this.PingSubnet = pingSubnet;
|
||||
this.DiscoverSubnet = discoverSubnet;
|
||||
this.ResolveDNS = resolveDNS;
|
||||
this.DNSRecursive = dnsRecursive;
|
||||
this.DNSRecords = dnsRecords;
|
||||
this.NameserverId = nameserverId;
|
||||
this.ScanAgent = scanAgent;
|
||||
this.IsFolder = isFolder;
|
||||
this.IsFull = isFull;
|
||||
this.IsPool = isPool;
|
||||
this.TagId = tagId;
|
||||
this.Threshold = threshold;
|
||||
this.LocationId = locationId;
|
||||
this.EditDate = editDate;
|
||||
this.LastScan = lastScan;
|
||||
this.LastDiscovery = lastDiscovery;
|
||||
this.Calculation = calculation;
|
||||
this.ExtendedData = custom_fields;
|
||||
}
|
||||
public sealed record Subnetwork(
|
||||
int Id,
|
||||
string Subnet,
|
||||
int Mask,
|
||||
int SectionId,
|
||||
string Description,
|
||||
string LinkedSubnet,
|
||||
string FirewallAddressObject,
|
||||
int VrfId,
|
||||
int MasterSubnetId,
|
||||
bool AllowRequests,
|
||||
int VlanId,
|
||||
bool ShowName,
|
||||
int DeviceId,
|
||||
string Permissions,
|
||||
bool PingSubnet,
|
||||
bool DiscoverSubnet,
|
||||
bool ResolveDNS,
|
||||
bool DNSRecursive,
|
||||
bool DNSRecords,
|
||||
int NameserverId,
|
||||
bool ScanAgent,
|
||||
bool IsFolder,
|
||||
bool IsFull,
|
||||
bool IsPool,
|
||||
int TagId,
|
||||
int Threshold,
|
||||
int LocationId,
|
||||
DateTime? EditDate,
|
||||
DateTime? LastScan,
|
||||
DateTime? LastDiscovery,
|
||||
object Calculation,
|
||||
Dictionary<string, object>? ExtendedData = null
|
||||
)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the subnet in CIDR notation (e.g., "192.168.1.0/24").
|
||||
/// </summary>
|
||||
public string CIDR => $"{Subnet}/{Mask}";
|
||||
|
||||
public string GetCIDR() {
|
||||
return $"{this.Subnet}/{this.Mask}";
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.GetCIDR();
|
||||
}
|
||||
}
|
||||
public override string ToString() => CIDR;
|
||||
}
|
||||
|
||||
@@ -1,45 +1,21 @@
|
||||
namespace PS.IPAM;
|
||||
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an address tag in phpIPAM.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Tag {
|
||||
public int Id { get; }
|
||||
public string Type { get; }
|
||||
public bool ShowTag { get; }
|
||||
public string BGColor { get; }
|
||||
public string FGColor { get; }
|
||||
public bool Compress { get; }
|
||||
public bool Locked { get; }
|
||||
public bool UpdateTag { get; }
|
||||
|
||||
public Tag(
|
||||
int id,
|
||||
string type,
|
||||
bool showTag,
|
||||
string BGColor,
|
||||
string FGColor,
|
||||
string compress,
|
||||
string locked,
|
||||
bool updateTag
|
||||
) {
|
||||
this.Id = id;
|
||||
this.Type = type;
|
||||
this.ShowTag = showTag;
|
||||
this.BGColor = BGColor;
|
||||
this.FGColor = FGColor;
|
||||
this.Compress = this.StringToBool(compress);
|
||||
this.Locked = this.StringToBool(locked);
|
||||
this.UpdateTag = updateTag;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return this.Type;
|
||||
}
|
||||
|
||||
private bool StringToBool(string str) {
|
||||
if (str == "Yes") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public sealed record Tag(
|
||||
int Id,
|
||||
string Type,
|
||||
bool ShowTag,
|
||||
string BackgroundColor,
|
||||
string ForegroundColor,
|
||||
string Compress,
|
||||
string Locked,
|
||||
bool UpdateTag
|
||||
)
|
||||
{
|
||||
public override string ToString() => Type;
|
||||
}
|
||||
|
||||
@@ -1,41 +1,27 @@
|
||||
namespace PS.IPAM;
|
||||
|
||||
using System;
|
||||
using System.Dynamic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a VLAN in phpIPAM.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Vlan : DynamicObject {
|
||||
public int Id { get; }
|
||||
public int VlanId { get; }
|
||||
public int DomainId { get; }
|
||||
public string Name { get; }
|
||||
public int Number { get; }
|
||||
public string Description { get; }
|
||||
public DateTime? EditDate { get; }
|
||||
public int CustomerId { get; }
|
||||
public Object? ExtendedData { get; }
|
||||
public Vlan (
|
||||
int vlanId,
|
||||
int domainId,
|
||||
string name,
|
||||
int number,
|
||||
string description,
|
||||
DateTime? editDate,
|
||||
int customer_id,
|
||||
Object? custom_fields
|
||||
) {
|
||||
this.Id = vlanId;
|
||||
this.VlanId = vlanId;
|
||||
this.DomainId = domainId;
|
||||
this.Name = name;
|
||||
this.Number = number;
|
||||
this.Description = description;
|
||||
this.EditDate = editDate;
|
||||
this.CustomerId = customer_id;
|
||||
this.ExtendedData = custom_fields;
|
||||
}
|
||||
public sealed record Vlan(
|
||||
int Id,
|
||||
int DomainId,
|
||||
string Name,
|
||||
int Number,
|
||||
string Description,
|
||||
DateTime? EditDate,
|
||||
int CustomerId,
|
||||
Dictionary<string, object>? ExtendedData = null
|
||||
)
|
||||
{
|
||||
/// <summary>
|
||||
/// Alias for Id to maintain API compatibility.
|
||||
/// </summary>
|
||||
public int VlanId => Id;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{this.Number}";
|
||||
}
|
||||
}
|
||||
public override string ToString() => Number.ToString();
|
||||
}
|
||||
|
||||
@@ -1,35 +1,21 @@
|
||||
namespace PS.IPAM;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a VRF (Virtual Routing and Forwarding) instance in phpIPAM.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Vrf {
|
||||
public int Id { get; }
|
||||
public string Name { get; }
|
||||
public string RouteDistinguisher { get; }
|
||||
public string Description { get; }
|
||||
public string Sections { get; }
|
||||
public DateTime? EditDate { get; }
|
||||
public Object? ExtendedData { get; }
|
||||
|
||||
public Vrf(
|
||||
int id,
|
||||
string name,
|
||||
string rd,
|
||||
string description,
|
||||
string sections,
|
||||
DateTime? editDate,
|
||||
Object? custom_fields
|
||||
) {
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
this.RouteDistinguisher = rd;
|
||||
this.Description = description;
|
||||
this.Sections = sections;
|
||||
this.EditDate = editDate;
|
||||
this.ExtendedData = custom_fields;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Name;
|
||||
}
|
||||
}
|
||||
public sealed record Vrf(
|
||||
int Id,
|
||||
string Name,
|
||||
string RouteDistinguisher,
|
||||
string Description,
|
||||
string Sections,
|
||||
DateTime? EditDate,
|
||||
Dictionary<string, object>? ExtendedData = null
|
||||
)
|
||||
{
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user