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

Last Used field on API tokens #9536

Closed
PieterL75 opened this issue Jun 15, 2022 · 4 comments · Fixed by #9554
Closed

Last Used field on API tokens #9536

PieterL75 opened this issue Jun 15, 2022 · 4 comments · Fixed by #9554
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@PieterL75
Copy link
Contributor

NetBox version

v3.2.3

Feature type

Change to existing functionality

Proposed functionality

Add a 'Last used' property to the API token

Use case

I want to know if a token is actively being used.

Database changes

Add 'Last used' field (datetime) to 'users_token'

External dependencies

No response

@PieterL75 PieterL75 added the type: feature Introduction of new functionality to the application label Jun 15, 2022
@jeremystretch
Copy link
Member

This is an interesting idea. My only concern is the introduction of an additional database query, but I wonder if it can be combined somehow with the existing auth query. 🤔

@jeremystretch jeremystretch added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Jun 15, 2022
@PieterL75
Copy link
Contributor Author

@jeremystretch I have PR ready.
It adds the new field to the model, and updates the last_used when the TokenAuthentication.authenticate_credentials is called.

It does introduce a write for each API call., so it only update once a minute..

@sdktr
Copy link
Contributor

sdktr commented Jun 17, 2022

Does it stil work when netbox is run in maintenance/readonly mode?

@PieterL75
Copy link
Contributor Author

@sdktr Any request with an API key will update the last_used field, independent of the accesslevel of the API token or state of Netbox

But when reading the docs https://docs.netbox.dev/en/stable/configuration/dynamic-settings/#maintenance_mode and this comment #6219 , I think we should not update the last_used field when in maintenance mode.

Thank you for pointing that out, I'll update the PR

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Jun 21, 2022
@jeremystretch jeremystretch added this to the v3.3 milestone Jun 21, 2022
jeremystretch added a commit that referenced this issue Jun 23, 2022
Closes #9536: Last Used field on API tokens
@jeremystretch jeremystretch self-assigned this Jun 23, 2022
jeremystretch added a commit that referenced this issue Jun 23, 2022
jeremystretch added a commit that referenced this issue Jun 23, 2022
Closes #9536: Record last used time for API tokens
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants