@@ -56,6 +56,8 @@ func (m *personalAccessTokenResourceModel) from(ctx context.Context, t *forgejo.
5656 m .Scopes , d = types .SetValueFrom (ctx , types .StringType , t .Scopes )
5757 diags .Append (d ... )
5858
59+ // Token intentionally omitted (API only returns it once during initial creation)
60+
5961 return diags
6062}
6163
@@ -84,9 +86,9 @@ func (r *personalAccessTokenResource) Metadata(_ context.Context, req resource.M
8486// Schema defines the schema for the resource.
8587func (r * personalAccessTokenResource ) Schema (_ context.Context , _ resource.SchemaRequest , resp * resource.SchemaResponse ) {
8688 resp .Schema = schema.Schema {
87- Description : `Forgejo repository personal access token resource.
89+ MarkdownDescription : `Forgejo personal access token resource.
8890
89- **Note**: Due to an upstream limitation, one cannot create access tokens when authorised with access tokens. Use basic-auth instead.` ,
91+ **Note**: Due to an upstream limitation, one cannot create access tokens when authorized with access tokens. Use basic-auth instead.` ,
9092
9193 Attributes : map [string ]schema.Attribute {
9294 "user" : schema.StringAttribute {
@@ -245,18 +247,18 @@ func (r *personalAccessTokenResource) Create(ctx context.Context, req resource.C
245247 )
246248 case 401 :
247249 msg = fmt .Sprintf (
248- "Authentication method is not allowed, use basic-auth: %s" ,
250+ "Authentication method not allowed, use basic-auth: %s" ,
249251 err ,
250252 )
251253 case 403 :
252254 msg = fmt .Sprintf (
253- "User %s forbidden: %s" ,
255+ "Personal access token for user %s forbidden: %s" ,
254256 data .User .String (),
255257 err ,
256258 )
257259 case 404 :
258260 msg = fmt .Sprintf (
259- "User %s not found: %s" ,
261+ "Personal access token for user %s not found: %s" ,
260262 data .User .String (),
261263 err ,
262264 )
@@ -280,7 +282,7 @@ func (r *personalAccessTokenResource) Create(ctx context.Context, req resource.C
280282 return
281283 }
282284
283- // The actual token is only returned on creation.
285+ // The actual token is only returned once during initial creation
284286 data .Token = types .StringValue (token .Token )
285287
286288 // Save data into Terraform state
@@ -302,7 +304,12 @@ func (r *personalAccessTokenResource) Read(ctx context.Context, req resource.Rea
302304 }
303305
304306 // Use Forgejo client to get personal access token
305- token , diags := getPersonalAccessToken (ctx , r .client , data .User .ValueString (), data .Name .ValueString ())
307+ token , diags := getPersonalAccessToken (
308+ ctx ,
309+ r .client ,
310+ data .User .ValueString (),
311+ data .Name .ValueString (),
312+ )
306313 resp .Diagnostics .Append (diags ... )
307314 if resp .Diagnostics .HasError () {
308315 return
@@ -368,14 +375,16 @@ func (r *personalAccessTokenResource) Delete(ctx context.Context, req resource.D
368375 switch res .StatusCode {
369376 case 403 :
370377 msg = fmt .Sprintf (
371- "User %s forbidden: %s" ,
378+ "Personal access token with user %s and ID %d forbidden: %s" ,
372379 data .User .String (),
380+ data .ID .ValueInt64 (),
373381 err ,
374382 )
375383 case 404 :
376384 msg = fmt .Sprintf (
377- "User %s not found: %s" ,
385+ "Personal access token with user %s and ID %d not found: %s" ,
378386 data .User .String (),
387+ data .ID .ValueInt64 (),
379388 err ,
380389 )
381390 case 422 :
@@ -388,7 +397,7 @@ func (r *personalAccessTokenResource) Delete(ctx context.Context, req resource.D
388397 )
389398 }
390399 }
391- resp .Diagnostics .AddError ("Unable to delete deploy key " , msg )
400+ resp .Diagnostics .AddError ("Unable to delete personal access token " , msg )
392401}
393402
394403// NewpersonalAccessTokenResource is a helper function to simplify the provider implementation.
0 commit comments