Skip to content

Commit

Permalink
Add status code to getSessionContext
Browse files Browse the repository at this point in the history
To handle invalid configuration of a context in both object and provider
levels.

Signed-off-by: Kobi Samoray <[email protected]>
  • Loading branch information
ksamoray committed Jun 9, 2024
1 parent b2db212 commit 8b24632
Show file tree
Hide file tree
Showing 94 changed files with 1,100 additions and 291 deletions.
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_bfd_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ func dataSourceNsxtPolicyBfdProfile() *schema.Resource {
func dataSourceNsxtPolicyBfdProfileRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)

_, err := policyDataSourceResourceRead(d, connector, getSessionContext(d, m), "BfdProfile", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, connector, context, "BfdProfile", nil)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_bridge_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ func dataSourceNsxtPolicyBridgeProfile() *schema.Resource {
func dataSourceNsxtPolicyBridgeProfileRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)

_, err := policyDataSourceResourceRead(d, connector, getSessionContext(d, m), "L2BridgeEndpointProfile", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, connector, context, "L2BridgeEndpointProfile", nil)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ func dataSourceNsxtPolicyCertificate() *schema.Resource {
func dataSourceNsxtPolicyCertificateRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)

_, err := policyDataSourceResourceRead(d, connector, getSessionContext(d, m), "TlsCertificate", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, connector, context, "TlsCertificate", nil)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_context_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func dataSourceNsxtPolicyContextProfile() *schema.Resource {
}

func dataSourceNsxtPolicyContextProfileRead(d *schema.ResourceData, m interface{}) error {
_, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "PolicyContextProfile", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, getPolicyConnector(m), context, "PolicyContextProfile", nil)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_dhcp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ func dataSourceNsxtPolicyDhcpServer() *schema.Resource {
func dataSourceNsxtPolicyDhcpServerRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)

_, err := policyDataSourceResourceRead(d, connector, getSessionContext(d, m), "DhcpServerConfig", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, connector, context, "DhcpServerConfig", nil)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ func dataSourceNsxtPolicyDistributedFloodProtectionProfile() *schema.Resource {
func dataSourceNsxtPolicyDistributedFloodProtectionProfileRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)

_, err := policyDataSourceResourceRead(d, connector, getSessionContext(d, m), "DistributedFloodProtectionProfile", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, connector, context, "DistributedFloodProtectionProfile", nil)
if err != nil {
return err
}
Expand Down
12 changes: 10 additions & 2 deletions nsxt/data_source_nsxt_policy_edge_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ func dataSourceNsxtPolicyEdgeClusterRead(d *schema.ResourceData, m interface{})
query := make(map[string]string)
globalPolicyEnforcementPointPath := getGlobalPolicyEnforcementPointPath(m, &objSitePath)
query["parent_path"] = globalPolicyEnforcementPointPath
_, err := policyDataSourceResourceReadWithValidation(d, getPolicyConnector(m), getSessionContext(d, m), "PolicyEdgeCluster", query, false)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceReadWithValidation(d, getPolicyConnector(m), context, "PolicyEdgeCluster", query, false)
if err != nil {
return err
}
Expand All @@ -50,7 +54,11 @@ func dataSourceNsxtPolicyEdgeClusterRead(d *schema.ResourceData, m interface{})

// Local manager
connector := getPolicyConnector(m)
_, err := policyDataSourceResourceRead(d, connector, getSessionContext(d, m), "PolicyEdgeCluster", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, connector, context, "PolicyEdgeCluster", nil)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_edge_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ func dataSourceNsxtPolicyEdgeNodeRead(d *schema.ResourceData, m interface{}) err
if memberIndexSet {
query["member_index"] = strconv.Itoa(memberIndex.(int))
}
obj, err := policyDataSourceResourceReadWithValidation(d, getPolicyConnector(m), getSessionContext(d, m), "PolicyEdgeNode", query, false)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
obj, err := policyDataSourceResourceReadWithValidation(d, getPolicyConnector(m), context, "PolicyEdgeNode", query, false)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_gateway_dns_forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ func dataSourceNsxtPolicyGatewayDNSForwarderRead(d *schema.ResourceData, m inter
if len(gwPath) > 0 {
query["parent_path"] = fmt.Sprintf("%s*", gwPath)
}
_, err := policyDataSourceResourceReadWithValidation(d, connector, getSessionContext(d, m), "PolicyDnsForwarder", query, false)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceReadWithValidation(d, connector, context, "PolicyDnsForwarder", query, false)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ func dataSourceNsxtPolicyGatewayFloodProtectionProfile() *schema.Resource {
func dataSourceNsxtPolicyGatewayFloodProtectionProfileRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)

_, err := policyDataSourceResourceRead(d, connector, getSessionContext(d, m), "GatewayFloodProtectionProfile", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, connector, context, "GatewayFloodProtectionProfile", nil)
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions nsxt/data_source_nsxt_policy_gateway_interface_realization.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ func dataSourceNsxtPolicyGatewayInterfaceRealization() *schema.Resource {

func dataSourceNsxtPolicyGatewayInterfaceRealizationRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)
client := realizedstate.NewRealizedEntitiesClient(getSessionContext(d, m), connector)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
client := realizedstate.NewRealizedEntitiesClient(context, connector)

id := d.Get("id").(string)
gatewayPath := d.Get("gateway_path").(string)
Expand Down Expand Up @@ -154,7 +158,7 @@ func dataSourceNsxtPolicyGatewayInterfaceRealizationRead(d *schema.ResourceData,
MinTimeout: 1 * time.Second,
Delay: time.Duration(delay) * time.Second,
}
_, err := stateConf.WaitForState()
_, err = stateConf.WaitForState()
if err != nil {
return fmt.Errorf("Failed to get gateway interface realization information for %s: %v", gatewayPath, err)
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_gateway_locale_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ func dataSourceNsxtPolicyGatewayLocaleServiceRead(d *schema.ResourceData, m inte
gwPath := d.Get("gateway_path").(string)
query := make(map[string]string)
query["parent_path"] = gwPath
obj, err := policyDataSourceResourceReadWithValidation(d, connector, getSessionContext(d, m), "LocaleServices", query, false)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
obj, err := policyDataSourceResourceReadWithValidation(d, connector, context, "LocaleServices", query, false)

if err != nil {
return err
Expand Down
5 changes: 4 additions & 1 deletion nsxt/data_source_nsxt_policy_gateway_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ func dataSourceNsxtPolicyGatewayPolicyRead(d *schema.ResourceData, m interface{}

category := d.Get("category").(string)
domain := d.Get("domain").(string)
context := getSessionContext(d, m)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
if isPolicyGlobalManager(m) {
query := make(map[string]string)
query["parent_path"] = "*/" + domain
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_gateway_prefix_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ func dataSourceNsxtPolicyGatewayPrefixListRead(d *schema.ResourceData, m interfa
if len(gwPath) > 0 {
query["parent_path"] = fmt.Sprintf("%s*", gwPath)
}
_, err := policyDataSourceResourceReadWithValidation(d, connector, getSessionContext(d, m), "PrefixList", query, false)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceReadWithValidation(d, connector, context, "PrefixList", query, false)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion nsxt/data_source_nsxt_policy_gateway_qos_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func dataSourceNsxtPolicyGatewayQosProfile() *schema.Resource {
}

func dataSourceNsxtPolicyGatewayQosProfileRead(d *schema.ResourceData, m interface{}) error {
_, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "GatewayQosProfile", nil)
context, err := getSessionContext(d, m)

Check failure on line 25 in nsxt/data_source_nsxt_policy_gateway_qos_profile.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
_, err = policyDataSourceResourceRead(d, getPolicyConnector(m), context, "GatewayQosProfile", nil)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_gateway_route_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ func dataSourceNsxtPolicyGatewayRouteMapRead(d *schema.ResourceData, m interface
if len(gwPath) > 0 {
query["parent_path"] = fmt.Sprintf("%s*", gwPath)
}
_, err := policyDataSourceResourceReadWithValidation(d, connector, getSessionContext(d, m), "Tier0RouteMap", query, false)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceReadWithValidation(d, connector, context, "Tier0RouteMap", query, false)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ func dataSourceNsxtPolicyGroupRead(d *schema.ResourceData, m interface{}) error
domain := d.Get("domain").(string)
query := make(map[string]string)
query["parent_path"] = "*/" + domain
_, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "Group", query)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, getPolicyConnector(m), context, "Group", query)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_host_transport_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ func dataSourceNsxtPolicyHostTransportNode() *schema.Resource {
}

func dataSourceNsxtPolicyHostTransportNodeRead(d *schema.ResourceData, m interface{}) error {
obj, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "HostTransportNode", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
obj, err := policyDataSourceResourceRead(d, getPolicyConnector(m), context, "HostTransportNode", nil)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_host_transport_node_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ func dataSourceNsxtPolicyHostTransportNodeProfile() *schema.Resource {
}

func dataSourceNsxtPolicyHostTransportNodeProfileRead(d *schema.ResourceData, m interface{}) error {
_, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "PolicyHostTransportNodeProfile", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, getPolicyConnector(m), context, "PolicyHostTransportNodeProfile", nil)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_intrusion_service_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ func dataSourceNsxtPolicyIntrusionServiceProfileRead(d *schema.ResourceData, m i
return localManagerOnlyError()
}

_, err := policyDataSourceResourceRead(d, connector, getSessionContext(d, m), "IdsProfile", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, connector, context, "IdsProfile", nil)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_ip_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ func dataSourceNsxtPolicyIPBlock() *schema.Resource {

func dataSourceNsxtPolicyIPBlockRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)
client := infra.NewIpBlocksClient(getSessionContext(d, m), connector)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
client := infra.NewIpBlocksClient(context, connector)

objID := d.Get("id").(string)
objName := d.Get("display_name").(string)
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_ip_discovery_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func dataSourceNsxtPolicyIPDiscoveryProfile() *schema.Resource {
}

func dataSourceNsxtPolicyIPDiscoveryProfileRead(d *schema.ResourceData, m interface{}) error {
_, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "IPDiscoveryProfile", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, getPolicyConnector(m), context, "IPDiscoveryProfile", nil)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_ip_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ func dataSourceNsxtPolicyIPPool() *schema.Resource {
}

func dataSourceNsxtPolicyIPPoolRead(d *schema.ResourceData, m interface{}) error {
obj, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "IpAddressPool", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
obj, err := policyDataSourceResourceRead(d, getPolicyConnector(m), context, "IpAddressPool", nil)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_ipsec_vpn_local_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ func dataSourceNsxtPolicyIPSecVpnLocalEndpointRead(d *schema.ResourceData, m int
}
query["parent_path"] = fmt.Sprintf("%s*", servicePath)
}
objInt, err := policyDataSourceResourceReadWithValidation(d, connector, getSessionContext(d, m), "IPSecVpnLocalEndpoint", query, false)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
objInt, err := policyDataSourceResourceReadWithValidation(d, connector, context, "IPSecVpnLocalEndpoint", query, false)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_ipsec_vpn_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ func dataSourceNsxtPolicyIPSecVpnServiceRead(d *schema.ResourceData, m interface
if len(gwPath) > 0 {
query["parent_path"] = fmt.Sprintf("%s*", gwPath)
}
_, err := policyDataSourceResourceReadWithValidation(d, connector, getSessionContext(d, m), "IPSecVpnService", query, false)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceReadWithValidation(d, connector, context, "IPSecVpnService", query, false)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_ipv6_dad_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func dataSourceNsxtPolicyIpv6DadProfile() *schema.Resource {
}

func dataSourceNsxtPolicyIpv6DadProfileRead(d *schema.ResourceData, m interface{}) error {
_, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "Ipv6DadProfile", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, getPolicyConnector(m), context, "Ipv6DadProfile", nil)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_ipv6_ndra_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func dataSourceNsxtPolicyIpv6NdraProfile() *schema.Resource {
}

func dataSourceNsxtPolicyIpv6NdraProfileRead(d *schema.ResourceData, m interface{}) error {
_, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "Ipv6NdraProfile", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, getPolicyConnector(m), context, "Ipv6NdraProfile", nil)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_l2_vpn_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ func dataSourceNsxtPolicyL2VpnServiceRead(d *schema.ResourceData, m interface{})
if len(gwPath) > 0 {
query["parent_path"] = fmt.Sprintf("%s*", gwPath)
}
_, err := policyDataSourceResourceReadWithValidation(d, connector, getSessionContext(d, m), "L2VPNService", query, false)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceReadWithValidation(d, connector, context, "L2VPNService", query, false)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion nsxt/data_source_nsxt_policy_lb_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ func dataSourceNsxtPolicyLbService() *schema.Resource {
func dataSourceNsxtPolicyLbServiceRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)

_, err := policyDataSourceResourceRead(d, connector, getSessionContext(d, m), "LBService", nil)
context, err := getSessionContext(d, m)
if err != nil {
return err
}
_, err = policyDataSourceResourceRead(d, connector, context, "LBService", nil)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 8b24632

Please sign in to comment.