timedelta, not seconds

This commit is contained in:
meejah 2020-11-23 17:36:50 -07:00
parent 1e1aad8cc8
commit a98d784ce4
2 changed files with 15 additions and 2 deletions

View File

@ -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

View File

@ -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,