Skip to content

Commit

Permalink
Merge pull request #26 from permitio/raz/per-8702-bug-fix-role-deriva…
Browse files Browse the repository at this point in the history
…tion-read

Raz/per 8702 bug fix role derivation read
  • Loading branch information
RazcoDev committed Jan 5, 2024
2 parents 188d54a + 2bb432e commit ed607c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions internal/provider/role_derivations/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func (c *apiClient) Create(ctx context.Context, plan roleDerivationModel) (roleD

func (c *apiClient) Read(ctx context.Context, plan roleDerivationModel) (roleDerivationModel, error) {
targetRoleRead, err := c.client.Api.ResourceRoles.Get(
ctx, plan.Resource.ValueString(), plan.Role.String())
ctx, plan.Resource.ValueString(), plan.ToRole.ValueString())

if err != nil {
return roleDerivationModel{},
fmt.Errorf("failed getting target role %s/%s: %w", plan.Resource.ValueString(), plan.Role.ValueString(), err)
fmt.Errorf("failed getting target role %s/%s: %w", plan.Resource.ValueString(), plan.ToRole.ValueString(), err)
}

if targetRoleRead.GrantedTo == nil {
Expand All @@ -49,7 +49,7 @@ func (c *apiClient) Read(ctx context.Context, plan roleDerivationModel) (roleDer

derivation, found := lo.Find(targetRoleRead.GrantedTo.UsersWithRole, func(item models.DerivedRoleRuleRead) bool {
return item.OnResource == plan.OnResource.ValueString() &&
item.Role == plan.ToRole.ValueString() &&
item.Role == plan.Role.ValueString() &&
item.LinkedByRelation == plan.LinkedByRelation.ValueString()
})

Expand Down
6 changes: 5 additions & 1 deletion internal/provider/role_derivations/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (r *RoleDerivationResource) Create(ctx context.Context, request resource.Cr
"Unable to create role derivation",
fmt.Errorf("unable to create role derivation: %w", err).Error(),
)
return
}

response.Diagnostics.Append(response.State.Set(ctx, roleRead)...)
Expand All @@ -110,7 +111,10 @@ func (r *RoleDerivationResource) Read(ctx context.Context, request resource.Read
reality, err := r.client.Read(ctx, model)

if err != nil {
response.State.RemoveResource(ctx)
response.Diagnostics.AddError(
"Unable to read role derivation",
fmt.Errorf("unable to read role derivation: %w", err).Error(),
)
return
}

Expand Down

0 comments on commit ed607c5

Please sign in to comment.