Skip to content

Commit

Permalink
feat: improved import messaging
Browse files Browse the repository at this point in the history
- Added missing docstring
  • Loading branch information
kian99 committed Sep 16, 2024
1 parent cea0e68 commit 034adb4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions internal/provider/resource_access_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ func newJaasAccessID(targetTag names.Tag, accessStr string) string {
func retrieveJaasAccessFromID(ID types.String, diag *diag.Diagnostics) (resourceTag names.Tag, access string) {
resID := strings.Split(ID.ValueString(), ":")
if len(resID) != 2 {
diag.AddError("Malformed ID", fmt.Sprintf("Access ID %q is malformed, "+
"please use the format '<resourceTag>:<access>:'", resID))
diag.AddError("Malformed ID", fmt.Sprintf("Access ID %q is malformed", resID))
return nil, ""
}
tag, err := jimmnames.ParseTag(resID[0])
Expand All @@ -488,14 +487,16 @@ func retrieveJaasAccessFromID(ID types.String, diag *diag.Diagnostics) (resource
return tag, resID[1]
}

// Importstate validates the user provided ID and attempts to create a resource by
// reading and importing the object referred to by the provided ID.
func (a *genericJAASAccessResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
IDstr := req.ID
resID := strings.Split(IDstr, ":")
if len(resID) != 2 {
resp.Diagnostics.AddError(
"ImportState Failure",
fmt.Sprintf("Malformed Import ID %q, "+
"please use format '<resourceTag>:<access>' e.g. %s", IDstr, a.targetResource.ImportHint()),
"please use format %q", IDstr, a.targetResource.ImportHint()),
)
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_access_jaas_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (j modelInfo) Save(ctx context.Context, setter Setter, info genericJAASAcce

// ImportHint implements [resourceInfo] and provides a hint to users on the import string format.
func (j modelInfo) ImportHint() string {
return "model-<UUID>:writer"
return "model-<UUID>:<access-level>"
}

type jaasAccessModelResource struct {
Expand Down

0 comments on commit 034adb4

Please sign in to comment.