Skip to content

Commit

Permalink
Merge pull request #219 from cisco-en-programmability/develop
Browse files Browse the repository at this point in the history
Develop - 1.1.20
  • Loading branch information
DbarrantesE authored Oct 4, 2023
2 parents e421604 + 0cec640 commit 717d869
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.20-beta (October 04, 2023)
BUGFIXES:
* SearchUserGetUserApi added in resourceUserCreate and resourceUserRead to be able to create a user (Cannot create user #213)

## 1.1.19-beta (October 03, 2023)
BUGFIXES:
* Pagination support when interacting with API #215 - Adding code to paginate in resource.
Expand Down
38 changes: 21 additions & 17 deletions dnacenter/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, m interface
vvInvokeSource := interfaceToString(vInvokeSource)
queryParamImport := dnacentersdkgo.GetUsersApIQueryParams{}
queryParamImport.InvokeSource = vvInvokeSource
item2, err := searchUserGetUserApi(m, queryParamImport, request1.Username)
_, item2, err := searchUserGetUserApi(m, queryParamImport, request1.Username)

if err == nil && item2 != nil {
resourceMap := make(map[string]string)
resourceMap["invoke_source"] = vvInvokeSource
Expand All @@ -193,7 +194,8 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, m interface
// TODO REVIEW
queryParamValidate := dnacentersdkgo.GetUsersApIQueryParams{}
queryParamValidate.InvokeSource = vvInvokeSource
item3, _, err := client.UserandRoles.GetUsersApI(&queryParamValidate)
//item3, _, err := client.UserandRoles.GetUsersApI(&queryParamValidate)
_, item3, err := searchUserGetUserApi(m, queryParamValidate, request1.Username)
if err != nil || item3 == nil {
diags = append(diags, diagErrorWithAlt(
"Failure when executing AddUserApI", err,
Expand All @@ -209,8 +211,7 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, m interface
}

func resourceUserRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*dnacentersdkgo.Client)

//client := m.(*dnacentersdkgo.Client)
var diags diag.Diagnostics

resourceID := d.Id()
Expand All @@ -222,18 +223,21 @@ func resourceUserRead(ctx context.Context, d *schema.ResourceData, m interface{}
if selectedMethod == 1 {
log.Printf("[DEBUG] Selected method: GetUsersApI")
queryParams1 := dnacentersdkgo.GetUsersApIQueryParams{}

request1 := expandRequestUserAddUserApI(ctx, "parameters.0", d)
queryParams1.InvokeSource = vInvokeSource

response1, restyResp1, err := client.UserandRoles.GetUsersApI(&queryParams1)

if err != nil || response1 == nil {
//response1, restyResp1, err := client.UserandRoles.GetUsersApI(&queryParams1)
response1, item1, err := searchUserGetUserApi(m, queryParams1, request1.Username)
if err != nil || item1 == nil {
d.SetId("")
return diags
}
/*if err != nil || response1 == nil {
if restyResp1 != nil {
log.Printf("[DEBUG] Retrieved error response %s", restyResp1.String())
}
d.SetId("")
return diags
}
}*/

log.Printf("[DEBUG] Retrieved response %+v", responseInterfaceToString(*response1))

Expand Down Expand Up @@ -342,25 +346,25 @@ func expandRequestUserUpdateUserApI(ctx context.Context, key string, d *schema.R
return &request
}

func searchUserGetUserApi(m interface{}, queryParams dnacentersdkgo.GetUsersApIQueryParams, username string) (*dnacentersdkgo.ResponseUserandRolesGetUsersAPIResponseUsers, error) {
func searchUserGetUserApi(m interface{}, queryParams dnacentersdkgo.GetUsersApIQueryParams, username string) (*dnacentersdkgo.ResponseUserandRolesGetUsersApI, *dnacentersdkgo.ResponseUserandRolesGetUsersAPIResponseUsers, error) {
client := m.(*dnacentersdkgo.Client)
var err error
var foundItem *dnacentersdkgo.ResponseUserandRolesGetUsersAPIResponseUsers
ite, _, err := client.UserandRoles.GetUsersApI(&queryParams)
if err != nil {
return foundItem, err
return ite, foundItem, err
}

if ite == nil {
return foundItem, err
return ite, foundItem, err
}

if ite.Response == nil {
return foundItem, err
return ite, foundItem, err
}

if ite.Response.Users == nil {
return foundItem, err
return ite, foundItem, err
}

items := ite.Response.Users
Expand All @@ -372,8 +376,8 @@ func searchUserGetUserApi(m interface{}, queryParams dnacentersdkgo.GetUsersApIQ
var getItem *dnacentersdkgo.ResponseUserandRolesGetUsersAPIResponseUsers
getItem = &item
foundItem = getItem
return foundItem, err
return ite, foundItem, err
}
}
return foundItem, err
return ite, foundItem, err
}

0 comments on commit 717d869

Please sign in to comment.