Skip to content

Commit

Permalink
providerfwk: use abstract function to block isEmpty functions
Browse files Browse the repository at this point in the history
with reflection to determine if empty
instead of using switch with cases for each field
  • Loading branch information
jeremmfr committed Jan 15, 2024
1 parent fa36eb0 commit 7d92ee7
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 1,402 deletions.
27 changes: 1 addition & 26 deletions internal/providerfwk/resource_bridge_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,32 +311,7 @@ type bridgeDomainConfig struct {
}

func (rscConfig *bridgeDomainConfig) isEmpty() bool {
switch {
case !rscConfig.DomainTypeBridge.IsNull():
return false
case !rscConfig.CommunityVlans.IsNull():
return false
case !rscConfig.Description.IsNull():
return false
case !rscConfig.DomainID.IsNull():
return false
case !rscConfig.Interface.IsNull():
return false
case !rscConfig.IsolatedVLAN.IsNull():
return false
case !rscConfig.RoutingInterface.IsNull():
return false
case !rscConfig.ServiceID.IsNull():
return false
case !rscConfig.VLANID.IsNull():
return false
case !rscConfig.VLANIDList.IsNull():
return false
case rscConfig.VXLAN != nil:
return false
default:
return true
}
return tfdata.CheckBlockIsEmpty(rscConfig, "ID", "Name", "RoutingInstance")
}

type bridgeDomainBlockVXLAN struct {
Expand Down
11 changes: 1 addition & 10 deletions internal/providerfwk/resource_evpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,7 @@ type evpnBlockDuplicateMACDetection struct {
}

func (block *evpnBlockDuplicateMACDetection) isEmpty() bool {
switch {
case !block.AutoRecoveryTime.IsNull():
return false
case !block.DetectionThreshold.IsNull():
return false
case !block.DetectionWindow.IsNull():
return false
default:
return true
}
return tfdata.CheckBlockIsEmpty(block)
}

type evpnBlockSwitchOrRIOptions struct {
Expand Down
131 changes: 3 additions & 128 deletions internal/providerfwk/resource_firewall_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,16 +790,7 @@ type firewallFilterBlockTermConfig struct {
}

func (block *firewallFilterBlockTermConfig) isEmpty() bool {
switch {
case !block.Filter.IsNull():
return false
case block.From != nil:
return false
case block.Then != nil:
return false
default:
return true
}
return tfdata.CheckBlockIsEmpty(block, "Name")
}

type firewallFilterBlockTermBlockFrom struct {
Expand Down Expand Up @@ -895,96 +886,7 @@ type firewallFilterBlockTermBlockFromConfig struct {
}

func (block *firewallFilterBlockTermBlockFromConfig) isEmpty() bool {
switch {
case !block.IsFragment.IsNull():
return false
case !block.TCPEstablished.IsNull():
return false
case !block.TCPInitial.IsNull():
return false
case !block.Address.IsNull():
return false
case !block.AddressExcept.IsNull():
return false
case !block.DestinationAddress.IsNull():
return false
case !block.DestinationAddressExcept.IsNull():
return false
case !block.DestinationMacAddress.IsNull():
return false
case !block.DestinationMacAddressExcept.IsNull():
return false
case !block.DestinationPort.IsNull():
return false
case !block.DestinationPortExcept.IsNull():
return false
case !block.DestinationPrefixList.IsNull():
return false
case !block.DestinationPrefixListExcept.IsNull():
return false
case !block.ForwardingClass.IsNull():
return false
case !block.ForwardingClassExcept.IsNull():
return false
case !block.IcmpCode.IsNull():
return false
case !block.IcmpCodeExcept.IsNull():
return false
case !block.IcmpType.IsNull():
return false
case !block.IcmpTypeExcept.IsNull():
return false
case !block.Interface.IsNull():
return false
case !block.LossPriority.IsNull():
return false
case !block.LossPriorityExcept.IsNull():
return false
case !block.NextHeader.IsNull():
return false
case !block.NextHeaderExcept.IsNull():
return false
case !block.PacketLength.IsNull():
return false
case !block.PacketLengthExcept.IsNull():
return false
case !block.PolicyMap.IsNull():
return false
case !block.PolicyMapExcept.IsNull():
return false
case !block.Port.IsNull():
return false
case !block.PortExcept.IsNull():
return false
case !block.PrefixList.IsNull():
return false
case !block.PrefixListExcept.IsNull():
return false
case !block.Protocol.IsNull():
return false
case !block.ProtocolExcept.IsNull():
return false
case !block.SourceAddress.IsNull():
return false
case !block.SourceAddressExcept.IsNull():
return false
case !block.SourceMacAddress.IsNull():
return false
case !block.SourceMacAddressExcept.IsNull():
return false
case !block.SourcePort.IsNull():
return false
case !block.SourcePortExcept.IsNull():
return false
case !block.SourcePrefixList.IsNull():
return false
case !block.SourcePrefixListExcept.IsNull():
return false
case !block.TCPFlags.IsNull():
return false
default:
return true
}
return tfdata.CheckBlockIsEmpty(block)
}

type firewallFilterBlockTermBlockThen struct {
Expand All @@ -1003,34 +905,7 @@ type firewallFilterBlockTermBlockThen struct {
}

func (block *firewallFilterBlockTermBlockThen) isEmpty() bool {
switch {
case !block.Log.IsNull():
return false
case !block.PacketMode.IsNull():
return false
case !block.PortMirror.IsNull():
return false
case !block.Sample.IsNull():
return false
case !block.ServiceAccounting.IsNull():
return false
case !block.Syslog.IsNull():
return false
case !block.Action.IsNull():
return false
case !block.Count.IsNull():
return false
case !block.ForwardingClass.IsNull():
return false
case !block.LossPriority.IsNull():
return false
case !block.Policer.IsNull():
return false
case !block.RoutingInstance.IsNull():
return false
default:
return true
}
return tfdata.CheckBlockIsEmpty(block)
}

func (rsc *firewallFilter) ValidateConfig(
Expand Down
13 changes: 1 addition & 12 deletions internal/providerfwk/resource_firewall_policer.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,7 @@ type firewallPolicerBlockThen struct {
}

func (block *firewallPolicerBlockThen) isEmpty() bool {
switch {
case !block.Discard.IsNull():
return false
case !block.OutOfProfile.IsNull():
return false
case !block.ForwardingClass.IsNull():
return false
case !block.LossPriority.IsNull():
return false
default:
return true
}
return tfdata.CheckBlockIsEmpty(block)
}

func (rsc *firewallPolicer) ValidateConfig(
Expand Down
19 changes: 4 additions & 15 deletions internal/providerfwk/resource_forwardingoptions_sampling.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,10 @@ type forwardingoptionsSamplingBlockInput struct {
RunLength types.Int64 `tfsdk:"run_length"`
}

func (block *forwardingoptionsSamplingBlockInput) isEmpty() bool {
return tfdata.CheckBlockIsEmpty(block)
}

//nolint:lll
type forwardingoptionsSamplingBlockFamilyInetOutput struct {
AggregateExportInterval types.Int64 `tfsdk:"aggregate_export_interval"`
Expand Down Expand Up @@ -820,21 +824,6 @@ type forwardingoptionsSamplingBlockOutputBlockInterface struct {
SourceAddress types.String `tfsdk:"source_address"`
}

func (block *forwardingoptionsSamplingBlockInput) isEmpty() bool {
switch {
case !block.MaxPacketsPerSecond.IsNull():
return false
case !block.MaximumPacketLength.IsNull():
return false
case !block.Rate.IsNull():
return false
case !block.RunLength.IsNull():
return false
default:
return true
}
}

func (rsc *forwardingoptionsSampling) ValidateConfig(
ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ type forwardingoptionsSamplingInstanceBlockInput struct {
RunLength types.Int64 `tfsdk:"run_length"`
}

func (block *forwardingoptionsSamplingInstanceBlockInput) isEmpty() bool {
return tfdata.CheckBlockIsEmpty(block)
}

//nolint:lll
type forwardingoptionsSamplingInstanceBlockFamilyInetOutput struct {
AggregateExportInterval types.Int64 `tfsdk:"aggregate_export_interval"`
Expand Down Expand Up @@ -763,21 +767,6 @@ type forwardingoptionsSamplingInstanceBlockOutputBlockInterface struct {
SourceAddress types.String `tfsdk:"source_address"`
}

func (block *forwardingoptionsSamplingInstanceBlockInput) isEmpty() bool {
switch {
case !block.MaxPacketsPerSecond.IsNull():
return false
case !block.MaximumPacketLength.IsNull():
return false
case !block.Rate.IsNull():
return false
case !block.RunLength.IsNull():
return false
default:
return true
}
}

func (rsc *forwardingoptionsSamplingInstance) ValidateConfig(
ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse,
) {
Expand Down
52 changes: 2 additions & 50 deletions internal/providerfwk/resource_interface_physical.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,26 +807,7 @@ type interfacePhysicalBlockEtherOpts struct {
}

func (block *interfacePhysicalBlockEtherOpts) isEmpty() bool {
switch {
case !block.AutoNegotiation.IsNull():
return false
case !block.NoAutoNegotiation.IsNull():
return false
case !block.FlowControl.IsNull():
return false
case !block.NoFlowControl.IsNull():
return false
case !block.Loopback.IsNull():
return false
case !block.NoLoopback.IsNull():
return false
case !block.Ae8023ad.IsNull():
return false
case !block.RedundantParent.IsNull():
return false
default:
return true
}
return tfdata.CheckBlockIsEmpty(block)
}

type interfacePhysicalBlockParentEtherOpts struct {
Expand Down Expand Up @@ -862,36 +843,7 @@ type interfacePhysicalBlockParentEtherOptsConfig struct {
}

func (block *interfacePhysicalBlockParentEtherOptsConfig) isEmpty() bool {
switch {
case !block.FlowControl.IsNull():
return false
case !block.NoFlowControl.IsNull():
return false
case !block.Loopback.IsNull():
return false
case !block.NoLoopback.IsNull():
return false
case !block.SourceFiltering.IsNull():
return false
case !block.LinkSpeed.IsNull():
return false
case !block.MinimumBandwidth.IsNull():
return false
case !block.MinimumLinks.IsNull():
return false
case !block.RedundancyGroup.IsNull():
return false
case !block.SourceAddressFilter.IsNull():
return false
case block.BFDLivenessDetection != nil:
return false
case block.LACP != nil:
return false
case block.MCAE != nil:
return false
default:
return true
}
return tfdata.CheckBlockIsEmpty(block)
}

type interfacePhysicalBlockParentEtherOptsBlockBFDLivenessDetection struct {
Expand Down
Loading

0 comments on commit 7d92ee7

Please sign in to comment.