Skip to content

Commit

Permalink
adding pagination support to data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
tmunzer committed Aug 30, 2024
1 parent 3cf8ba9 commit 4ab4c78
Show file tree
Hide file tree
Showing 50 changed files with 2,824 additions and 909 deletions.
32 changes: 31 additions & 1 deletion docs/data-sources/org_nactags.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ data "mist_org_nactags" "nactags" {

- `org_id` (String)

### Optional

- `limit` (Number)
- `match` (String) Type of NAC Tag
- `name` (String) Name of NAC Tag
- `page` (Number)
- `type` (String) Type of NAC Tag

### Read-Only

- `org_nactags` (Attributes Set) (see [below for nested schema](#nestedatt--org_nactags))
Expand All @@ -34,8 +42,30 @@ data "mist_org_nactags" "nactags" {

Read-Only:

- `allow_usermac_override` (Boolean) can be set to true to allow the override by usermac result
- `created_time` (Number)
- `egress_vlan_names` (List of String) if `type`==`egress_vlan_names`, list of egress vlans to return
- `gbp_tag` (Number) if `type`==`gbp_tag`
- `id` (String)
- `match` (String) if `type`==`match`. enum: `cert_cn`, `cert_issuer`, `cert_san`, `cert_serial`, `cert_sub`, `client_mac`, `idp_role`, `mdm_status`, `radius_group`, `realm`, `ssid`, `user_name`, `usermac_label`
- `match_all` (Boolean) This field is applicable only when `type`==`match`
* `false`: means it is sufficient to match any of the values (i.e., match-any behavior)
* `true`: means all values should be matched (i.e., match-all behavior)


Currently it makes sense to set this field to `true` only if the `match`==`idp_role` or `match`==`usermac_label`'
- `modified_time` (Number)
- `name` (String)
- `org_id` (String)
- `org_id` (String)
- `radius_attrs` (List of String) if `type`==`radius_attrs`, user can specify a list of one or more standard attributes in the field "radius_attrs".
It is the responsibility of the user to provide a syntactically correct string, otherwise it may not work as expected.
Note that it is allowed to have more than one radius_attrs in the result of a given rule.
- `radius_group` (String) if `type`==`radius_group`
- `radius_vendor_attrs` (List of String) if `type`==`radius_vendor_attrs`, user can specify a list of one or more vendor-specific attributes in the field "radius_vendor_attrs".
It is the responsibility of the user to provide a syntactically correct string, otherwise it may not work as expected.
Note that it is allowed to have more than one radius_vendor_attrs in the result of a given rule.
- `session_timeout` (Number) if `type`==`session_timeout, in seconds
- `type` (String) enum: `egress_vlan_names`, `gbp_tag`, `match`, `radius_attrs`, `radius_group`, `radius_vendor_attrs`, `session_timeout`, `username_attr`, `vlan`
- `username_attr` (String)
- `values` (List of String) if `type`==`match`
- `vlan` (String) if `type`==`vlan`
27 changes: 5 additions & 22 deletions internal/datasource_device_ap_stats/sdk_to_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package datasource_device_ap_stats

import (
"context"
"encoding/json"
"math/big"

mist_transform "github.com/Juniper/terraform-provider-mist/internal/commons/utils"
Expand All @@ -15,31 +14,15 @@ import (
"github.com/tmunzer/mistapi-go/mistapi/models"
)

func SdkToTerraform(ctx context.Context, l []models.StatsDevice) (basetypes.SetValue, diag.Diagnostics) {
func SdkToTerraform(ctx context.Context, l *[]models.StatsAp, elements *[]attr.Value) diag.Diagnostics {
var diags diag.Diagnostics

var elements []attr.Value
for _, d := range l {
ap_js, e := d.MarshalJSON()
if e != nil {
diags.AddError("Unable to Marshal AP Stats", e.Error())
} else {
ap := models.StatsAp{}
e := json.Unmarshal(ap_js, &ap)
if e != nil {
diags.AddError("Unable to unMarshal AP Stats", e.Error())
}
elem := deviceApStatSdkToTerraform(ctx, &diags, &ap)
elements = append(elements, elem)
}
for _, d := range *l {
elem := deviceApStatSdkToTerraform(ctx, &diags, &d)
*elements = append(*elements, elem)
}

dataSet, err := types.SetValue(DeviceApStatsValue{}.Type(ctx), elements)
if err != nil {
diags.Append(err...)
}

return dataSet, diags
return diags
}

func deviceApStatSdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d *models.StatsAp) DeviceApStatsValue {
Expand Down
27 changes: 5 additions & 22 deletions internal/datasource_device_gateway_stats/sdk_to_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package datasource_device_gateway_stats

import (
"context"
"encoding/json"
"math/big"

"github.com/hashicorp/terraform-plugin-framework/attr"
Expand All @@ -13,31 +12,15 @@ import (
"github.com/tmunzer/mistapi-go/mistapi/models"
)

func SdkToTerraform(ctx context.Context, l []models.StatsDevice) (basetypes.SetValue, diag.Diagnostics) {
func SdkToTerraform(ctx context.Context, l *[]models.StatsGateway, elements *[]attr.Value) diag.Diagnostics {
var diags diag.Diagnostics

var elements []attr.Value
for _, d := range l {
gw_js, e := d.MarshalJSON()
if e != nil {
diags.AddError("Unable to unMarshal Gateway Stats", e.Error())
} else {
gw := models.StatsGateway{}
e := json.Unmarshal(gw_js, &gw)
if e != nil {
diags.AddError("Unable to unMarshal Switch Stats", e.Error())
}
elem := deviceGatewayStatSdkToTerraform(ctx, &diags, &gw)
elements = append(elements, elem)
}
for _, d := range *l {
elem := deviceGatewayStatSdkToTerraform(ctx, &diags, &d)
*elements = append(*elements, elem)
}

dataSet, err := types.SetValue(DeviceGatewayStatsValue{}.Type(ctx), elements)
if err != nil {
diags.Append(err...)
}

return dataSet, diags
return diags
}

func deviceGatewayStatSdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d *models.StatsGateway) DeviceGatewayStatsValue {
Expand Down
27 changes: 5 additions & 22 deletions internal/datasource_device_switch_stats/sdk_to_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package datasource_device_switch_stats

import (
"context"
"encoding/json"
"math/big"

"github.com/hashicorp/terraform-plugin-framework/attr"
Expand All @@ -13,31 +12,15 @@ import (
"github.com/tmunzer/mistapi-go/mistapi/models"
)

func SdkToTerraform(ctx context.Context, l []models.StatsDevice) (basetypes.SetValue, diag.Diagnostics) {
func SdkToTerraform(ctx context.Context, l *[]models.StatsSwitch, elements *[]attr.Value) diag.Diagnostics {
var diags diag.Diagnostics

var elements []attr.Value
for _, d := range l {
sw_js, e := d.MarshalJSON()
if e != nil {
diags.AddError("Unable to Marshal Switch Stats", e.Error())
} else {
sw := models.StatsSwitch{}
e := json.Unmarshal(sw_js, &sw)
if e != nil {
diags.AddError("Unable to unMarshal Switch Stats", e.Error())
}
elem := deviceSwitchStatSdkToTerraform(ctx, &diags, &sw)
elements = append(elements, elem)
}
for _, d := range *l {
elem := deviceSwitchStatSdkToTerraform(ctx, &diags, &d)
*elements = append(*elements, elem)
}

dataSet, err := types.SetValue(DeviceSwitchStatsValue{}.Type(ctx), elements)
if err != nil {
diags.Append(err...)
}

return dataSet, diags
return diags
}

func deviceSwitchStatSdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d *models.StatsSwitch) DeviceSwitchStatsValue {
Expand Down
27 changes: 5 additions & 22 deletions internal/datasource_org_deviceprofiles_ap/sdk_to_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package datasource_org_deviceprofiles_ap

import (
"context"
"encoding/json"
"math/big"

"github.com/tmunzer/mistapi-go/mistapi/models"
Expand All @@ -13,31 +12,15 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

func SdkToTerraform(ctx context.Context, l []models.Deviceprofile) (basetypes.SetValue, diag.Diagnostics) {
func SdkToTerraform(ctx context.Context, l *[]models.DeviceprofileAp, elements *[]attr.Value) diag.Diagnostics {
var diags diag.Diagnostics

var elements []attr.Value
for _, d := range l {
ap_js, e := d.MarshalJSON()
if e != nil {
diags.AddError("Unable to Marshal Deviceprofile AP", e.Error())
} else {
deviceprofile := models.DeviceprofileAp{}
e := json.Unmarshal(ap_js, &deviceprofile)
if e != nil {
diags.AddError("Unable to unMarshal AP Stats", e.Error())
}
elem := deviceprofileApSdkToTerraform(ctx, &diags, &deviceprofile)
elements = append(elements, elem)
}
for _, d := range *l {
elem := deviceprofileApSdkToTerraform(ctx, &diags, &d)
*elements = append(*elements, elem)
}

dataSet, err := types.SetValue(OrgDeviceprofilesApValue{}.Type(ctx), elements)
if err != nil {
diags.Append(err...)
}

return dataSet, diags
return diags
}

func deviceprofileApSdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d *models.DeviceprofileAp) OrgDeviceprofilesApValue {
Expand Down
27 changes: 5 additions & 22 deletions internal/datasource_org_deviceprofiles_gateway/sdk_to_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package datasource_org_deviceprofiles_gateway

import (
"context"
"encoding/json"
"math/big"

"github.com/tmunzer/mistapi-go/mistapi/models"
Expand All @@ -13,31 +12,15 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

func SdkToTerraform(ctx context.Context, l []models.Deviceprofile) (basetypes.SetValue, diag.Diagnostics) {
func SdkToTerraform(ctx context.Context, l *[]models.DeviceprofileGateway, elements *[]attr.Value) diag.Diagnostics {
var diags diag.Diagnostics

var elements []attr.Value
for _, d := range l {
ap_js, e := d.MarshalJSON()
if e != nil {
diags.AddError("Unable to Marshal Deviceprofile AP", e.Error())
} else {
deviceprofile := models.DeviceprofileGateway{}
e := json.Unmarshal(ap_js, &deviceprofile)
if e != nil {
diags.AddError("Unable to unMarshal AP Stats", e.Error())
}
elem := deviceprofileApSdkToTerraform(ctx, &diags, &deviceprofile)
elements = append(elements, elem)
}
for _, d := range *l {
elem := deviceprofileApSdkToTerraform(ctx, &diags, &d)
*elements = append(*elements, elem)
}

dataSet, err := types.SetValue(OrgDeviceprofilesGatewayValue{}.Type(ctx), elements)
if err != nil {
diags.Append(err...)
}

return dataSet, diags
return diags
}

func deviceprofileApSdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d *models.DeviceprofileGateway) OrgDeviceprofilesGatewayValue {
Expand Down
18 changes: 6 additions & 12 deletions internal/datasource_org_gatewaytemplates/sdk_to_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,18 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

func SdkToTerraform(ctx context.Context, l []models.GatewayTemplate) (basetypes.SetValue, diag.Diagnostics) {
func SdkToTerraform(ctx context.Context, l *[]models.GatewayTemplate, elements *[]attr.Value) diag.Diagnostics {
var diags diag.Diagnostics

var elements []attr.Value
for _, d := range l {
elem := gatewaytemplateSdkToTerraform(ctx, &diags, d)
elements = append(elements, elem)
for _, d := range *l {
elem := gatewaytemplateSdkToTerraform(ctx, &diags, &d)
*elements = append(*elements, elem)
}

dataSet, err := types.SetValue(OrgGatewaytemplatesValue{}.Type(ctx), elements)
if err != nil {
diags.Append(err...)
}

return dataSet, diags
return diags
}

func gatewaytemplateSdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d models.GatewayTemplate) OrgGatewaytemplatesValue {
func gatewaytemplateSdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d *models.GatewayTemplate) OrgGatewaytemplatesValue {

var created_time basetypes.NumberValue
var id basetypes.StringValue
Expand Down
18 changes: 6 additions & 12 deletions internal/datasource_org_idpprofiles/sdk_to_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,18 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

func SdkToTerraform(ctx context.Context, l []models.IdpProfile) (basetypes.SetValue, diag.Diagnostics) {
func SdkToTerraform(ctx context.Context, l *[]models.IdpProfile, elements *[]attr.Value) diag.Diagnostics {
var diags diag.Diagnostics

var elements []attr.Value
for _, d := range l {
elem := servicepolicieSdkToTerraform(ctx, &diags, d)
elements = append(elements, elem)
for _, d := range *l {
elem := servicepolicieSdkToTerraform(ctx, &diags, &d)
*elements = append(*elements, elem)
}

dataSet, err := types.SetValue(OrgIdpprofilesValue{}.Type(ctx), elements)
if err != nil {
diags.Append(err...)
}

return dataSet, diags
return diags
}

func servicepolicieSdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d models.IdpProfile) OrgIdpprofilesValue {
func servicepolicieSdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d *models.IdpProfile) OrgIdpprofilesValue {

var base_profile types.String
var created_time basetypes.NumberValue
Expand Down
14 changes: 4 additions & 10 deletions internal/datasource_org_inventory/sdk_to_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,15 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

func SdkToTerraform(ctx context.Context, l []models.Inventory) (basetypes.SetValue, diag.Diagnostics) {
func SdkToTerraform(ctx context.Context, l *[]models.Inventory, elements *[]attr.Value) diag.Diagnostics {
var diags diag.Diagnostics

var elements []attr.Value
for _, d := range l {
for _, d := range *l {
elem := inventorySdkToTerraform(ctx, &diags, d)
elements = append(elements, elem)
*elements = append(*elements, elem)
}

dataSet, err := types.SetValue(OrgInventoryValue{}.Type(ctx), elements)
if err != nil {
diags.Append(err...)
}

return dataSet, diags
return diags
}

func inventorySdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d models.Inventory) OrgInventoryValue {
Expand Down
18 changes: 6 additions & 12 deletions internal/datasource_org_nacrules/sdk_to_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,18 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

func SdkToTerraform(ctx context.Context, l []models.NacRule) (basetypes.SetValue, diag.Diagnostics) {
func SdkToTerraform(ctx context.Context, l *[]models.NacRule, elements *[]attr.Value) diag.Diagnostics {
var diags diag.Diagnostics

var elements []attr.Value
for _, d := range l {
elem := nacruleSdkToTerraform(ctx, &diags, d)
elements = append(elements, elem)
for _, d := range *l {
elem := nacruleSdkToTerraform(ctx, &diags, &d)
*elements = append(*elements, elem)
}

dataSet, err := types.SetValue(OrgNacrulesValue{}.Type(ctx), elements)
if err != nil {
diags.Append(err...)
}

return dataSet, diags
return diags
}

func nacruleSdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d models.NacRule) OrgNacrulesValue {
func nacruleSdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d *models.NacRule) OrgNacrulesValue {

var created_time basetypes.NumberValue
var id basetypes.StringValue
Expand Down
Loading

1 comment on commit 4ab4c78

@tmunzer
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix for #2

Please sign in to comment.