From 0e7fd58fa315dca56f28343f8a81ff72839a6119 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Mon, 26 Apr 2021 16:23:44 +0200 Subject: [PATCH] clean code: fix lll linter errors with a var to map --- CHANGELOG.md | 1 + junos/resource_interface_physical.go | 48 ++++++++--------- junos/resource_security.go | 60 ++++++++++----------- junos/resource_security_screen.go | 79 ++++++++++++---------------- junos/resource_services.go | 7 ++- 5 files changed, 90 insertions(+), 105 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71e17ea5..baa02f6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ENHANCEMENTS: * resource/`junos_security`: add `policies` argument with `policy_rematch` and `policy_rematch_extensive` arguments inside (Fixes #185) Thanks @Sha-San-P * clean code: remove override of the lists of 1 map to handle directly the map +* clean code: fix lll linter errors with a var to map BUG FIXES: diff --git a/junos/resource_interface_physical.go b/junos/resource_interface_physical.go index f6afba20..7fb4c557 100644 --- a/junos/resource_interface_physical.go +++ b/junos/resource_interface_physical.go @@ -1392,78 +1392,74 @@ func readInterfacePhysicalParentEtherOpts(confRead *interfacePhysicalOptions, it "version": "", }) } + parentEtherOptsBFDLiveDetect := confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0] itemTrimBfdLiveDet := strings.TrimPrefix(itemTrim, "bfd-liveness-detection ") switch { case strings.HasPrefix(itemTrimBfdLiveDet, "local-address "): - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["local_address"] = - strings.TrimPrefix(itemTrimBfdLiveDet, "local-address ") + parentEtherOptsBFDLiveDetect["local_address"] = strings.TrimPrefix(itemTrimBfdLiveDet, "local-address ") case strings.HasPrefix(itemTrimBfdLiveDet, "authentication algorithm "): - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["authentication_algorithm"] = + parentEtherOptsBFDLiveDetect["authentication_algorithm"] = strings.TrimPrefix(itemTrimBfdLiveDet, "authentication algorithm ") case strings.HasPrefix(itemTrimBfdLiveDet, "authentication key-chain "): - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["authentication_key_chain"] = + parentEtherOptsBFDLiveDetect["authentication_key_chain"] = strings.TrimPrefix(itemTrimBfdLiveDet, "authentication key-chain ") case itemTrimBfdLiveDet == "authentication loose-check": - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["authentication_loose_check"] = - true + parentEtherOptsBFDLiveDetect["authentication_loose_check"] = true case strings.HasPrefix(itemTrimBfdLiveDet, "detection-time threshold "): var err error - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["detection_time_threshold"], - err = strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "detection-time threshold ")) + parentEtherOptsBFDLiveDetect["detection_time_threshold"], err = + strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "detection-time threshold ")) if err != nil { return fmt.Errorf("failed to convert value from '%s' to integer : %w", itemTrim, err) } case strings.HasPrefix(itemTrimBfdLiveDet, "holddown-interval "): var err error - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["holddown_interval"], - err = strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "holddown-interval ")) + parentEtherOptsBFDLiveDetect["holddown_interval"], err = + strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "holddown-interval ")) if err != nil { return fmt.Errorf("failed to convert value from '%s' to integer : %w", itemTrim, err) } case strings.HasPrefix(itemTrimBfdLiveDet, "minimum-interval "): var err error - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["minimum_interval"], - err = strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "minimum-interval ")) + parentEtherOptsBFDLiveDetect["minimum_interval"], err = + strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "minimum-interval ")) if err != nil { return fmt.Errorf("failed to convert value from '%s' to integer : %w", itemTrim, err) } case strings.HasPrefix(itemTrimBfdLiveDet, "minimum-receive-interval "): var err error - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["minimum_receive_interval"], - err = strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "minimum-receive-interval ")) + parentEtherOptsBFDLiveDetect["minimum_receive_interval"], err = + strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "minimum-receive-interval ")) if err != nil { return fmt.Errorf("failed to convert value from '%s' to integer : %w", itemTrim, err) } case strings.HasPrefix(itemTrimBfdLiveDet, "multiplier "): var err error - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["multiplier"], - err = strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "multiplier ")) + parentEtherOptsBFDLiveDetect["multiplier"], err = + strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "multiplier ")) if err != nil { return fmt.Errorf("failed to convert value from '%s' to integer : %w", itemTrim, err) } case strings.HasPrefix(itemTrimBfdLiveDet, "neighbor "): - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["neighbor"] = - strings.TrimPrefix(itemTrimBfdLiveDet, "neighbor ") + parentEtherOptsBFDLiveDetect["neighbor"] = strings.TrimPrefix(itemTrimBfdLiveDet, "neighbor ") case itemTrimBfdLiveDet == "no-adaptation": - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["no_adaptation"] = - true + parentEtherOptsBFDLiveDetect["no_adaptation"] = true case strings.HasPrefix(itemTrimBfdLiveDet, "transmit-interval minimum-interval "): var err error - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["transmit_interval_minimum_interval"], // nolint: lll - err = strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "transmit-interval minimum-interval ")) + parentEtherOptsBFDLiveDetect["transmit_interval_minimum_interval"], err = + strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "transmit-interval minimum-interval ")) if err != nil { return fmt.Errorf("failed to convert value from '%s' to integer : %w", itemTrim, err) } case strings.HasPrefix(itemTrimBfdLiveDet, "transmit-interval threshold "): var err error - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["transmit_interval_threshold"], - err = strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "transmit-interval threshold ")) + parentEtherOptsBFDLiveDetect["transmit_interval_threshold"], err = + strconv.Atoi(strings.TrimPrefix(itemTrimBfdLiveDet, "transmit-interval threshold ")) if err != nil { return fmt.Errorf("failed to convert value from '%s' to integer : %w", itemTrim, err) } case strings.HasPrefix(itemTrimBfdLiveDet, "version "): - confRead.parentEtherOpts[0]["bfd_liveness_detection"].([]map[string]interface{})[0]["version"] = - strings.TrimPrefix(itemTrimBfdLiveDet, "version ") + parentEtherOptsBFDLiveDetect["version"] = strings.TrimPrefix(itemTrimBfdLiveDet, "version ") } case itemTrim == flowControlWords: confRead.parentEtherOpts[0]["flow_control"] = true diff --git a/junos/resource_security.go b/junos/resource_security.go index 68244f41..5a0b4d62 100644 --- a/junos/resource_security.go +++ b/junos/resource_security.go @@ -1609,23 +1609,23 @@ func readSecurityFlow(confRead *securityOptions, itemTrimFlow string) error { "no_packet_flooding": make([]map[string]interface{}, 0), }) } + flowEthernetSwitching := confRead.flow[0]["ethernet_switching"].([]map[string]interface{})[0] switch { case itemTrim == "ethernet-switching block-non-ip-all": - confRead.flow[0]["ethernet_switching"].([]map[string]interface{})[0]["block_non_ip_all"] = true + flowEthernetSwitching["block_non_ip_all"] = true case itemTrim == "ethernet-switching bypass-non-ip-unicast": - confRead.flow[0]["ethernet_switching"].([]map[string]interface{})[0]["bypass_non_ip_unicast"] = true + flowEthernetSwitching["bypass_non_ip_unicast"] = true case itemTrim == "ethernet-switching bpdu-vlan-flooding": - confRead.flow[0]["ethernet_switching"].([]map[string]interface{})[0]["bpdu_vlan_flooding"] = true + flowEthernetSwitching["bpdu_vlan_flooding"] = true case strings.HasPrefix(itemTrim, "ethernet-switching no-packet-flooding"): - if len(confRead.flow[0]["ethernet_switching"].([]map[string]interface{})[0]["no_packet_flooding"].([]map[string]interface{})) == 0 { // nolint: lll - confRead.flow[0]["ethernet_switching"].([]map[string]interface{})[0]["no_packet_flooding"] = append( - confRead.flow[0]["ethernet_switching"].([]map[string]interface{})[0]["no_packet_flooding"].([]map[string]interface{}), // nolint: lll - map[string]interface{}{ + if len(flowEthernetSwitching["no_packet_flooding"].([]map[string]interface{})) == 0 { + flowEthernetSwitching["no_packet_flooding"] = append( + flowEthernetSwitching["no_packet_flooding"].([]map[string]interface{}), map[string]interface{}{ "no_trace_route": false, }) } if itemTrim == "ethernet-switching no-packet-flooding no-trace-route" { - confRead.flow[0]["ethernet_switching"].([]map[string]interface{})[0]["no_packet_flooding"].([]map[string]interface{})[0]["no_trace_route"] = true // nolint: lll + flowEthernetSwitching["no_packet_flooding"].([]map[string]interface{})[0]["no_trace_route"] = true } } case itemTrim == "force-ip-reassembly": @@ -1732,35 +1732,34 @@ func readSecurityFlow(confRead *securityOptions, itemTrimFlow string) error { "time_wait_state": make([]map[string]interface{}, 0), }) } + flowTCPSession := confRead.flow[0]["tcp_session"].([]map[string]interface{})[0] switch { case itemTrim == "tcp-session fin-invalidate-session": - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["fin_invalidate_session"] = true + flowTCPSession["fin_invalidate_session"] = true case strings.HasPrefix(itemTrim, "tcp-session maximum-window "): - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["maximum_window"] = - strings.TrimPrefix(itemTrim, "tcp-session maximum-window ") + flowTCPSession["maximum_window"] = strings.TrimPrefix(itemTrim, "tcp-session maximum-window ") case itemTrim == "tcp-session no-sequence-check": - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["no_sequence_check"] = true + flowTCPSession["no_sequence_check"] = true case itemTrim == "tcp-session no-syn-check": - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["no_syn_check"] = true + flowTCPSession["no_syn_check"] = true case itemTrim == "tcp-session no-syn-check-in-tunnel": - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["no_syn_check_in_tunnel"] = true + flowTCPSession["no_syn_check_in_tunnel"] = true case itemTrim == "tcp-session rst-invalidate-session": - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["rst_invalidate_session"] = true + flowTCPSession["rst_invalidate_session"] = true case itemTrim == "tcp-session rst-sequence-check": - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["rst_sequence_check"] = true + flowTCPSession["rst_sequence_check"] = true case itemTrim == "tcp-session strict-syn-check": - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["strict_syn_check"] = true + flowTCPSession["strict_syn_check"] = true case strings.HasPrefix(itemTrim, "tcp-session tcp-initial-timeout "): var err error - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["tcp_initial_timeout"], err = + flowTCPSession["tcp_initial_timeout"], err = strconv.Atoi(strings.TrimPrefix(itemTrim, "tcp-session tcp-initial-timeout ")) if err != nil { return fmt.Errorf("failed to convert value from '%s' to integer : %w", itemTrim, err) } case strings.HasPrefix(itemTrim, "tcp-session time-wait-state"): - if len(confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["time_wait_state"].([]map[string]interface{})) == 0 { // nolint: lll - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["time_wait_state"] = append( - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["time_wait_state"].([]map[string]interface{}), + if len(flowTCPSession["time_wait_state"].([]map[string]interface{})) == 0 { + flowTCPSession["time_wait_state"] = append(flowTCPSession["time_wait_state"].([]map[string]interface{}), map[string]interface{}{ "apply_to_half_close_state": false, "session_ageout": false, @@ -1769,12 +1768,12 @@ func readSecurityFlow(confRead *securityOptions, itemTrimFlow string) error { } switch { case itemTrim == "tcp-session time-wait-state apply-to-half-close-state": - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["time_wait_state"].([]map[string]interface{})[0]["apply_to_half_close_state"] = true // nolint: lll + flowTCPSession["time_wait_state"].([]map[string]interface{})[0]["apply_to_half_close_state"] = true case itemTrim == "tcp-session time-wait-state session-ageout": - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["time_wait_state"].([]map[string]interface{})[0]["session_ageout"] = true // nolint: lll + flowTCPSession["time_wait_state"].([]map[string]interface{})[0]["session_ageout"] = true case strings.HasPrefix(itemTrim, "tcp-session time-wait-state session-timeout "): var err error - confRead.flow[0]["tcp_session"].([]map[string]interface{})[0]["time_wait_state"].([]map[string]interface{})[0]["session_timeout"], err = // nolint: lll + flowTCPSession["time_wait_state"].([]map[string]interface{})[0]["session_timeout"], err = strconv.Atoi(strings.TrimPrefix(itemTrim, "tcp-session time-wait-state session-timeout ")) if err != nil { return fmt.Errorf("failed to convert value from '%s' to integer : %w", itemTrim, err) @@ -2006,23 +2005,22 @@ func readSecurityUtm(confRead *securityOptions, itemTrimUtm string) error { }) } itemTrimServer := strings.TrimPrefix(itemTrimUtm, "utm feature-profile web-filtering juniper-enhanced server") + utmFeatProfWebFiltJunEnhServer := + confRead.utm[0]["feature_profile_web_filtering_juniper_enhanced_server"].([]map[string]interface{})[0] switch { case strings.HasPrefix(itemTrimServer, " host "): - confRead.utm[0]["feature_profile_web_filtering_juniper_enhanced_server"].([]map[string]interface{})[0]["host"] = - strings.TrimPrefix(itemTrimServer, " host ") + utmFeatProfWebFiltJunEnhServer["host"] = strings.TrimPrefix(itemTrimServer, " host ") case strings.HasPrefix(itemTrimServer, " port "): var err error - confRead.utm[0]["feature_profile_web_filtering_juniper_enhanced_server"].([]map[string]interface{})[0]["port"], err = - strconv.Atoi(strings.TrimPrefix(itemTrimServer, " port ")) + utmFeatProfWebFiltJunEnhServer["port"], err = strconv.Atoi(strings.TrimPrefix(itemTrimServer, " port ")) if err != nil { return fmt.Errorf("failed to convert value from '%s' to integer : %w", itemTrimUtm, err) } case strings.HasPrefix(itemTrimServer, " proxy-profile "): - confRead.utm[0]["feature_profile_web_filtering_juniper_enhanced_server"].([]map[string]interface{})[0]["proxy_profile"] = //nolint: lll + utmFeatProfWebFiltJunEnhServer["proxy_profile"] = strings.Trim(strings.TrimPrefix(itemTrimServer, " proxy-profile "), "\"") case strings.HasPrefix(itemTrimServer, " routing-instance "): - confRead.utm[0]["feature_profile_web_filtering_juniper_enhanced_server"].([]map[string]interface{})[0]["routing_instance"] = //nolint: lll - strings.TrimPrefix(itemTrimServer, " routing-instance ") + utmFeatProfWebFiltJunEnhServer["routing_instance"] = strings.TrimPrefix(itemTrimServer, " routing-instance ") } } diff --git a/junos/resource_security_screen.go b/junos/resource_security_screen.go index 2e067b1d..0d8e2563 100644 --- a/junos/resource_security_screen.go +++ b/junos/resource_security_screen.go @@ -1410,17 +1410,18 @@ func readSecurityScreenIP(confRead *screenOptions, itemTrim string) error { "user_defined_header_type": make([]string, 0), }) } + ipIPv6ExtensionHeader := confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0] switch { case strings.HasPrefix(itemTrim, "ip ipv6-extension-header AH-header"): - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["ah_header"] = true + ipIPv6ExtensionHeader["ah_header"] = true case strings.HasPrefix(itemTrim, "ip ipv6-extension-header ESP-header"): - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["esp_header"] = true + ipIPv6ExtensionHeader["esp_header"] = true case strings.HasPrefix(itemTrim, "ip ipv6-extension-header HIP-header"): - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["hip_header"] = true + ipIPv6ExtensionHeader["hip_header"] = true case strings.HasPrefix(itemTrim, "ip ipv6-extension-header destination-header"): - if len(confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["destination_header"].([]map[string]interface{})) == 0 { // nolint: lll - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["destination_header"] = append( - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["destination_header"].([]map[string]interface{}), // nolint: lll + if len(ipIPv6ExtensionHeader["destination_header"].([]map[string]interface{})) == 0 { + ipIPv6ExtensionHeader["destination_header"] = append( + ipIPv6ExtensionHeader["destination_header"].([]map[string]interface{}), map[string]interface{}{ "ilnp_nonce_option": false, "home_address_option": false, @@ -1429,31 +1430,27 @@ func readSecurityScreenIP(confRead *screenOptions, itemTrim string) error { "user_defined_option_type": make([]string, 0), }) } + ipIPv6ExtensionHeaderDstHeader := ipIPv6ExtensionHeader["destination_header"].([]map[string]interface{})[0] switch { case itemTrim == "ip ipv6-extension-header destination-header ILNP-nonce-option": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["destination_header"].([]map[string]interface{})[0]["ilnp_nonce_option"] = // nolint: lll - true + ipIPv6ExtensionHeaderDstHeader["ilnp_nonce_option"] = true case itemTrim == "ip ipv6-extension-header destination-header home-address-option": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["destination_header"].([]map[string]interface{})[0]["home_address_option"] = // nolint: lll - true + ipIPv6ExtensionHeaderDstHeader["home_address_option"] = true case itemTrim == "ip ipv6-extension-header destination-header line-identification-option": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["destination_header"].([]map[string]interface{})[0]["line_identification_option"] = // nolint: lll - true + ipIPv6ExtensionHeaderDstHeader["line_identification_option"] = true case itemTrim == "ip ipv6-extension-header destination-header tunnel-encapsulation-limit-option": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["destination_header"].([]map[string]interface{})[0]["tunnel_encapsulation_limit_option"] = // nolint: lll - true + ipIPv6ExtensionHeaderDstHeader["tunnel_encapsulation_limit_option"] = true case strings.HasPrefix(itemTrim, "ip ipv6-extension-header destination-header user-defined-option-type "): - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["destination_header"].([]map[string]interface{})[0]["user_defined_option_type"] = // nolint: lll - append( - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["destination_header"].([]map[string]interface{})[0]["user_defined_option_type"].([]string), // nolint: lll - strings.TrimPrefix(itemTrim, "ip ipv6-extension-header destination-header user-defined-option-type ")) + ipIPv6ExtensionHeaderDstHeader["user_defined_option_type"] = append( + ipIPv6ExtensionHeaderDstHeader["user_defined_option_type"].([]string), + strings.TrimPrefix(itemTrim, "ip ipv6-extension-header destination-header user-defined-option-type ")) } case strings.HasPrefix(itemTrim, "ip ipv6-extension-header fragment-header"): - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["fragment_header"] = true + ipIPv6ExtensionHeader["fragment_header"] = true case strings.HasPrefix(itemTrim, "ip ipv6-extension-header hop-by-hop-header"): - if len(confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["hop_by_hop_header"].([]map[string]interface{})) == 0 { // nolint: lll - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["hop_by_hop_header"] = append( - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["hop_by_hop_header"].([]map[string]interface{}), // nolint: lll + if len(ipIPv6ExtensionHeader["hop_by_hop_header"].([]map[string]interface{})) == 0 { + ipIPv6ExtensionHeader["hop_by_hop_header"] = append( + ipIPv6ExtensionHeader["hop_by_hop_header"].([]map[string]interface{}), map[string]interface{}{ "calipso_option": false, "rpl_option": false, @@ -1464,42 +1461,36 @@ func readSecurityScreenIP(confRead *screenOptions, itemTrim string) error { "user_defined_option_type": make([]string, 0), }) } + ipIPv6ExtensionHeaderHopByHopHeader := ipIPv6ExtensionHeader["hop_by_hop_header"].([]map[string]interface{})[0] switch { case itemTrim == "ip ipv6-extension-header hop-by-hop-header CALIPSO-option": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["hop_by_hop_header"].([]map[string]interface{})[0]["calipso_option"] = // nolint: lll - true + ipIPv6ExtensionHeaderHopByHopHeader["calipso_option"] = true case itemTrim == "ip ipv6-extension-header hop-by-hop-header RPL-option": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["hop_by_hop_header"].([]map[string]interface{})[0]["rpl_option"] = // nolint: lll - true + ipIPv6ExtensionHeaderHopByHopHeader["rpl_option"] = true case itemTrim == "ip ipv6-extension-header hop-by-hop-header SMF-DPD-option": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["hop_by_hop_header"].([]map[string]interface{})[0]["smf_dpd_option"] = // nolint: lll - true + ipIPv6ExtensionHeaderHopByHopHeader["smf_dpd_option"] = true case itemTrim == "ip ipv6-extension-header hop-by-hop-header jumbo-payload-option": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["hop_by_hop_header"].([]map[string]interface{})[0]["jumbo_payload_option"] = // nolint: lll - true + ipIPv6ExtensionHeaderHopByHopHeader["jumbo_payload_option"] = true case itemTrim == "ip ipv6-extension-header hop-by-hop-header quick-start-option": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["hop_by_hop_header"].([]map[string]interface{})[0]["quick_start_option"] = // nolint: lll - true + ipIPv6ExtensionHeaderHopByHopHeader["quick_start_option"] = true case itemTrim == "ip ipv6-extension-header hop-by-hop-header router-alert-option": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["hop_by_hop_header"].([]map[string]interface{})[0]["router_alert_option"] = // nolint: lll - true + ipIPv6ExtensionHeaderHopByHopHeader["router_alert_option"] = true case strings.HasPrefix(itemTrim, "ip ipv6-extension-header hop-by-hop-header user-defined-option-type "): - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["hop_by_hop_header"].([]map[string]interface{})[0]["user_defined_option_type"] = // nolint: lll - append( - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["hop_by_hop_header"].([]map[string]interface{})[0]["user_defined_option_type"].([]string), // nolint: lll - strings.TrimPrefix(itemTrim, "ip ipv6-extension-header hop-by-hop-header user-defined-option-type ")) + ipIPv6ExtensionHeaderHopByHopHeader["user_defined_option_type"] = append( + ipIPv6ExtensionHeaderHopByHopHeader["user_defined_option_type"].([]string), + strings.TrimPrefix(itemTrim, "ip ipv6-extension-header hop-by-hop-header user-defined-option-type ")) } case itemTrim == "ip ipv6-extension-header mobility-header": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["mobility_header"] = true + ipIPv6ExtensionHeader["mobility_header"] = true case itemTrim == "ip ipv6-extension-header no-next-header": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["no_next_header"] = true + ipIPv6ExtensionHeader["no_next_header"] = true case itemTrim == "ip ipv6-extension-header routing-header": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["routing_header"] = true + ipIPv6ExtensionHeader["routing_header"] = true case itemTrim == "ip ipv6-extension-header shim6-header": - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["shim6_header"] = true + ipIPv6ExtensionHeader["shim6_header"] = true case strings.HasPrefix(itemTrim, "ip ipv6-extension-header user-defined-header-type "): - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["user_defined_header_type"] = append( - confRead.ip[0]["ipv6_extension_header"].([]map[string]interface{})[0]["user_defined_header_type"].([]string), + ipIPv6ExtensionHeader["user_defined_header_type"] = append( + ipIPv6ExtensionHeader["user_defined_header_type"].([]string), strings.TrimPrefix(itemTrim, "ip ipv6-extension-header user-defined-header-type ")) } case strings.HasPrefix(itemTrim, "ip ipv6-extension-header-limit "): diff --git a/junos/resource_services.go b/junos/resource_services.go index 460aa2ef..ce3ed4f5 100644 --- a/junos/resource_services.go +++ b/junos/resource_services.go @@ -702,13 +702,12 @@ func readServicesApplicationIdentification(confRead *servicesOptions, itemTrimAp "security_services": false, }) } + applicationSystemCache := confRead.appIdent[0]["application_system_cache"].([]map[string]interface{})[0] switch { case itemTrim == "application-system-cache no-miscellaneous-services": - confRead.appIdent[0]["application_system_cache"].([]map[string]interface{})[0]["no_miscellaneous_services"] = // nolint: lll - true + applicationSystemCache["no_miscellaneous_services"] = true case itemTrim == "application-system-cache security-services": - confRead.appIdent[0]["application_system_cache"].([]map[string]interface{})[0]["security_services"] = - true + applicationSystemCache["security_services"] = true } case itemTrim == "no-application-system-cache": confRead.appIdent[0]["no_application_system_cache"] = true