configstore: create token only if it doesn't exists

This commit is contained in:
Simone Gotti 2019-04-05 15:06:26 +02:00
parent c4310be7de
commit 200aef20b9

View File

@ -660,6 +660,11 @@ func (s *CommandHandler) CreateUserToken(ctx context.Context, userName, tokenNam
if err != nil {
return "", err
}
if user.Tokens != nil {
if _, ok := user.Tokens[tokenName]; ok {
return "", util.NewErrBadRequest(errors.Errorf("token %q for user %q already exists", tokenName, userName))
}
}
if user.Tokens == nil {
user.Tokens = make(map[string]string)