Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(apikey): adds command to delete api keys #1702

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

pallabpain
Copy link
Contributor

@pallabpain pallabpain commented Jan 27, 2024

Description

We currently do not have a way to clean up api keys. There may be cases where users of headscale may generate a lot of api keys and these may end up accumulating in the database. This commit adds the command to delete an api key given a prefix.

Usage

→ hs apikeys --help
Handle the Api keys in Headscale

Usage:
  headscale apikeys [command]

Aliases:
  apikeys, apikey, api

Available Commands:
  create      Creates a new Api key
  delete      Delete an ApiKey
  expire      Expire an ApiKey
  list        List the Api keys for headscale

Flags:
  -h, --help   help for apikeys

Global Flags:
  -c, --config string   config file (default is /etc/headscale/config.yaml)
      --force           Disable prompts and forces the execution
  -o, --output string   Output format. Empty for human-readable, 'json', 'json-line' or 'yaml'

Use "headscale apikeys [command] --help" for more information about a command.

→ hs apikeys delete --help
Delete an ApiKey

Usage:
  headscale apikeys delete [flags]

Aliases:
  delete, remove, del

Flags:
  -h, --help            help for delete
  -p, --prefix string   ApiKey prefix

Global Flags:
  -c, --config string   config file (default is /etc/headscale/config.yaml)
      --force           Disable prompts and forces the execution
  -o, --output string   Output format. Empty for human-readable, 'json', 'json-line' or 'yaml'

Testing

Manual

04:16:58 pallab@pop-os headscale ±|feat/delete-apikeys ✗|
→ sudo ./headscale apikeys create -e 9d --config config.yaml
uYZ927_pGw.2BjBph-ncqd5ZFM1_cISVgjEUkHA8fj-vOYn3WuaZ3Y

04:17:06 pallab@pop-os headscale ±|feat/delete-apikeys ✗|
→ sudo ./headscale apikeys ls --config config.yaml 
ID | Prefix     | Expiration          | Created
1  | uYZ927_pGw | 2024-02-06 10:47:06 | 2024-01-28 10:47:06

04:17:09 pallab@pop-os headscale ±|feat/delete-apikeys ✗|
→ alias hs='sudo ./headscale --config config.yaml'

04:17:39 pallab@pop-os headscale ±|feat/delete-apikeys ✗|
→ hs apikeys ls
ID | Prefix     | Expiration          | Created
1  | uYZ927_pGw | 2024-02-06 10:47:06 | 2024-01-28 10:47:06

04:17:44 pallab@pop-os headscale ±|feat/delete-apikeys ✗|
→ hs apikeys delete --prefix uYZ927_pGw
Key deleted

04:17:54 pallab@pop-os headscale ±|feat/delete-apikeys ✗|
→ hs apikeys ls
ID | Prefix | Expiration | Created
  • read the CONTRIBUTING guidelines
  • raised a GitHub issue or discussed it on the projects chat beforehand
  • added unit tests
  • added integration tests
  • updated documentation if needed
  • updated CHANGELOG.md

Resolves

Depends

@pallabpain pallabpain marked this pull request as draft January 27, 2024 19:38
@pallabpain pallabpain marked this pull request as ready for review January 28, 2024 10:50
@pallabpain pallabpain changed the title feat: adds command to delete api keys ✨ feat: adds command to delete api keys Jan 28, 2024
@pallabpain pallabpain changed the title ✨ feat: adds command to delete api keys ✨ feat(apikey): adds command to delete api keys Jan 28, 2024
@kradalby
Copy link
Collaborator

I think this looks reasonable, but I would prefer to get in the db changes I have a pr up for first (transactions).

@pallabpain
Copy link
Contributor Author

I think this looks reasonable, but I would prefer to get in the db changes I have a pr up for first (transactions).

Sounds good to me.

@pallabpain pallabpain force-pushed the feat/delete-apikeys branch 5 times, most recently from 7c0b202 to 7c33fa8 Compare February 10, 2024 08:31
@kradalby
Copy link
Collaborator

Could you add a test for this in integrations/cli_test.go ?, otherwise looks sensible.

We currently do not have a way to clean up api keys. There may be cases
where users of headscale may generate a lot of api keys and these may
end up accumulating in the database. This commit adds the command to
delete an api key given a prefix.
@pallabpain
Copy link
Contributor Author

Could you add a test for this in integrations/cli_test.go ?, otherwise looks sensible.

@kradalby Done. Please review.

@kradalby kradalby merged commit 4740593 into juanfont:main Feb 12, 2024
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants