Token example does not do what is expected. #32

Closed
opened 2023-10-23 14:07:12 +00:00 by tobiasbp · 0 comments
Contributor

Describe the bug
The token example shows how to create a token for a user. However, that is not the
result of running the example. The token will created for the user defined in var.gitea_user, not the
user created in the example.

Here is the relevant code in the Gitea SDK. The username from the client (the authenticated user) is used to create the path /users/<username>/tokens.
The username supplied in the token resource is not used for anything, only the name of the token is used with the API.

The current token example:

provider "gitea" {
  base_url = var.gitea_url
  # Token Auth can not be used with this resource
  username = var.gitea_username
  password = var.gitea_password
}

resource "gitea_user" "test" {
  username             = "test"
  login_name           = "test"
  password             = "Geheim1!"
  email                = "test@user.dev"
  must_change_password = false
  admin                = true
}

resource "gitea_token" "test_token" {
  username = resource.gitea_user.test.username
  name     = "test-token"
}

To Reproduce
Run the example. The token will be created for the account used to access the API. the test user will have no token.

Expected behavior
The token should be created for the test user, not the user accessing the API.

The documentation should be updated, to show who the token will be created for.

  • Provider Version: 0.3.0
**Describe the bug** The _token_ example shows [how to create a token for a user](https://gitea.com/gitea/terraform-provider-gitea/src/branch/main/examples/resources/gitea_token/resource.tf#L18). However, that is not the result of running the example. The _token_ will created for the user defined in _var.gitea_user_, not the [user created in the example](https://gitea.com/gitea/terraform-provider-gitea/src/branch/main/examples/resources/gitea_token/resource.tf#L8). Here is [the relevant code](https://gitea.com/gitea/go-sdk/src/tag/gitea/v0.16.0/gitea/user_app.go#L102) in the Gitea SDK. The username from the _client_ (the authenticated user) is used to [create the path](https://gitea.com/gitea/go-sdk/src/tag/gitea/v0.16.0/gitea/user_app.go#L114) _/users/\<username\>/tokens_. The username supplied in the _token resource_ is not used for anything, only the name of the token [is used with the API](https://gitea.com/gitea/terraform-provider-gitea/src/branch/main/gitea/resource_gitea_token.go#L46). The current _token_ example: ``` provider "gitea" { base_url = var.gitea_url # Token Auth can not be used with this resource username = var.gitea_username password = var.gitea_password } resource "gitea_user" "test" { username = "test" login_name = "test" password = "Geheim1!" email = "test@user.dev" must_change_password = false admin = true } resource "gitea_token" "test_token" { username = resource.gitea_user.test.username name = "test-token" } ``` **To Reproduce** Run the example. The token will be created for the account used to access the API. the _test_ user will have no token. **Expected behavior** The _token_ should be created for the _test_ user, not the user accessing the API. The documentation should be updated, to show who the _token_ will be created for. - Provider Version: 0.3.0
tobiasbp added the
bug
label 2023-10-23 14:07:12 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: gitea/terraform-provider-gitea#32
No description provided.