Skip to content

Commit

Permalink
Merge pull request #172 from citrix/go-nitro-migrate
Browse files Browse the repository at this point in the history
Go nitro migrate
  • Loading branch information
George Nikolopoulos authored Jul 6, 2021
2 parents c9a0d06 + f4be7ed commit c669c9b
Show file tree
Hide file tree
Showing 2,065 changed files with 60,119 additions and 13,557 deletions.
16 changes: 8 additions & 8 deletions citrixadc/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"strings"
"testing"

"github.com/chiradeep/go-nitro/config/system"
"github.com/chiradeep/go-nitro/netscaler"
"github.com/citrix/adc-nitro-go/resource/config/system"
"github.com/citrix/adc-nitro-go/service"
)

func uploadTestdataFile(c *NetScalerNitroClient, t *testing.T, filename, targetDir string) error {
Expand All @@ -33,14 +33,14 @@ func uploadTestdataFile(c *NetScalerNitroClient, t *testing.T, filename, targetD
Filecontent: base64.StdEncoding.EncodeToString(b),
Filelocation: targetDir,
}
_, err = nsClient.AddResource(netscaler.Systemfile.Type(), filename, &sf)
_, err = nsClient.AddResource(service.Systemfile.Type(), filename, &sf)
if err != nil && strings.Contains(err.Error(), "File already exists") {
url_args := map[string]string{"filelocation": strings.Replace(targetDir, "/", "%2F", -1)}
err := nsClient.DeleteResourceWithArgsMap(netscaler.Systemfile.Type(), filename, url_args)
err := nsClient.DeleteResourceWithArgsMap(service.Systemfile.Type(), filename, url_args)
if err != nil {
return err
}
_, err = nsClient.AddResource(netscaler.Systemfile.Type(), filename, &sf)
_, err = nsClient.AddResource(service.Systemfile.Type(), filename, &sf)
if err != nil {
return err
}
Expand Down Expand Up @@ -80,14 +80,14 @@ func testHelperInstantiateClient(nsUrl, username, password string, sslVerify boo
Endpoint: nsUrl,
}

params := netscaler.NitroParams{
params := service.NitroParams{
Url: nsUrl,
Username: username,
Password: password,
//ProxiedNs: d.Get("proxied_ns").(string),
SslVerify: sslVerify,
}
client, err := netscaler.NewNitroClientFromParams(params)
client, err := service.NewNitroClientFromParams(params)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func testIsTargetAdcCluster() bool {
}
nsClient := c.client

datalist, err := nsClient.FindAllResources(netscaler.Clusterinstance.Type())
datalist, err := nsClient.FindAllResources(service.Clusterinstance.Type())
if err != nil {
//lintignore:R009
panic(err)
Expand Down
8 changes: 4 additions & 4 deletions citrixadc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"log"
"sync"

"github.com/chiradeep/go-nitro/netscaler"
"github.com/citrix/adc-nitro-go/service"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform/version"
Expand All @@ -29,7 +29,7 @@ type NetScalerNitroClient struct {
Username string
Password string
Endpoint string
client *netscaler.NitroClient
client *service.NitroClient
lock sync.Mutex
}

Expand Down Expand Up @@ -203,15 +203,15 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
Endpoint: d.Get("endpoint").(string),
}

params := netscaler.NitroParams{
params := service.NitroParams{
Url: d.Get("endpoint").(string),
Username: d.Get("username").(string),
Password: d.Get("password").(string),
ProxiedNs: d.Get("proxied_ns").(string),
SslVerify: !d.Get("insecure_skip_verify").(bool),
Headers: userHeaders,
}
client, err := netscaler.NewNitroClientFromParams(params)
client, err := service.NewNitroClientFromParams(params)
if err != nil {
return nil, err
}
Expand Down
7 changes: 7 additions & 0 deletions citrixadc/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var testAccProvider *schema.Provider

var isCpxRun bool
var isCluster bool
var adcTestbed string

func init() {
log.Printf("[DEBUG] citrixadc-provider-test: In init")
Expand All @@ -27,6 +28,12 @@ func init() {
isCpxRun = strings.Contains(nsUrl, "localhost")

isCluster = testIsTargetAdcCluster()

var exists bool
adcTestbed, exists = os.LookupEnv("ADC_TESTBED")
if !exists {
adcTestbed = "UNSPECIFIED"
}
}

func TestProvider(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions citrixadc/resource_citrixadc_appfwfieldtype.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package citrixadc

import (
"github.com/chiradeep/go-nitro/config/appfw"
"github.com/citrix/adc-nitro-go/resource/config/appfw"

"github.com/chiradeep/go-nitro/netscaler"
"github.com/citrix/adc-nitro-go/service"
"github.com/hashicorp/terraform/helper/schema"

"fmt"
Expand Down Expand Up @@ -59,7 +59,7 @@ func createAppfwfieldtypeFunc(d *schema.ResourceData, meta interface{}) error {
Regex: d.Get("regex").(string),
}

_, err := client.AddResource(netscaler.Appfwfieldtype.Type(), appfwfieldtypeName, &appfwfieldtype)
_, err := client.AddResource(service.Appfwfieldtype.Type(), appfwfieldtypeName, &appfwfieldtype)
if err != nil {
return err
}
Expand All @@ -79,7 +79,7 @@ func readAppfwfieldtypeFunc(d *schema.ResourceData, meta interface{}) error {
client := meta.(*NetScalerNitroClient).client
appfwfieldtypeName := d.Id()
log.Printf("[DEBUG] citrixadc-provider: Reading appfwfieldtype state %s", appfwfieldtypeName)
data, err := client.FindResource(netscaler.Appfwfieldtype.Type(), appfwfieldtypeName)
data, err := client.FindResource(service.Appfwfieldtype.Type(), appfwfieldtypeName)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing appfwfieldtype state %s", appfwfieldtypeName)
d.SetId("")
Expand Down Expand Up @@ -133,7 +133,7 @@ func updateAppfwfieldtypeFunc(d *schema.ResourceData, meta interface{}) error {
// }

if hasChange {
_, err := client.UpdateResource(netscaler.Appfwfieldtype.Type(), appfwfieldtypeName, &appfwfieldtype)
_, err := client.UpdateResource(service.Appfwfieldtype.Type(), appfwfieldtypeName, &appfwfieldtype)
if err != nil {
return fmt.Errorf("Error updating appfwfieldtype %s", appfwfieldtypeName)
}
Expand All @@ -145,7 +145,7 @@ func deleteAppfwfieldtypeFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In deleteAppfwfieldtypeFunc")
client := meta.(*NetScalerNitroClient).client
appfwfieldtypeName := d.Id()
err := client.DeleteResource(netscaler.Appfwfieldtype.Type(), appfwfieldtypeName)
err := client.DeleteResource(service.Appfwfieldtype.Type(), appfwfieldtypeName)
if err != nil {
return err
}
Expand Down
12 changes: 8 additions & 4 deletions citrixadc/resource_citrixadc_appfwfieldtype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ package citrixadc

import (
"fmt"
"github.com/chiradeep/go-nitro/netscaler"
"testing"

"github.com/citrix/adc-nitro-go/service"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"testing"
)

const testAccAppfwfieldtype_add = `
Expand All @@ -39,6 +40,9 @@ resource "citrixadc_appfwfieldtype" "tfAcc_appfwfieldtype" {
`

func TestAccAppfwfieldtype_basic(t *testing.T) {
if adcTestbed != "STANDALONE" {
t.Skipf("ADC testbed is %s. Expected STANDALONE.", adcTestbed)
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down Expand Up @@ -84,7 +88,7 @@ func testAccCheckAppfwfieldtypeExist(n string, id *string) resource.TestCheckFun
}

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

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

_, err := nsClient.FindResource(netscaler.Appfwfieldtype.Type(), rs.Primary.ID)
_, err := nsClient.FindResource(service.Appfwfieldtype.Type(), rs.Primary.ID)
if err == nil {
return fmt.Errorf("LB vserver %s still exists", rs.Primary.ID)
}
Expand Down
10 changes: 5 additions & 5 deletions citrixadc/resource_citrixadc_appfwjsoncontenttype.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package citrixadc

import (
"github.com/chiradeep/go-nitro/config/appfw"
"github.com/citrix/adc-nitro-go/resource/config/appfw"
"github.com/citrix/adc-nitro-go/service"

"github.com/chiradeep/go-nitro/netscaler"
"github.com/hashicorp/terraform/helper/schema"

"log"
Expand Down Expand Up @@ -39,7 +39,7 @@ func createAppfwjsoncontenttypeFunc(d *schema.ResourceData, meta interface{}) er
Jsoncontenttypevalue: appfwjsoncontenttypeName,
}

_, err := client.AddResource(netscaler.Appfwjsoncontenttype.Type(), appfwjsoncontenttypeName, &appfwjsoncontenttype)
_, err := client.AddResource(service.Appfwjsoncontenttype.Type(), appfwjsoncontenttypeName, &appfwjsoncontenttype)
if err != nil {
return err
}
Expand All @@ -59,7 +59,7 @@ func readAppfwjsoncontenttypeFunc(d *schema.ResourceData, meta interface{}) erro
client := meta.(*NetScalerNitroClient).client
appfwjsoncontenttypeName := d.Id()
log.Printf("[DEBUG] citrixadc-provider: Reading appfwjsoncontenttype state %s", appfwjsoncontenttypeName)
data, err := client.FindResource(netscaler.Appfwjsoncontenttype.Type(), appfwjsoncontenttypeName)
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 @@ -76,7 +76,7 @@ func deleteAppfwjsoncontenttypeFunc(d *schema.ResourceData, meta interface{}) er
log.Printf("[DEBUG] citrixadc-provider: In deleteAppfwjsoncontenttypeFunc")
client := meta.(*NetScalerNitroClient).client
appfwjsoncontenttypeName := d.Id()
err := client.DeleteResource(netscaler.Appfwjsoncontenttype.Type(), appfwjsoncontenttypeName)
err := client.DeleteResource(service.Appfwjsoncontenttype.Type(), appfwjsoncontenttypeName)
if err != nil {
return err
}
Expand Down
12 changes: 8 additions & 4 deletions citrixadc/resource_citrixadc_appfwjsoncontenttype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ package citrixadc

import (
"fmt"
"github.com/chiradeep/go-nitro/netscaler"
"testing"

"github.com/citrix/adc-nitro-go/service"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"testing"
)

const testAccAppfwjsoncontenttype_basic = `
Expand All @@ -33,6 +34,9 @@ const testAccAppfwjsoncontenttype_basic = `
`

func TestAccAppfwjsoncontenttype_basic(t *testing.T) {
if adcTestbed != "STANDALONE" {
t.Skipf("ADC testbed is %s. Expected STANDALONE.", adcTestbed)
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down Expand Up @@ -69,7 +73,7 @@ func testAccCheckAppfwjsoncontenttypeExist(n string, id *string) resource.TestCh
}

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

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

_, err := nsClient.FindResource(netscaler.Appfwjsoncontenttype.Type(), rs.Primary.ID)
_, err := nsClient.FindResource(service.Appfwjsoncontenttype.Type(), rs.Primary.ID)
if err == nil {
return fmt.Errorf("LB vserver %s still exists", rs.Primary.ID)
}
Expand Down
12 changes: 6 additions & 6 deletions citrixadc/resource_citrixadc_appfwpolicy.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package citrixadc

import (
"github.com/chiradeep/go-nitro/config/appfw"
"github.com/citrix/adc-nitro-go/resource/config/appfw"
"github.com/citrix/adc-nitro-go/service"

"github.com/chiradeep/go-nitro/netscaler"
"github.com/hashicorp/terraform/helper/schema"

"fmt"
Expand Down Expand Up @@ -66,7 +66,7 @@ func createAppfwpolicyFunc(d *schema.ResourceData, meta interface{}) error {
Rule: d.Get("rule").(string),
}

_, err := client.AddResource(netscaler.Appfwpolicy.Type(), appfwpolicyName, &appfwpolicy)
_, err := client.AddResource(service.Appfwpolicy.Type(), appfwpolicyName, &appfwpolicy)
if err != nil {
return err
}
Expand All @@ -86,7 +86,7 @@ func readAppfwpolicyFunc(d *schema.ResourceData, meta interface{}) error {
client := meta.(*NetScalerNitroClient).client
appfwpolicyName := d.Id()
log.Printf("[DEBUG] citrixadc-provider: Reading appfwpolicy state %s", appfwpolicyName)
data, err := client.FindResource(netscaler.Appfwpolicy.Type(), appfwpolicyName)
data, err := client.FindResource(service.Appfwpolicy.Type(), appfwpolicyName)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing appfwpolicy state %s", appfwpolicyName)
d.SetId("")
Expand Down Expand Up @@ -145,7 +145,7 @@ func updateAppfwpolicyFunc(d *schema.ResourceData, meta interface{}) error {
}

if hasChange {
_, err := client.UpdateResource(netscaler.Appfwpolicy.Type(), appfwpolicyName, &appfwpolicy)
_, err := client.UpdateResource(service.Appfwpolicy.Type(), appfwpolicyName, &appfwpolicy)
if err != nil {
return fmt.Errorf("Error updating appfwpolicy %s", appfwpolicyName)
}
Expand All @@ -157,7 +157,7 @@ func deleteAppfwpolicyFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In deleteAppfwpolicyFunc")
client := meta.(*NetScalerNitroClient).client
appfwpolicyName := d.Id()
err := client.DeleteResource(netscaler.Appfwpolicy.Type(), appfwpolicyName)
err := client.DeleteResource(service.Appfwpolicy.Type(), appfwpolicyName)
if err != nil {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions citrixadc/resource_citrixadc_appfwpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"
"testing"

"github.com/chiradeep/go-nitro/netscaler"
"github.com/citrix/adc-nitro-go/service"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
Expand Down Expand Up @@ -105,6 +105,9 @@ const testAccAppfwpolicy_update = `
`

func TestAccAppfwpolicy_basic(t *testing.T) {
if adcTestbed != "STANDALONE" {
t.Skipf("ADC testbed is %s. Expected STANDALONE.", adcTestbed)
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down Expand Up @@ -153,7 +156,7 @@ func testAccCheckAppfwpolicyExist(n string, id *string) resource.TestCheckFunc {
}

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

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

_, err := nsClient.FindResource(netscaler.Appfwpolicy.Type(), rs.Primary.ID)
_, err := nsClient.FindResource(service.Appfwpolicy.Type(), rs.Primary.ID)
if err == nil {
return fmt.Errorf("LB vserver %s still exists", rs.Primary.ID)
}
Expand Down
Loading

0 comments on commit c669c9b

Please sign in to comment.