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

Write token file upon refresh #54

Open
RichieB2B opened this issue Sep 29, 2023 · 10 comments · May be fixed by #63
Open

Write token file upon refresh #54

RichieB2B opened this issue Sep 29, 2023 · 10 comments · May be fixed by #63
Assignees

Comments

@RichieB2B
Copy link
Contributor

I just started using the new OAuth using the toke file. It works great, thanks!
I did notice however that the token file is only written when netatmo-explorer exists. I think it would be better to save the new tokens every time they are refreshed. In case of a crash the new tokens are currently lost.

@xperimental
Copy link
Owner

Currently the token rotation is completely handled by the oauth library I use, so the "netatmo-exporter code" does not know when a refresh actually happens, it is completely transparent to it. It just reads the (possibly changed) token from the library on exit.

Saving the token on change / periodically is something I had thought about before as well, but did not get to implementing so far.

@RichieB2B
Copy link
Contributor Author

Perhaps you can check if the expiry has changed and only save the token file when it has. Once every few minutes should be enough.

@xperimental
Copy link
Owner

@RichieB2B Just realized something: I think the more important question for me is: why did it crash? Do you have any logs of the crash that we can use to fix that issue?

@RichieB2B
Copy link
Contributor Author

netatmo-exporter doesn't crash often, the last time was 6 months and many versions ago. Not worth investigating now. It's just that you can't count on a clean process exit 100% of the time.

@xperimental
Copy link
Owner

Ok. I thought this occurred to you because of a recent crash and was worried there might be a bigger issue here than just "does not save token". 😌

I do know that there's no "100% stable" but I surely try to make it as reliable as possible 🙂

@xperimental
Copy link
Owner

It looks to me as if more people are experiencing errors writing the token file on shutdown (see mentioned issue).

I have come around to implementing a "save on token change" mechanism, but I am still looking at how to integrate this into the existing code. The token handling is done in the oauth2 library and not my own code, so I'll have to move around a few bits first.

@szermatt
Copy link

szermatt commented Sep 11, 2024

I have the same problem, usually caused by power outages, which are unfortunately very common.

I fixed it for now with the following (draft) changes:
xperimental/netatmo-api-go@master...szermatt:netatmo-api-go:savetoken
master...szermatt:netatmo-exporter:savetoken

It modifies your copy of netatmo-api-go; I couldn't see an alternative. I do wonder whether it wouldn't be more straightforward to just do the oauth2 stuff inside netatmo-exporter.

I was getting ready to send them out, but you're already working on it, so I just thought I'd send them out FYI. Feel free to disregard them completely, to copy from them, or, if you prefer, let me know if I should clean them up and sent out pull request for a real review.

Thanks!

@xperimental
Copy link
Owner

@szermatt Thanks for the contribution. I'm currently on vacation, but I'll have a look once I'm back home.

@xperimental xperimental linked a pull request Oct 13, 2024 that will close this issue
@xperimental
Copy link
Owner

Finally found the time to get this in.

Please have a look at the PR and test if this works properly. There's also a testing image available:

ghcr.io/xperimental/netatmo-exporter:save-token

@RichieB2B
Copy link
Contributor Author

RichieB2B commented Oct 14, 2024

I've been running this version since this morning and it working great. It updates the stored JSON every hour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants