Skip to content

Commit

Permalink
microseg sdk pointing to internals
Browse files Browse the repository at this point in the history
  • Loading branch information
abhimutant committed Mar 12, 2024
1 parent 81fc1c6 commit 2fccf60
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 71 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ require (
github.com/hashicorp/go-uuid v1.0.2
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/mitchellh/gox v1.0.1
github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16 v16.9.0-4944 // indirect
github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16 v16.9.0-4914 // indirect
github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4 v4.0.1-alpha.1 // indirect
// github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4 v4.0.1-alpha.1 // indirect
github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4 v4.0.1-beta.1 // indirect
// github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.3-alpha.2 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96d
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758=
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16 v16.9.0-4944 h1:NGBOf7hUy0nsQgPSCes8sArsGUF1EAm3Po3wV77p3zg=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16 v16.9.0-4944/go.mod h1:1SI3/z0o6uKsLVEDy1qHutEhaSnjnA89ppjas0RwEMI=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/networking-go-client/v16 v16.8.0-3635 h1:eVNonw1w8i0lVNNK4Ep/P8fAb2j6EEe+VNXAQXPLThc=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/networking-go-client/v16 v16.8.0-3635/go.mod h1:vHyQVF3IKxmip+xGxXDQznKk1ffrVa4HSiEEueiekaE=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16 v16.9.0-4914 h1:xl9+7uyYFvhFRkNdgzn5mWsrNjoRd0ookC4n/x42GH0=
Expand Down
4 changes: 2 additions & 2 deletions nutanix/sdks/v4/microseg/microseg.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package microseg

import (
"github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4/api"
microseg "github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4/client"
"github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16/api"
microseg "github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16/client"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/client"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
import1 "github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4/models/microseg/v4/config"
import1 "github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16/models/microseg/v4/config"
conns "github.com/terraform-providers/terraform-provider-nutanix/nutanix"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
)
Expand Down Expand Up @@ -79,7 +79,7 @@ func DatasourceNutanixAddressGroupV4Read(ctx context.Context, d *schema.Resource
conn := meta.(*conns.Client).MicroSegAPI

extID := d.Get("ext_id")
resp, err := conn.AddressGroupAPIInstance.GetAddressGroupByExtId(utils.StringPtr(extID.(string)))
resp, err := conn.AddressGroupAPIInstance.GetAddressGroupById(utils.StringPtr(extID.(string)))
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
import1 "github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4/models/microseg/v4/config"
import1 "github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16/models/microseg/v4/config"
conns "github.com/terraform-providers/terraform-provider-nutanix/nutanix"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
)
Expand Down Expand Up @@ -109,7 +109,7 @@ func DatasourceNutanixAddressGroupsV4Read(ctx context.Context, d *schema.Resourc
conn := meta.(*conns.Client).MicroSegAPI

// initialize query params
var filter, orderBy *string
var filter, orderBy, selects *string
var page, limit *int

if pagef, ok := d.GetOk("page"); ok {
Expand All @@ -132,13 +132,13 @@ func DatasourceNutanixAddressGroupsV4Read(ctx context.Context, d *schema.Resourc
} else {
orderBy = nil
}
// if selectf, ok := d.GetOk("select"); ok {
// selects = utils.StringPtr(selectf.(string))
// } else {
// selects = nil
// }
if selectf, ok := d.GetOk("select"); ok {
selects = utils.StringPtr(selectf.(string))
} else {
selects = nil
}

resp, err := conn.AddressGroupAPIInstance.ListAddressGroups(page, limit, filter, orderBy)
resp, err := conn.AddressGroupAPIInstance.ListAddressGroups(page, limit, filter, orderBy, selects)
fmt.Println("HEELLLLLLLLL")
if err != nil {
fmt.Println(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
import1 "github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4/models/microseg/v4/config"
import1 "github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16/models/microseg/v4/config"
conns "github.com/terraform-providers/terraform-provider-nutanix/nutanix"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
)
Expand Down Expand Up @@ -341,7 +341,7 @@ func DataSourceNutanixNetworkSecurityPoliciesV4Read(ctx context.Context, d *sche
selects = nil
}

resp, err := conn.NetworkingSecurityInstance.GetNetworkSecurityPolicyList(page, limit, filter, orderBy, selects)
resp, err := conn.NetworkingSecurityInstance.ListNetworkSecurityPolicies(page, limit, filter, orderBy, selects)
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
config "github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4/models/common/v1/config"
import1 "github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4/models/microseg/v4/config"
config "github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16/models/common/v1/config"
import1 "github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16/models/microseg/v4/config"
conns "github.com/terraform-providers/terraform-provider-nutanix/nutanix"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
)
Expand Down Expand Up @@ -285,7 +285,7 @@ func DataSourceNutanixNetworkSecurityPolicyV4Read(ctx context.Context, d *schema

extID := d.Get("ext_id")

resp, err := conn.NetworkingSecurityInstance.GetNetworkSecurityPolicyByExtId(utils.StringPtr((extID.(string))))
resp, err := conn.NetworkingSecurityInstance.GetNetworkSecurityPolicyById(utils.StringPtr((extID.(string))))
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down Expand Up @@ -386,20 +386,20 @@ func flattenOneOfNetworkSecurityPolicyRuleSpec(pr *import1.OneOfNetworkSecurityP
getVal := pr.ObjectType_

if utils.StringValue(getVal) == "microseg.v4.r0.b1.config.TwoEnvIsolationRuleSpec" {
twoIsolationRule := pr.GetValue().(import1.NSPTwoEnvIsolationRuleSpec)
twoIsolationRule := pr.GetValue().(import1.TwoEnvIsolationRuleSpec)
assc["first_isolation_group"] = twoIsolationRule.FirstIsolationGroup
assc["second_isolation_group"] = twoIsolationRule.SecondIsolationGroup
} else if utils.StringValue(getVal) == "microseg.v4.r0.b1.config.ApplicationRuleSpec" {
appRules := pr.GetValue().(import1.NSPApplicationRuleSpec)
appRules := pr.GetValue().(import1.ApplicationRuleSpec)

if appRules.SourceAllowSpec != nil {
assc["src_allow_spec"] = flattenAllowType(appRules.SourceAllowSpec)
if appRules.SrcAllowSpec != nil {
assc["src_allow_spec"] = flattenAllowType(appRules.SrcAllowSpec)
}
if appRules.DestAllowSpec != nil {
assc["dest_allow_spec"] = flattenAllowType(appRules.DestAllowSpec)
}
if appRules.SourceSubnet != nil {
assc["src_subnet"] = flattenIPv4Address(appRules.SourceSubnet)
if appRules.SrcSubnet != nil {
assc["src_subnet"] = flattenIPv4Address(appRules.SrcSubnet)
}
if appRules.DestSubnet != nil {
assc["dest_subnet"] = flattenIPv4Address(appRules.DestSubnet)
Expand All @@ -417,7 +417,7 @@ func flattenOneOfNetworkSecurityPolicyRuleSpec(pr *import1.OneOfNetworkSecurityP
assc["icmp_services"] = flattenIcmpTypeCodeSpec(appRules.IcmpServices)
}
} else if utils.StringValue(getVal) == "microseg.v4.r0.b1.config.IntraEntityGroupRuleSpec" {
intraRuleSpec := pr.GetValue().(import1.NSPIntraEntityGroupRuleSpec)
intraRuleSpec := pr.GetValue().(import1.IntraEntityGroupRuleSpec)

if intraRuleSpec.SecuredGroupAction != nil {
assc["secured_group_action"] = intraRuleSpec.SecuredGroupAction
Expand Down Expand Up @@ -464,16 +464,16 @@ func flattenAllowType(pr *import1.AllowType) string {
return "UNKNOWN"
}

func flattenPolicyState(pr *import1.PolicyState) string {
func flattenPolicyState(pr *import1.SecurityPolicyState) string {
const two, three, four = 2, 3, 4
if pr != nil {
if *pr == import1.PolicyState(two) {
if *pr == import1.SecurityPolicyState(two) {
return "SAVE"
}
if *pr == import1.PolicyState(three) {
if *pr == import1.SecurityPolicyState(three) {
return "MONITOR"
}
if *pr == import1.PolicyState(four) {
if *pr == import1.SecurityPolicyState(four) {
return "ENFORCE"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
import1 "github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4/models/microseg/v4/config"
import1 "github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16/models/microseg/v4/config"
conns "github.com/terraform-providers/terraform-provider-nutanix/nutanix"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
)
Expand Down Expand Up @@ -119,7 +119,7 @@ func DatasourceNutanixServiceGroupV4Read(ctx context.Context, d *schema.Resource

extID := d.Get("ext_id")

resp, err := conn.ServiceGroupAPIInstance.GetServiceGroupByExtId(utils.StringPtr(extID.(string)))
resp, err := conn.ServiceGroupAPIInstance.GetServiceGroupById(utils.StringPtr(extID.(string)))
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down Expand Up @@ -207,7 +207,7 @@ func flattenIcmpTypeCodeSpec(pr []import1.IcmpTypeCodeSpec) []interface{} {
for k, v := range pr {
rg := make(map[string]interface{})

rg["is_allowed"] = v.IsAllCodeTypeAllowed
rg["is_allowed"] = v.IsAllAllowed
rg["type"] = v.Type
rg["code"] = v.Code

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
import1 "github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4/models/microseg/v4/config"
import1 "github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16/models/microseg/v4/config"
conns "github.com/terraform-providers/terraform-provider-nutanix/nutanix"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
)
Expand Down Expand Up @@ -147,7 +147,7 @@ func DatasourceNutanixServiceGroupsV4Read(ctx context.Context, d *schema.Resourc
conn := meta.(*conns.Client).MicroSegAPI

// initialize query params
var filter, orderBy *string
var filter, orderBy, selects *string
var page, limit *int

if pagef, ok := d.GetOk("page"); ok {
Expand All @@ -170,13 +170,13 @@ func DatasourceNutanixServiceGroupsV4Read(ctx context.Context, d *schema.Resourc
} else {
orderBy = nil
}
// if selectf, ok := d.GetOk("select"); ok {
// selects = utils.StringPtr(selectf.(string))
// } else {
// selects = nil
// }
if selectf, ok := d.GetOk("select"); ok {
selects = utils.StringPtr(selectf.(string))
} else {
selects = nil
}

resp, err := conn.ServiceGroupAPIInstance.ListServiceGroups(page, limit, filter, orderBy)
resp, err := conn.ServiceGroupAPIInstance.ListServiceGroups(page, limit, filter, orderBy, selects)
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
config "github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4/models/common/v1/config"
import1 "github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4/models/microseg/v4/config"
import4 "github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4/models/prism/v4/config"
config "github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16/models/common/v1/config"
import1 "github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16/models/microseg/v4/config"
import4 "github.com/nutanix-core/ntnx-api-golang-sdk-internal/microseg-go-client/v16/models/prism/v4/config"
conns "github.com/terraform-providers/terraform-provider-nutanix/nutanix"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
)
Expand Down Expand Up @@ -106,7 +106,7 @@ func ResourceNutanixAddressGroupsV4Create(ctx context.Context, d *schema.Resourc
func ResourceNutanixAddressGroupsV4Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.Client).MicroSegAPI

resp, err := conn.AddressGroupAPIInstance.GetAddressGroupByExtId(utils.StringPtr(d.Id()))
resp, err := conn.AddressGroupAPIInstance.GetAddressGroupById(utils.StringPtr(d.Id()))
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down Expand Up @@ -142,7 +142,7 @@ func ResourceNutanixAddressGroupsV4Read(ctx context.Context, d *schema.ResourceD
func ResourceNutanixAddressGroupsV4Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.Client).MicroSegAPI
updateInput := &import1.AddressGroup{}
resp, err := conn.AddressGroupAPIInstance.GetAddressGroupByExtId(utils.StringPtr(d.Id()))
resp, err := conn.AddressGroupAPIInstance.GetAddressGroupById(utils.StringPtr(d.Id()))
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down Expand Up @@ -172,7 +172,7 @@ func ResourceNutanixAddressGroupsV4Update(ctx context.Context, d *schema.Resourc
updateInput.IpRanges = expandIPv4Range(d.Get("ip_ranges").([]interface{}))
}

updatedResp, err := conn.AddressGroupAPIInstance.UpdateAddressGroupByExtId(utils.StringPtr(d.Id()), updateInput)
updatedResp, err := conn.AddressGroupAPIInstance.UpdateAddressGroupById(utils.StringPtr(d.Id()), updateInput)
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down Expand Up @@ -208,7 +208,7 @@ func ResourceNutanixAddressGroupsV4Update(ctx context.Context, d *schema.Resourc
func ResourceNutanixAddressGroupsV4Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.Client).MicroSegAPI

resp, err := conn.AddressGroupAPIInstance.DeleteAddressGroupByExtId(utils.StringPtr(d.Id()))
resp, err := conn.AddressGroupAPIInstance.DeleteAddressGroupById(utils.StringPtr(d.Id()))
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down
Loading

0 comments on commit 2fccf60

Please sign in to comment.