diff --git a/management/server/account.go b/management/server/account.go index 6714e6e1a9d..9f8e10e6c7a 100644 --- a/management/server/account.go +++ b/management/server/account.go @@ -3,11 +3,11 @@ package server import ( "github.com/google/uuid" log "github.com/sirupsen/logrus" + "github.com/wiretrustee/wiretrustee/util" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "net" "sync" - "time" ) type AccountManager struct { @@ -35,16 +35,21 @@ func NewManager(store Store, peersUpdateManager *PeersUpdateManager) *AccountMan } //AddSetupKey generates a new setup key with a given name and type, and adds it to the specified account -func (am *AccountManager) AddSetupKey(accountId string, keyName string, keyType SetupKeyType, expiresIn time.Duration) (*SetupKey, error) { +func (am *AccountManager) AddSetupKey(accountId string, keyName string, keyType SetupKeyType, expiresIn *util.Duration) (*SetupKey, error) { am.mux.Lock() defer am.mux.Unlock() + keyDuration := DefaultSetupKeyDuration + if expiresIn != nil { + keyDuration = expiresIn.Duration + } + account, err := am.Store.GetAccount(accountId) if err != nil { return nil, status.Errorf(codes.NotFound, "account not found") } - setupKey := GenerateSetupKey(keyName, keyType, expiresIn) + setupKey := GenerateSetupKey(keyName, keyType, keyDuration) account.SetupKeys[setupKey.Key] = setupKey err = am.Store.SaveAccount(account) diff --git a/management/server/http/handler/setupkeys.go b/management/server/http/handler/setupkeys.go index ba1a44c9f61..bbd8bbe9a21 100644 --- a/management/server/http/handler/setupkeys.go +++ b/management/server/http/handler/setupkeys.go @@ -5,6 +5,7 @@ import ( "github.com/gorilla/mux" log "github.com/sirupsen/logrus" "github.com/wiretrustee/wiretrustee/management/server" + "github.com/wiretrustee/wiretrustee/util" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "net/http" @@ -34,7 +35,7 @@ type SetupKeyResponse struct { type SetupKeyRequest struct { Name string Type server.SetupKeyType - ExpiresIn Duration + ExpiresIn *util.Duration Revoked bool } @@ -102,7 +103,7 @@ func (h *SetupKeys) createKey(accountId string, w http.ResponseWriter, r *http.R return } - setupKey, err := h.accountManager.AddSetupKey(accountId, req.Name, req.Type, req.ExpiresIn.Duration) + setupKey, err := h.accountManager.AddSetupKey(accountId, req.Name, req.Type, req.ExpiresIn) if err != nil { errStatus, ok := status.FromError(err) if ok && errStatus.Code() == codes.NotFound {