Skip to content

Commit

Permalink
Merge pull request #1197 from citrix/encoding-request-url
Browse files Browse the repository at this point in the history
handling request url encoding
  • Loading branch information
rohit-myali authored Sep 2, 2024
2 parents 9035072 + e518c92 commit 7b0c8d4
Show file tree
Hide file tree
Showing 29 changed files with 98 additions and 120 deletions.
11 changes: 3 additions & 8 deletions citrixadc/resource_citrixadc_aaapreauthenticationaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"fmt"
"log"
"net/url"
)

func resourceCitrixAdcAaapreauthenticationaction() *schema.Resource {
Expand Down Expand Up @@ -80,10 +79,9 @@ func readAaapreauthenticationactionFunc(d *schema.ResourceData, meta interface{}
log.Printf("[DEBUG] citrixadc-provider: In readAaapreauthenticationactionFunc")
client := meta.(*NetScalerNitroClient).client
aaapreauthenticationactionName := d.Id()
aaapreauthenticationactionName_pathescaped := url.PathEscape(aaapreauthenticationactionName)

log.Printf("[DEBUG] citrixadc-provider: Reading aaapreauthenticationaction state %s", aaapreauthenticationactionName)
data, err := client.FindResource(service.Aaapreauthenticationaction.Type(), aaapreauthenticationactionName_pathescaped)
data, err := client.FindResource(service.Aaapreauthenticationaction.Type(), aaapreauthenticationactionName)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing aaapreauthenticationaction state %s", aaapreauthenticationactionName)
d.SetId("")
Expand All @@ -105,8 +103,6 @@ func updateAaapreauthenticationactionFunc(d *schema.ResourceData, meta interface
client := meta.(*NetScalerNitroClient).client
aaapreauthenticationactionName := d.Get("name").(string)

aaapreauthenticationactionName_pathescaped := url.PathEscape(aaapreauthenticationactionName)

aaapreauthenticationaction := aaa.Aaapreauthenticationaction{
Name: d.Get("name").(string),
}
Expand All @@ -133,7 +129,7 @@ func updateAaapreauthenticationactionFunc(d *schema.ResourceData, meta interface
}

if hasChange {
_, err := client.UpdateResource(service.Aaapreauthenticationaction.Type(), aaapreauthenticationactionName_pathescaped, &aaapreauthenticationaction)
_, err := client.UpdateResource(service.Aaapreauthenticationaction.Type(), aaapreauthenticationactionName, &aaapreauthenticationaction)
if err != nil {
return fmt.Errorf("Error updating aaapreauthenticationaction %s", aaapreauthenticationactionName)
}
Expand All @@ -145,8 +141,7 @@ func deleteAaapreauthenticationactionFunc(d *schema.ResourceData, meta interface
log.Printf("[DEBUG] citrixadc-provider: In deleteAaapreauthenticationactionFunc")
client := meta.(*NetScalerNitroClient).client
aaapreauthenticationactionName := d.Id()
aaapreauthenticationactionName_pathescaped := url.PathEscape(aaapreauthenticationactionName)
err := client.DeleteResource(service.Aaapreauthenticationaction.Type(), aaapreauthenticationactionName_pathescaped)
err := client.DeleteResource(service.Aaapreauthenticationaction.Type(), aaapreauthenticationactionName)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions citrixadc/resource_citrixadc_appfwhtmlerrorpage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const testAccAppfwhtmlerrorpage_basic = `
`

func TestAccAppfwhtmlerrorpage_basic(t *testing.T) {
t.Skip("TODO: Need to find a way to test this resource!")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down
7 changes: 2 additions & 5 deletions citrixadc/resource_citrixadc_appfwjsoncontenttype.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"

"log"
"net/url"
)

func resourceCitrixAdcAppfwjsoncontenttype() *schema.Resource {
Expand Down Expand Up @@ -62,9 +61,8 @@ func readAppfwjsoncontenttypeFunc(d *schema.ResourceData, meta interface{}) erro
log.Printf("[DEBUG] citrixadc-provider: In readAppfwjsoncontenttypeFunc")
client := meta.(*NetScalerNitroClient).client
appfwjsoncontenttypeName := d.Id()
appfwjsoncontenttypeNameEscaped := url.PathEscape(url.QueryEscape(appfwjsoncontenttypeName))
log.Printf("[DEBUG] citrixadc-provider: Reading appfwjsoncontenttype state %s", appfwjsoncontenttypeName)
data, err := client.FindResource(service.Appfwjsoncontenttype.Type(), appfwjsoncontenttypeNameEscaped)
data, err := client.FindResource(service.Appfwjsoncontenttype.Type(), appfwjsoncontenttypeName)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing appfwjsoncontenttype state %s", appfwjsoncontenttypeName)
d.SetId("")
Expand All @@ -81,8 +79,7 @@ func deleteAppfwjsoncontenttypeFunc(d *schema.ResourceData, meta interface{}) er
log.Printf("[DEBUG] citrixadc-provider: In deleteAppfwjsoncontenttypeFunc")
client := meta.(*NetScalerNitroClient).client
appfwjsoncontenttypeName := d.Id()
appfwjsoncontenttypeNameEscaped := url.PathEscape(url.QueryEscape(appfwjsoncontenttypeName))
err := client.DeleteResource(service.Appfwjsoncontenttype.Type(), appfwjsoncontenttypeNameEscaped)
err := client.DeleteResource(service.Appfwjsoncontenttype.Type(), appfwjsoncontenttypeName)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions citrixadc/resource_citrixadc_appfwjsonerrorpage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const testAccAppfwjsonerrorpage_basic = `
`

func TestAccAppfwjsonerrorpage_basic(t *testing.T) {
t.Skip("TODO: Need to find a way to test this resource!")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down
9 changes: 3 additions & 6 deletions citrixadc/resource_citrixadc_appfwmultipartformcontenttype.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"

"log"
"net/url"
)

func resourceCitrixAdcAppfwmultipartformcontenttype() *schema.Resource {
Expand Down Expand Up @@ -63,10 +62,9 @@ func readAppfwmultipartformcontenttypeFunc(d *schema.ResourceData, meta interfac
client := meta.(*NetScalerNitroClient).client
appfwmultipartformcontenttypeName := d.Id()
log.Printf("[DEBUG] citrixadc-provider: Reading appfwmultipartformcontenttype state %s", appfwmultipartformcontenttypeName)
appfwmultipartformcontenttypeNameEscaped := url.PathEscape(url.QueryEscape(appfwmultipartformcontenttypeName))
data, err := client.FindResource("appfwmultipartformcontenttype", appfwmultipartformcontenttypeNameEscaped)
data, err := client.FindResource("appfwmultipartformcontenttype", appfwmultipartformcontenttypeName)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing appfwmultipartformcontenttype state %s", appfwmultipartformcontenttypeNameEscaped)
log.Printf("[WARN] citrixadc-provider: Clearing appfwmultipartformcontenttype state %s", appfwmultipartformcontenttypeName)
d.SetId("")
return nil
}
Expand All @@ -81,8 +79,7 @@ func deleteAppfwmultipartformcontenttypeFunc(d *schema.ResourceData, meta interf
log.Printf("[DEBUG] citrixadc-provider: In deleteAppfwmultipartformcontenttypeFunc")
client := meta.(*NetScalerNitroClient).client
appfwmultipartformcontenttypeName := d.Id()
appfwmultipartformcontenttypeNameEscaped := url.PathEscape(url.QueryEscape(appfwmultipartformcontenttypeName))
err := client.DeleteResource("appfwmultipartformcontenttype", appfwmultipartformcontenttypeNameEscaped)
err := client.DeleteResource("appfwmultipartformcontenttype", appfwmultipartformcontenttypeName)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"net/url"
"testing"
)

Expand Down Expand Up @@ -68,8 +67,8 @@ func testAccCheckAppfwmultipartformcontenttypeExist(n string, id *string) resour
}

nsClient := testAccProvider.Meta().(*NetScalerNitroClient).client
appfwmultipartformcontenttypeNameEscaped := url.PathEscape(url.QueryEscape(rs.Primary.ID))
data, err := nsClient.FindResource("appfwmultipartformcontenttype", appfwmultipartformcontenttypeNameEscaped)
appfwmultipartformcontenttypeName := rs.Primary.ID
data, err := nsClient.FindResource("appfwmultipartformcontenttype", appfwmultipartformcontenttypeName)

if err != nil {
return err
Expand All @@ -95,8 +94,8 @@ func testAccCheckAppfwmultipartformcontenttypeDestroy(s *terraform.State) error
return fmt.Errorf("No name is set")
}

appfwmultipartformcontenttypeNameEscaped := url.PathEscape(url.QueryEscape(rs.Primary.ID))
_, err := nsClient.FindResource("appfwmultipartformcontenttype", appfwmultipartformcontenttypeNameEscaped)
appfwmultipartformcontenttypeName := rs.Primary.ID
_, err := nsClient.FindResource("appfwmultipartformcontenttype", appfwmultipartformcontenttypeName)

if err == nil {
return fmt.Errorf("appfwmultipartformcontenttype %s still exists", rs.Primary.ID)
Expand Down
1 change: 1 addition & 0 deletions citrixadc/resource_citrixadc_appfwsignatures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const testAccAppfwsignatures_basic = `
`

func TestAccAppfwsignatures_basic(t *testing.T) {
t.Skip("TODO: Need to find a way to test this resource!")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down
7 changes: 2 additions & 5 deletions citrixadc/resource_citrixadc_appfwxmlcontenttype.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"

"log"
"net/url"
)

func resourceCitrixAdcAppfwxmlcontenttype() *schema.Resource {
Expand Down Expand Up @@ -62,9 +61,8 @@ func readAppfwxmlcontenttypeFunc(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] citrixadc-provider: In readAppfwxmlcontenttypeFunc")
client := meta.(*NetScalerNitroClient).client
appfwxmlcontenttypeName := d.Id()
appfwxmlcontenttypeNameEscaped := url.PathEscape(url.QueryEscape(appfwxmlcontenttypeName))
log.Printf("[DEBUG] citrixadc-provider: Reading appfwxmlcontenttype state %s", appfwxmlcontenttypeName)
data, err := client.FindResource(service.Appfwxmlcontenttype.Type(), appfwxmlcontenttypeNameEscaped)
data, err := client.FindResource(service.Appfwxmlcontenttype.Type(), appfwxmlcontenttypeName)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing appfwxmlcontenttype state %s", appfwxmlcontenttypeName)
d.SetId("")
Expand All @@ -81,8 +79,7 @@ func deleteAppfwxmlcontenttypeFunc(d *schema.ResourceData, meta interface{}) err
log.Printf("[DEBUG] citrixadc-provider: In deleteAppfwxmlcontenttypeFunc")
client := meta.(*NetScalerNitroClient).client
appfwxmlcontenttypeName := d.Id()
appfwxmlcontenttypeNameEscaped := url.PathEscape(url.QueryEscape(appfwxmlcontenttypeName))
err := client.DeleteResource(service.Appfwxmlcontenttype.Type(), appfwxmlcontenttypeNameEscaped)
err := client.DeleteResource(service.Appfwxmlcontenttype.Type(), appfwxmlcontenttypeName)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions citrixadc/resource_citrixadc_appfwxmlschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const testAccAppfwxmlschema_basic = `
`

func TestAccAppfwxmlschema_basic(t *testing.T) {
t.Skip("TODO: Need to find a way to test this resource!")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down
11 changes: 3 additions & 8 deletions citrixadc/resource_citrixadc_auditsyslogpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ func readAuditsyslogpolicyFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In readAuditsyslogpolicyFunc")
client := meta.(*NetScalerNitroClient).client
auditsyslogpolicyName := d.Id()
auditsyslogpolicyNameEscaped := url.QueryEscape(auditsyslogpolicyName)
log.Printf("[DEBUG] citrixadc-provider: Reading auditsyslogpolicy state %s", auditsyslogpolicyName)
data, err := client.FindResource(service.Auditsyslogpolicy.Type(), auditsyslogpolicyNameEscaped)
data, err := client.FindResource(service.Auditsyslogpolicy.Type(), auditsyslogpolicyName)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing auditsyslogpolicy state %s", auditsyslogpolicyName)
d.SetId("")
Expand Down Expand Up @@ -176,10 +175,8 @@ func updateAuditsyslogpolicyFunc(d *schema.ResourceData, meta interface{}) error
hasChange = true
}

auditsyslogpolicyNameEscaped := url.QueryEscape(auditsyslogpolicyName)

if hasChange {
_, err := client.UpdateResource(service.Auditsyslogpolicy.Type(), auditsyslogpolicyNameEscaped, &auditsyslogpolicy)
_, err := client.UpdateResource(service.Auditsyslogpolicy.Type(), auditsyslogpolicyName, &auditsyslogpolicy)
if err != nil {
return fmt.Errorf("Error updating auditsyslogpolicy %s: %s", auditsyslogpolicyName, err.Error())
}
Expand All @@ -197,8 +194,6 @@ func deleteAuditsyslogpolicyFunc(d *schema.ResourceData, meta interface{}) error
client := meta.(*NetScalerNitroClient).client
auditsyslogpolicyName := d.Id()

auditsyslogpolicyNameEscaped := url.QueryEscape(auditsyslogpolicyName)

// Unbind from global if appropriate
if v, ok := d.GetOk("globalbinding"); ok {
// There is only one element
Expand All @@ -209,7 +204,7 @@ func deleteAuditsyslogpolicyFunc(d *schema.ResourceData, meta interface{}) error
}
}

err := client.DeleteResource(service.Auditsyslogpolicy.Type(), auditsyslogpolicyNameEscaped)
err := client.DeleteResource(service.Auditsyslogpolicy.Type(), auditsyslogpolicyName)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions citrixadc/resource_citrixadc_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"fmt"
"log"
"net/url"
)

func resourceCitrixAdcChannel() *schema.Resource {
Expand Down Expand Up @@ -175,7 +174,7 @@ func readChannelFunc(d *schema.ResourceData, meta interface{}) error {
client := meta.(*NetScalerNitroClient).client
channelName := d.Id()
log.Printf("[DEBUG] citrixadc-provider: Reading channel state %s", channelName)
data, err := client.FindResource(service.Channel.Type(), url.QueryEscape(url.QueryEscape(channelName)))
data, err := client.FindResource(service.Channel.Type(), channelName)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing channel state %s", channelName)
d.SetId("")
Expand Down Expand Up @@ -326,7 +325,7 @@ func deleteChannelFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In deleteChannelFunc")
client := meta.(*NetScalerNitroClient).client
channelName := d.Id()
err := client.DeleteResource(service.Channel.Type(), url.QueryEscape(url.QueryEscape(channelName)))
err := client.DeleteResource(service.Channel.Type(), channelName)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions citrixadc/resource_citrixadc_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/citrix/adc-nitro-go/service"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"net/url"
"testing"
)

Expand Down Expand Up @@ -91,7 +90,7 @@ func testAccCheckChannelExist(n string, id *string) resource.TestCheckFunc {
}

nsClient := testAccProvider.Meta().(*NetScalerNitroClient).client
data, err := nsClient.FindResource(service.Channel.Type(), url.QueryEscape(url.QueryEscape(rs.Primary.ID)))
data, err := nsClient.FindResource(service.Channel.Type(), rs.Primary.ID)

if err != nil {
return err
Expand All @@ -117,7 +116,7 @@ func testAccCheckChannelDestroy(s *terraform.State) error {
return fmt.Errorf("No name is set")
}

_, err := nsClient.FindResource(service.Channel.Type(), url.QueryEscape(url.QueryEscape(rs.Primary.ID)))
_, err := nsClient.FindResource(service.Channel.Type(), rs.Primary.ID)
if err == nil {
return fmt.Errorf("channel %s still exists", rs.Primary.ID)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ const testAccGslbservicegroup_gslbservicegroupmember_binding_basic = `
siteipaddress = "172.31.96.234"
sessionexchange = "DISABLED"
}
resource "citrixadc_server" "tf_server" {
name = "tf_server"
ipaddress = "192.168.11.13"
}
resource "citrixadc_gslbservicegroup_gslbservicegroupmember_binding" "tf_binding" {
servicegroupname = citrixadc_gslbservicegroup.tf_gslbservicegroup.servicegroupname
servername = "10.10.10.10"
servername = citrixadc_server.tf_server.name
port = 60
}
Expand All @@ -65,6 +69,10 @@ const testAccGslbservicegroup_gslbservicegroupmember_binding_basic_step2 = `
siteipaddress = "172.31.96.234"
sessionexchange = "DISABLED"
}
resource "citrixadc_server" "tf_server" {
name = "tf_server"
ipaddress = "192.168.11.13"
}
`

func TestAccGslbservicegroup_gslbservicegroupmember_binding_basic(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const testAccHanode_routemonitor6_binding_basic_step2 = `
`

func TestAccHanode_routemonitor6_binding_basic(t *testing.T) {
t.Skip("TODO: Need to find a way to test this resource!")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down
16 changes: 4 additions & 12 deletions citrixadc/resource_citrixadc_linkset.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ func readLinksetFunc(d *schema.ResourceData, meta interface{}) error {
client := meta.(*NetScalerNitroClient).client
linksetName := d.Id()
log.Printf("[DEBUG] citrixadc-provider: Reading linkset state %s", linksetName)
// double encode value part as it contains `/`
//linksetNameEscaped := url.QueryEscape(url.QueryEscape(linksetName))
linksetNameEscaped := url.PathEscape(url.QueryEscape(linksetName))
data, err := client.FindResource(service.Linkset.Type(), linksetNameEscaped)
data, err := client.FindResource(service.Linkset.Type(), linksetName)

err = readLinksetInterfaceBindings(d, meta)
if err != nil {
Expand All @@ -89,9 +86,7 @@ func deleteLinksetFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In deleteLinksetFunc")
client := meta.(*NetScalerNitroClient).client
linksetName := d.Id()
// double encode value part as it contains `/`
linksetNameEscaped := url.QueryEscape(url.QueryEscape(linksetName))
err := client.DeleteResource(service.Linkset.Type(), linksetNameEscaped)
err := client.DeleteResource(service.Linkset.Type(), linksetName)
if err != nil {
return err
}
Expand All @@ -114,9 +109,8 @@ func deleteSingleLinksetInterfaceBinding(d *schema.ResourceData, meta interface{
args = append(args, s)

log.Printf("args is %v", args)
linksetNameEscaped := url.QueryEscape(url.QueryEscape(linksetName))

if err := client.DeleteResourceWithArgs(service.Linkset_interface_binding.Type(), linksetNameEscaped, args); err != nil {
if err := client.DeleteResourceWithArgs(service.Linkset_interface_binding.Type(), linksetName, args); err != nil {
log.Printf("[DEBUG] citrixadc-provider: Error deleting interface binding %v\n", ifnum)
return err
}
Expand Down Expand Up @@ -164,10 +158,8 @@ func readLinksetInterfaceBindings(d *schema.ResourceData, meta interface{}) erro
log.Printf("[DEBUG] citrixadc-provider: In readLinksetInterfaceBindings")
client := meta.(*NetScalerNitroClient).client
linksetName := d.Get("linkset_id").(string)
// double encode value part as it contains `/`
linksetNameEscaped := url.QueryEscape(url.QueryEscape(linksetName))

bindings, _ := client.FindResourceArray(service.Linkset_interface_binding.Type(), linksetNameEscaped)
bindings, _ := client.FindResourceArray(service.Linkset_interface_binding.Type(), linksetName)
log.Printf("bindings %v\n", bindings)

processedBindings := make([]interface{}, len(bindings))
Expand Down
2 changes: 1 addition & 1 deletion citrixadc/resource_citrixadc_linkset_channel_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func deleteLinkset_channel_bindingFunc(d *schema.ResourceData, meta interface{})
args := make([]string, 0)
args = append(args, fmt.Sprintf("ifnum:%v", url.QueryEscape(ifnum)))

err := client.DeleteResourceWithArgs(service.Linkset_channel_binding.Type(), url.QueryEscape(url.QueryEscape(name)), args)
err := client.DeleteResourceWithArgs(service.Linkset_channel_binding.Type(), name, args)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func testAccCheckLinkset_channel_bindingDestroy(s *terraform.State) error {
return fmt.Errorf("No name is set")
}

_, err := nsClient.FindResource(service.Linkset_channel_binding.Type(), url.QueryEscape(url.QueryEscape(rs.Primary.ID)))
_, err := nsClient.FindResource(service.Linkset_channel_binding.Type(), rs.Primary.ID)
if err == nil {
return fmt.Errorf("linkset_channel_binding %s still exists", rs.Primary.ID)
}
Expand Down
Loading

0 comments on commit 7b0c8d4

Please sign in to comment.