Skip to content

Commit bdb115a

Browse files
committed
refactor: send custom_language entity directly, drop decoupling shim
Backend infra now accepts the custom_language entity, so the resource no longer needs the name/entity split. Use plain newResource and remove newResourceWithEntity.
1 parent dfb776b commit bdb115a

2 files changed

Lines changed: 7 additions & 16 deletions

File tree

internal/resources/base.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@ import (
1919
// the resource will be assumed to be a project-level resource (like a connector or flow), otherwise
2020
// it'll be assumed to be a company-level resource.
2121
func newResource[T any, M helpers.ResourceModel[T]](name string, sc schema.Schema) resource.Resource {
22-
return &baseResource[T, M]{name: name, entity: name, schema: sc}
23-
}
24-
25-
// Like newResource but with a distinct API entity name, for when the user-facing resource name
26-
// differs from the infra entity the backend expects (e.g. descope_custom_language -> custom_locale).
27-
func newResourceWithEntity[T any, M helpers.ResourceModel[T]](name, entity string, sc schema.Schema) resource.Resource {
28-
return &baseResource[T, M]{name: name, entity: entity, schema: sc}
22+
return &baseResource[T, M]{name: name, schema: sc}
2923
}
3024

3125
// Use a random model to ensure interface conformance
@@ -36,8 +30,7 @@ var (
3630
)
3731

3832
type baseResource[T any, M helpers.ResourceModel[T]] struct {
39-
name string // user-facing resource name (descope_<name>)
40-
entity string // infra entity name sent to the backend; defaults to name
33+
name string
4134
schema schema.Schema
4235
client *infra.Client
4336
}
@@ -71,7 +64,7 @@ func (r *baseResource[T, M]) Create(ctx context.Context, req resource.CreateRequ
7164
return
7265
}
7366

74-
res, err := r.client.Create(ctx, model.GetProjectID().ValueString(), r.entity, values)
67+
res, err := r.client.Create(ctx, model.GetProjectID().ValueString(), r.name, values)
7568
if failure, ok := infra.AsValidationError(err); ok {
7669
resp.Diagnostics.AddError("Invalid "+r.name+" configuration", failure)
7770
return
@@ -98,7 +91,7 @@ func (r *baseResource[T, M]) Read(ctx context.Context, req resource.ReadRequest,
9891
return
9992
}
10093

101-
res, err := r.client.Read(ctx, model.GetProjectID().ValueString(), r.entity, model.GetID().ValueString())
94+
res, err := r.client.Read(ctx, model.GetProjectID().ValueString(), r.name, model.GetID().ValueString())
10295
if err != nil {
10396
resp.Diagnostics.AddError("Error reading "+r.name, err.Error())
10497
return
@@ -126,7 +119,7 @@ func (r *baseResource[T, M]) Update(ctx context.Context, req resource.UpdateRequ
126119
return
127120
}
128121

129-
res, err := r.client.Update(ctx, model.GetProjectID().ValueString(), r.entity, model.GetID().ValueString(), values)
122+
res, err := r.client.Update(ctx, model.GetProjectID().ValueString(), r.name, model.GetID().ValueString(), values)
130123
if failure, ok := infra.AsValidationError(err); ok {
131124
resp.Diagnostics.AddError("Invalid "+r.name+" configuration", failure)
132125
return
@@ -151,7 +144,7 @@ func (r *baseResource[T, M]) Delete(ctx context.Context, req resource.DeleteRequ
151144
return
152145
}
153146

154-
err := r.client.Delete(ctx, model.GetProjectID().ValueString(), r.entity, model.GetID().ValueString())
147+
err := r.client.Delete(ctx, model.GetProjectID().ValueString(), r.name, model.GetID().ValueString())
155148
if err != nil {
156149
resp.Diagnostics.AddError("Error deleting "+r.name, err.Error())
157150
return

internal/resources/resources.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,5 @@ func NewEngineResource() resource.Resource {
3131
}
3232

3333
func NewCustomLanguageResource() resource.Resource {
34-
// user-facing resource stays descope_custom_language (product vocabulary); the backend infra
35-
// entity is custom_locale (consistent with projectservice).
36-
return newResourceWithEntity[customlanguage.CustomLanguageModel]("custom_language", "custom_locale", customlanguage.Schema)
34+
return newResource[customlanguage.CustomLanguageModel]("custom_language", customlanguage.Schema)
3735
}

0 commit comments

Comments
 (0)