Skip to content

Commit

Permalink
feat: users and userroles to use new client
Browse files Browse the repository at this point in the history
  • Loading branch information
mik-ky committed Oct 10, 2023
1 parent 181bb8b commit 7aac2f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions octopusdeploy/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/users"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -28,7 +29,7 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, m interface
log.Printf("[DEBUG] creating user")

client := m.(*client.Client)
createdUser, err := client.Users.Add(user)
createdUser, err := users.Add(client, user)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -47,7 +48,7 @@ func resourceUserDelete(ctx context.Context, d *schema.ResourceData, m interface
log.Printf("[INFO] deleting user (%s)", d.Id())

client := m.(*client.Client)
if err := client.Users.DeleteByID(d.Id()); err != nil {
if err := users.DeleteByID(client, d.Id()); err != nil {
return diag.FromErr(err)
}

Expand All @@ -61,7 +62,7 @@ func resourceUserRead(ctx context.Context, d *schema.ResourceData, m interface{}
log.Printf("[INFO] reading user (%s)", d.Id())

client := m.(*client.Client)
user, err := client.Users.GetByID(d.Id())
user, err := users.GetByID(client, d.Id())
if err != nil {
return errors.ProcessApiError(ctx, d, err, "user")
}
Expand All @@ -79,7 +80,7 @@ func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, m interface

user := expandUser(d)
client := m.(*client.Client)
updatedUser, err := client.Users.Update(user)
updatedUser, err := users.Update(client, user)
if err != nil {
return diag.FromErr(err)
}
Expand Down
9 changes: 5 additions & 4 deletions octopusdeploy/resource_user_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/userroles"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -28,7 +29,7 @@ func resourceUserRoleCreate(ctx context.Context, d *schema.ResourceData, m inter
log.Printf("[INFO] creating user role: %#v", userRole)

client := m.(*client.Client)
createdUserRole, err := client.UserRoles.Add(userRole)
createdUserRole, err := userroles.Add(client, userRole)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -47,7 +48,7 @@ func resourceUserRoleDelete(ctx context.Context, d *schema.ResourceData, m inter
log.Printf("[INFO] deleting user role (%s)", d.Id())

client := m.(*client.Client)
if err := client.UserRoles.DeleteByID(d.Id()); err != nil {
if err := userroles.DeleteByID(client, d.Id()); err != nil {
return diag.FromErr(err)
}

Expand All @@ -61,7 +62,7 @@ func resourceUserRoleRead(ctx context.Context, d *schema.ResourceData, m interfa
log.Printf("[INFO] reading user role (%s)", d.Id())

client := m.(*client.Client)
userRole, err := client.UserRoles.GetByID(d.Id())
userRole, err := userroles.GetByID(client, d.Id())
if err != nil {
return errors.ProcessApiError(ctx, d, err, "user role")
}
Expand All @@ -79,7 +80,7 @@ func resourceUserRoleUpdate(ctx context.Context, d *schema.ResourceData, m inter

userRole := expandUserRole(d)
client := m.(*client.Client)
updatedUserRole, err := client.UserRoles.Update(userRole)
updatedUserRole, err := userroles.Update(client, userRole)
if err != nil {
return diag.FromErr(err)
}
Expand Down

0 comments on commit 7aac2f7

Please sign in to comment.