Jigsaw-Code / outline-apps

Outline Client and Manager, developed by Jigsaw. Outline Manager makes it easy to create your own VPN server. Outline Client lets you share access to your VPN with anyone in your network, giving them access to the free and open internet.
https://getoutline.org/
Apache License 2.0
8.39k stars 1.36k forks source link

Deleting and re-creating a key with the same ID preserves usage information #2081

Open digitalberd opened 1 month ago

digitalberd commented 1 month ago

Hello! I created key on server with client.create_key(key_id='123', name=name, data_limit=data_limit_gb) After that I used some trafic by this key - and have used_bytes = X in key After that I delete this key with client.delete_key('123') And after that I created this key again with client.create_key(key_id='123', name=name, data_limit=data_limit_gb)

And I have a problem: new key with id equal old id - '123' - have used_bytes not 0 - it have X used bytes.

digitalberd commented 1 month ago

new_key = client.create_key(key_id='123', name=name, data_limit=data_limit_gb) new_key.used_bytes = 0 BUT KEY = client.get_key('123') KEY.used_bytes = X (can be some gigabytes - what was used by old key, before delete key)

digitalberd commented 1 month ago

I think, it becouse: def init(self, response: dict, metrics: dict = None): self.key_id = response.get("id") self.name = response.get("name") self.password = response.get("password") self.port = response.get("port") self.method = response.get("method") self.access_url = response.get("accessUrl") self.used_bytes = ( metrics.get("bytesTransferredByUserId").get(response.get("id")) if metrics else 0 ) self.data_limit = response.get("dataLimit", {}).get("bytes")

fortuna commented 1 month ago

If you use the same ID, the server interprets as the same user. If it's a new user, you can use a new id.

maddyhof commented 1 month ago

The open feature request for manually resetting the usage information would help with this #1860.