mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-21 23:20:24 +00:00
REST cli: allow to disable password or public_key auth
using something like this: update-user <user-id> <username> --public-keys '' the public keys auth will be disabled using something like this: update-user <user-id> <username> --password '' the password auth will be disabled
This commit is contained in:
parent
6aff8c2f5e
commit
741e65a3a1
2 changed files with 8 additions and 5 deletions
|
@ -74,6 +74,7 @@ func getUserByID(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
func addUser(w http.ResponseWriter, r *http.Request) {
|
||||
var user dataprovider.User
|
||||
user.PublicKeys = []string{}
|
||||
err := render.DecodeJSON(r.Body, &user)
|
||||
if err != nil {
|
||||
sendAPIResponse(w, r, err, "", http.StatusBadRequest)
|
||||
|
@ -84,7 +85,6 @@ func addUser(w http.ResponseWriter, r *http.Request) {
|
|||
user, err = dataprovider.UserExists(dataProvider, user.Username)
|
||||
if err == nil {
|
||||
user.Password = ""
|
||||
user.PublicKeys = []string{}
|
||||
render.JSON(w, r, user)
|
||||
} else {
|
||||
sendAPIResponse(w, r, err, "", http.StatusInternalServerError)
|
||||
|
|
|
@ -69,10 +69,13 @@ class SFTPGoApiRequests:
|
|||
"max_sessions":max_sessions, "quota_size":quota_size, "quota_files":quota_files,
|
||||
"upload_bandwidth":upload_bandwidth, "download_bandwidth":download_bandwidth,
|
||||
"status":status, "expiration_date":expiration_date}
|
||||
if password:
|
||||
if password is not None:
|
||||
user.update({"password":password})
|
||||
if public_keys:
|
||||
user.update({"public_keys":public_keys})
|
||||
if len(public_keys) == 1 and not public_keys[0]:
|
||||
user.update({"public_keys":[]})
|
||||
else:
|
||||
user.update({"public_keys":public_keys})
|
||||
if home_dir:
|
||||
user.update({"home_dir":home_dir})
|
||||
if permissions:
|
||||
|
@ -180,7 +183,7 @@ def getDatetimeAsMillisSinceEpoch(dt):
|
|||
|
||||
def addCommonUserArguments(parser):
|
||||
parser.add_argument('username', type=str)
|
||||
parser.add_argument('-P', '--password', type=str, default="", help='Default: %(default)s')
|
||||
parser.add_argument('-P', '--password', type=str, default=None, help='Default: %(default)s')
|
||||
parser.add_argument('-K', '--public-keys', type=str, nargs='+', default=[], help='Default: %(default)s')
|
||||
parser.add_argument('-H', '--home-dir', type=str, default="", help='Default: %(default)s')
|
||||
parser.add_argument('--uid', type=int, default=0, help='Default: %(default)s')
|
||||
|
@ -269,7 +272,7 @@ if __name__ == '__main__':
|
|||
|
||||
parserLoadData = subparsers.add_parser('loaddata', help='Restore SFTPGo data from a JSON backup')
|
||||
parserLoadData.add_argument('input_file', type=str)
|
||||
parserLoadData.add_argument('-q', '--scan-quota', type=int, choices=[0, 1, 2], default=0,
|
||||
parserLoadData.add_argument('-Q', '--scan-quota', type=int, choices=[0, 1, 2], default=0,
|
||||
help='0 means no quota scan after a user is added/updated. 1 means always scan quota. 2 ' +
|
||||
'means scan quota if the user has quota restrictions. Default: %(default)s')
|
||||
|
||||
|
|
Loading…
Reference in a new issue