From a98d784ce44140e4b93ef9c627364bbbb5553578 Mon Sep 17 00:00:00 2001 From: meejah Date: Mon, 23 Nov 2020 17:36:50 -0700 Subject: [PATCH] timedelta, not seconds --- src/allmydata/cli/grid_manager.py | 2 ++ src/allmydata/grid_manager.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/allmydata/cli/grid_manager.py b/src/allmydata/cli/grid_manager.py index a5e0ee09a..8e561d36a 100644 --- a/src/allmydata/cli/grid_manager.py +++ b/src/allmydata/cli/grid_manager.py @@ -1,5 +1,6 @@ from datetime import ( datetime, + timedelta, ) import json @@ -120,6 +121,7 @@ def add(ctx, name, public_key): save_grid_manager( _config_path_from_option(ctx.parent.params["config"]), ctx.obj.grid_manager, + create=False, ) return 0 diff --git a/src/allmydata/grid_manager.py b/src/allmydata/grid_manager.py index 71395fd11..d3256813d 100644 --- a/src/allmydata/grid_manager.py +++ b/src/allmydata/grid_manager.py @@ -185,14 +185,25 @@ class _GridManager(object): def public_identity(self): return ed25519.string_from_verifying_key(self._public_key) - def sign(self, name, expiry_seconds): + def sign(self, name, expiry): + """ + Create a new signed certificate for a particular server + + :param str name: the server to create a certificate for + + :param timedelta expiry: how far in the future the certificate + should expire. + + :returns: a dict defining the certificate (it has + "certificate" and "signature" keys). + """ try: srv = self._storage_servers[name] except KeyError: raise KeyError( "No storage server named '{}'".format(name) ) - expiration = datetime.utcnow() + timedelta(seconds=expiry_seconds) + expiration = datetime.utcnow() + expiry epoch_offset = (expiration - datetime(1970, 1, 1)).total_seconds() cert_info = { "expires": epoch_offset,