Skip to content

Commit

Permalink
Merge pull request #113 from NetApp/55-new-data-source-protocolscifsl…
Browse files Browse the repository at this point in the history
…ocal-users

55 new data source protocolscifslocal users
  • Loading branch information
carchi8py authored Dec 12, 2023
2 parents 04b83b5 + 17e20ea commit 5f6161e
Show file tree
Hide file tree
Showing 21 changed files with 659 additions and 20 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
## 1.1.0 ()

FEATURES:

* **New Data Source:** `netapp_ontap_protocols_cifs_local_group_data_source` ([#54](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/54))
* **New Data Source:** `netapp_ontap_protocols_cifs_local_groups_data_source` ([#54](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/54))
* **New Data Source:** `netapp_ontap_cluster_peer_data_source` ([#50](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/50))
* **New Data Source:** `netapp_ontap_cluster_peers_data_source` ([#50](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/50))
* **New Data Source:** `netapp-ontap_protocols_cifs_local_user_data_source` ([#55](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/55))
* **New Data Source:** `netapp-ontap_protocols_cifs_local_users_data_source` ([#55](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/55))


ENHANCEMENTS:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "netapp-ontap_protocols_cifs_local_user_data_source Data Source - terraform-provider-netapp-ontap"
subcategory: "nas"
description: |-
Retrieve CifsLocalUser data source
---

# Data Source netapp-ontap_protocols_cifs_local_user

Retreives protocols cifs local user configuration

## Example Usage
```terraform
data "netapp-ontap_protocols_cifs_local_user_data_source" "local_user" {
# required to know which system to interface with
cx_profile_name = "cluster4"
svm_name = "svm3"
name = "test"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `cx_profile_name` (String) Connection profile name
- `name` (String) CifsLocalUser name
- `svm_name` (String) IPInterface svm name

### Read-Only

- `account_disabled` (Boolean) CifsLocalUser account disabled
- `description` (String) CifsLocalUser description
- `full_name` (String) CifsLocalUser full name
- `id` (String) CifsLocalUser id
- `membership` (Attributes List) CifsLocalUser membership (see [below for nested schema](#nestedatt--membership))

<a id="nestedatt--membership"></a>
### Nested Schema for `membership`

Read-Only:

- `name` (String) CifsLocalUser membership name


Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "netapp-ontap_protocols_cifs_local_users_data_source Data Source - terraform-provider-netapp-ontap"
subcategory: "nas"
description: |-
Retrieves list of Cifs Local Users.
---

# Data Source protocols_cifs_local_users

Retrieves a list of Cifs Local Users.

## Example Usage
```terraform
data "netapp-ontap_protocols_cifs_local_users_data_source" "protocols_cifs_local_users" {
# required to know which system to interface with
cx_profile_name = "cluster4"
filter = {
svm_name = "svm*"
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `cx_profile_name` (String) Connection profile name

### Optional

- `filter` (Attributes) (see [below for nested schema](#nestedatt--filter))

### Read-Only

- `protocols_cifs_local_users` (Attributes List) Protocols CIFS local users (see [below for nested schema](#nestedatt--protocols_cifs_local_users))

<a id="nestedatt--filter"></a>
### Nested Schema for `filter`

Optional:

- `name` (String) CifsLocalUser name
- `svm_name` (String) CifsLocalUser svm name


<a id="nestedatt--protocols_cifs_local_users"></a>
### Nested Schema for `protocols_cifs_local_users`

Required:

- `cx_profile_name` (String) Connection profile name
- `name` (String) CifsLocalUser name

Read-Only:

- `account_disabled` (Boolean) CifsLocalUser account disabled
- `description` (String) CifsLocalUser description
- `full_name` (String) CifsLocalUser full name
- `id` (String) CifsLocalUser id
- `membership` (Attributes List) CifsLocalUser membership (see [below for nested schema](#nestedatt--protocols_cifs_local_users--membership))
- `svm_name` (String) CifsLocalUser svm name

<a id="nestedatt--protocols_cifs_local_users--membership"></a>
### Nested Schema for `protocols_cifs_local_users.membership`

Read-Only:

- `name` (String) CifsLocalUser membership name


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
data "netapp-ontap_protocols_cifs_local_user_data_source" "protocols_cifs_local_user" {
# required to know which system to interface with
cx_profile_name = "cluster4"
svm_name = "svm1"
name = "testme"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
data "netapp-ontap_protocols_cifs_local_users_data_source" "protocols_cifs_local_users" {
# required to know which system to interface with
cx_profile_name = "cluster4"
filter = {
name = "user1"
svm_name = "svm*"
}
}
129 changes: 129 additions & 0 deletions internal/interfaces/protocols_cifs_local_user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package interfaces

import (
"fmt"

"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/mitchellh/mapstructure"
"github.com/netapp/terraform-provider-netapp-ontap/internal/restclient"
"github.com/netapp/terraform-provider-netapp-ontap/internal/utils"
)

// CifsLocalUserGetDataModelONTAP describes the GET record data model using go types for mapping.
type CifsLocalUserGetDataModelONTAP struct {
Name string `mapstructure:"name"`
SID string `mapstructure:"sid"`
SVM svm `mapstructure:"svm"`
FullName string `mapstructure:"full_name"`
Description string `mapstructure:"description"`
Membership []membership `mapstructure:"membership"`
AccountDisabled bool `mapstructure:"account_disabled"`
}

// Membership describes the membership data model using go types for mapping.
type membership struct {
Name string `mapstructure:"name"`
}

// CifsLocalUserDataSourceFilterModel describes the data source data model for queries.
type CifsLocalUserDataSourceFilterModel struct {
Name string `mapstructure:"name"`
SVMName string `mapstructure:"svm.name"`
}

// CifsLocalUserResourceBodyDataModelONTAP describes the body data model using go types for mapping.
type CifsLocalUserResourceBodyDataModelONTAP struct {
Name string `mapstructure:"name"`
SVM svm `mapstructure:"svm"`
}

// GetCifsLocalUserByName to get protocols_cifs_local_user info
func GetCifsLocalUserByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string, svmName string) (*CifsLocalUserGetDataModelONTAP, error) {
api := "protocols/cifs/local-users"
query := r.NewQuery()
query.Set("name", name)
query.Set("svm.name", svmName)

query.Fields([]string{"name", "svm.name", "full_name", "description", "membership", "account_disabled"})
statusCode, response, err := r.GetNilOrOneRecord(api, query, nil)
if err == nil && response == nil {
err = fmt.Errorf("no response for GET %s", api)
}
if err != nil {
return nil, errorHandler.MakeAndReportError("error reading protocols_cifs_local_user info", fmt.Sprintf("error on GET %s: %s, statusCode %d", api, err, statusCode))
}

var dataONTAP CifsLocalUserGetDataModelONTAP
if err := mapstructure.Decode(response, &dataONTAP); err != nil {
return nil, errorHandler.MakeAndReportError(fmt.Sprintf("failed to decode response from GET %s", api),
fmt.Sprintf("error: %s, statusCode %d, response %#v", err, statusCode, response))
}
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read protocols_cifs_local_user data source: %#v", dataONTAP))
return &dataONTAP, nil
}

// GetCifsLocalUsers to get protocols_cifs_local_user info for all resources matching a filter
func GetCifsLocalUsers(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *CifsLocalUserDataSourceFilterModel) ([]CifsLocalUserGetDataModelONTAP, error) {
api := "protocols/cifs/local-users"
query := r.NewQuery()
query.Fields([]string{"name", "svm.name", "full_name", "description", "membership", "account_disabled"})

if filter != nil {
var filterMap map[string]interface{}
if err := mapstructure.Decode(filter, &filterMap); err != nil {
return nil, errorHandler.MakeAndReportError("error encoding protocols_cifs_local_users filter info", fmt.Sprintf("error on filter %#v: %s", filter, err))
}
query.SetValues(filterMap)
}
statusCode, response, err := r.GetZeroOrMoreRecords(api, query, nil)
if err == nil && response == nil {
err = fmt.Errorf("no response for GET %s", api)
}
if err != nil {
return nil, errorHandler.MakeAndReportError("error reading protocols_cifs_local_users info", fmt.Sprintf("error on GET %s: %s, statusCode %d", api, err, statusCode))
}

var dataONTAP []CifsLocalUserGetDataModelONTAP
for _, info := range response {
var record CifsLocalUserGetDataModelONTAP
if err := mapstructure.Decode(info, &record); err != nil {
return nil, errorHandler.MakeAndReportError(fmt.Sprintf("failed to decode response from GET %s", api),
fmt.Sprintf("error: %s, statusCode %d, info %#v", err, statusCode, info))
}
dataONTAP = append(dataONTAP, record)
}
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read protocols_cifs_local_users data source: %#v", dataONTAP))
return dataONTAP, nil
}

// CreateCifsLocalUser to create protocols_cifs_local_user
func CreateCifsLocalUser(errorHandler *utils.ErrorHandler, r restclient.RestClient, body CifsLocalUserResourceBodyDataModelONTAP) (*CifsLocalUserGetDataModelONTAP, error) {
api := "protocols/cifs/local-users"
var bodyMap map[string]interface{}
if err := mapstructure.Decode(body, &bodyMap); err != nil {
return nil, errorHandler.MakeAndReportError("error encoding protocols_cifs_local_user body", fmt.Sprintf("error on encoding %s body: %s, body: %#v", api, err, body))
}
query := r.NewQuery()
query.Add("return_records", "true")
statusCode, response, err := r.CallCreateMethod(api, query, bodyMap)
if err != nil {
return nil, errorHandler.MakeAndReportError("error creating protocols_cifs_local_user", fmt.Sprintf("error on POST %s: %s, statusCode %d", api, err, statusCode))
}

var dataONTAP CifsLocalUserGetDataModelONTAP
if err := mapstructure.Decode(response.Records[0], &dataONTAP); err != nil {
return nil, errorHandler.MakeAndReportError("error decoding protocols_cifs_local_user info", fmt.Sprintf("error on decode storage/protocols_cifs_local_users info: %s, statusCode %d, response %#v", err, statusCode, response))
}
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Create protocols_cifs_local_user source - udata: %#v", dataONTAP))
return &dataONTAP, nil
}

// DeleteCifsLocalUser to delete protocols_cifs_local_user
func DeleteCifsLocalUser(errorHandler *utils.ErrorHandler, r restclient.RestClient, uuid string) error {
api := "protocols/cifs/local-users"
statusCode, _, err := r.CallDeleteMethod(api+"/"+uuid, nil, nil)
if err != nil {
return errorHandler.MakeAndReportError("error deleting protocols_cifs_local_user", fmt.Sprintf("error on DELETE %s: %s, statusCode %d", api, err, statusCode))
}
return nil
}
18 changes: 12 additions & 6 deletions internal/interfaces/tag_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ type GoPrefixResourceBodyDataModelONTAP struct {
SVM svm `mapstructure:"svm"`
}

// GetGoPrefix to get tag_prefix info
func GetGoPrefix(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string, svmName string) (*GoPrefixGetDataModelONTAP, error) {
// GoPrefixDataSourceFilterModel describes the data source data model for queries.
type GoPrefixDataSourceFilterModel struct {
Name string `mapstructure:"name"`
SVMName string `mapstructure:"svm.name"`
}

// GetGoPrefixByName to get tag_prefix info
func GetGoPrefixByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string, svmName string) (*GoPrefixGetDataModelONTAP, error) {
api := "api_url"
query := r.NewQuery()
query.Set("name", name)
Expand Down Expand Up @@ -58,14 +64,14 @@ func GetGoPrefix(errorHandler *utils.ErrorHandler, r restclient.RestClient, name
}

// GetGoAllPrefix to get tag_prefix info for all resources matching a filter
func GetGoAllPrefix(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *GoPrefixGetDataModelONTAP) ([]GoPrefixGetDataModelONTAP, error) {
func GetGoAllPrefix(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *GoPrefixDataSourceFilterModel) ([]GoPrefixGetDataModelONTAP, error) {
api := "api_url"
query := r.NewQuery()
query.Fields([]string{"name", "svm.name", "scope"})
if filter != nil {
var filterMap map[string]interface{}
if err := mapstructure.Decode(filter, &filterMap); err != nil {
return nil, errorHandler.MakeAndReportError("error encoding tag_prefix filter info", fmt.Sprintf("error on filter %#v: %s", filter, err))
return nil, errorHandler.MakeAndReportError("error encoding tag_all_prefix filter info", fmt.Sprintf("error on filter %#v: %s", filter, err))
}
query.SetValues(filterMap)
}
Expand All @@ -74,7 +80,7 @@ func GetGoAllPrefix(errorHandler *utils.ErrorHandler, r restclient.RestClient, f
err = fmt.Errorf("no response for GET %s", api)
}
if err != nil {
return nil, errorHandler.MakeAndReportError("error reading tag_prefix info", fmt.Sprintf("error on GET %s: %s, statusCode %d", api, err, statusCode))
return nil, errorHandler.MakeAndReportError("error reading tag_all_prefix info", fmt.Sprintf("error on GET %s: %s, statusCode %d", api, err, statusCode))
}

var dataONTAP []GoPrefixGetDataModelONTAP
Expand All @@ -86,7 +92,7 @@ func GetGoAllPrefix(errorHandler *utils.ErrorHandler, r restclient.RestClient, f
}
dataONTAP = append(dataONTAP, record)
}
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read tag_prefix data source: %#v", dataONTAP))
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read tag_all_prefix data source: %#v", dataONTAP))
return dataONTAP, nil
}

Expand Down
Loading

0 comments on commit 5f6161e

Please sign in to comment.