Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
attempt to fix read of user data source
Browse files Browse the repository at this point in the history
  • Loading branch information
Luiggi33 committed Jul 24, 2024
1 parent 7870d1a commit 26b90c2
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions internal/provider/user_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,7 @@ func (d *userDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
var state userDataSourceModel

// Get the attributes from the request
var target struct {
ID int `tfsdk:"id"`
ExternalID string `tfsdk:"external_id"`
Username string `tfsdk:"username"`
Email string `tfsdk:"email"`
}
diags := req.Config.Get(ctx, &target)
diags := req.Config.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
Expand All @@ -151,14 +145,14 @@ func (d *userDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
// Fetch the user from the API based on the provided attribute
var user pterodactyl.User
var err error
if target.ID != 0 {
user, err = d.client.GetUser(target.ID)
} else if target.Username != "" {
user, err = d.client.GetUserUsername(target.Username)
} else if target.Email != "" {
user, err = d.client.GetUserEmail(target.Email)
} else if target.ExternalID != "" {
user, err = d.client.GetUserExternalID(target.ExternalID)
if state.ID != 0 {
user, err = d.client.GetUser(state.ID)
} else if state.Username != "" {
user, err = d.client.GetUserUsername(state.Username)
} else if state.Email != "" {
user, err = d.client.GetUserEmail(state.Email)
} else if state.ExternalID != "" {
user, err = d.client.GetUserExternalID(state.ExternalID)
} else {
resp.Diagnostics.AddError(
"Missing Attribute",
Expand Down

0 comments on commit 26b90c2

Please sign in to comment.