add -u and -p option to login commnand.

This commit is contained in:
Yoshihiro OKUMURA 2024-02-09 18:22:13 +09:00
parent ce0a608db2
commit c3e2dfbd8e
Signed by: orrisroot
GPG Key ID: 470AA444C92904B2
3 changed files with 55 additions and 51 deletions

View File

@ -4,7 +4,7 @@ The mdrs-client-python is python library and a command-line client for up- and d
## Installing ## Installing
``` ```shell
poetry install poetry install
``` ```
@ -14,141 +14,143 @@ poetry install
Create remote host configuration Create remote host configuration
``` ```shell
$ mdrs config create neurodata https://neurodata.riken.jp/api mdrs config create neurodata https://neurodata.riken.jp/api
``` ```
### login ### login
Login to remote host Login to remote host
``` ```shell
$ mdrs login neurodata: mdrs login neurodata:
Username: (enter your login name) Username: (enter your login name)
Password: (enter your password) Password: (enter your password)
mdrs login -u USERNAME -p PASSWORD neurodata:
``` ```
### logout ### logout
Logout from remote host Logout from remote host
``` ```shell
$ mdrs logout neurodata: mdrs logout neurodata:
``` ```
### whoami ### whoami
Print current user name Print current user name
``` ```shell
$ mdrs whoami neurodata: mdrs whoami neurodata:
``` ```
### labs ### labs
List all laboratories List all laboratories
``` ```shell
$ mdrs labs neurodata: mdrs labs neurodata:
``` ```
### ls ### ls
List the folder contents List the folder contents
``` ```shell
$ mdrs ls neurodata:/NIU/Repository/ mdrs ls neurodata:/NIU/Repository/
$ mdrs ls -p PW_OPEN_PASSWORD neurodata:/NIU/Repository/PW_Open/ mdrs ls -p PW_OPEN_PASSWORD neurodata:/NIU/Repository/PW_Open/
$ mdrs ls -r neurodata:/NIU/Repository/Dataset1/ mdrs ls -r neurodata:/NIU/Repository/Dataset1/
$ mdrs ls -J -r neurodata:/NIU/Repository/Dataset1/ mdrs ls -J -r neurodata:/NIU/Repository/Dataset1/
``` ```
### mkdir ### mkdir
Create a new folder Create a new folder
``` ```shell
$ mdrs mkdir neurodata:/NIU/Repository/TEST mdrs mkdir neurodata:/NIU/Repository/TEST
``` ```
### upload ### upload
Upload the file or directory Upload the file or directory
``` ```shell
$ mdrs upload ./sample.dat neurodata:/NIU/Repository/TEST/ mdrs upload ./sample.dat neurodata:/NIU/Repository/TEST/
$ mdrs upload -r ./dataset neurodata:/NIU/Repository/TEST/ mdrs upload -r ./dataset neurodata:/NIU/Repository/TEST/
``` ```
### download ### download
Download the file or folder Download the file or folder
``` ```shell
$ mdrs download neurodata:/NIU/Repository/TEST/sample.dat ./ mdrs download neurodata:/NIU/Repository/TEST/sample.dat ./
$ mdrs download -r neurodata:/NIU/Repository/TEST/dataset/ ./ mdrs download -r neurodata:/NIU/Repository/TEST/dataset/ ./
$ mdrs download -p PW_OPEN_PASSWORD neurodata:/NIU/Repository/PW_Open/Readme.dat ./ mdrs download -p PW_OPEN_PASSWORD neurodata:/NIU/Repository/PW_Open/Readme.dat ./
``` ```
### mv ### mv
Move or rename the file or folder Move or rename the file or folder
``` ```shell
$ mdrs mv neurodata:/NIU/Repository/TEST/sample.dat neurodata:/NIU/Repository/TEST2/sample2.dat mdrs mv neurodata:/NIU/Repository/TEST/sample.dat neurodata:/NIU/Repository/TEST2/sample2.dat
$ mdrs mv neurodata:/NIU/Repository/TEST/dataset neurodata:/NIU/Repository/TEST2/ mdrs mv neurodata:/NIU/Repository/TEST/dataset neurodata:/NIU/Repository/TEST2/
``` ```
### cp ### cp
Copy the file and folder Copy the file and folder
``` ```shell
$ mdrs cp neurodata:/NIU/Repository/TEST/sample.dat neurodata:/NIU/Repository/TEST2/sample2.dat mdrs cp neurodata:/NIU/Repository/TEST/sample.dat neurodata:/NIU/Repository/TEST2/sample2.dat
$ mdrs cp -r neurodata:/NIU/Repository/TEST/dataset neurodata:/NIU/Repository/TEST2/ mdrs cp -r neurodata:/NIU/Repository/TEST/dataset neurodata:/NIU/Repository/TEST2/
``` ```
### rm ### rm
Remove the file or folder Remove the file or folder
``` ```shell
$ mdrs rm neurodata:/NIU/Repository/TEST2/sample2.dat mdrs rm neurodata:/NIU/Repository/TEST2/sample2.dat
$ mdrs rm -r neurodata:/NIU/Repository/TEST2/dataset mdrs rm -r neurodata:/NIU/Repository/TEST2/dataset
``` ```
### chacl ### chacl
Change the folder access level Change the folder access level
``` ```shell
$ mdrs chacl private neurodata:/NIU/Repository/Private mdrs chacl private neurodata:/NIU/Repository/Private
$ mdrs chacl cbs_open -r neurodata:/NIU/Repository/CBS_Open mdrs chacl cbs_open -r neurodata:/NIU/Repository/CBS_Open
$ mdrs chacl pw_open -r -p FOLDER_PASSWORD neurodata:/NIU/Repository/PW_Open mdrs chacl pw_open -r -p FOLDER_PASSWORD neurodata:/NIU/Repository/PW_Open
``` ```
### metadata ### metadata
Get a folder metadata Get a folder metadata
``` ```shell
$ mdrs metadata neurodata:/NIU/Repository/TEST/ mdrs metadata neurodata:/NIU/Repository/TEST/
$ mdrs metadata -p PW_OPEN_PASSWORD neurodata:/NIU/Repository/PW_Open/ mdrs metadata -p PW_OPEN_PASSWORD neurodata:/NIU/Repository/PW_Open/
``` ```
### file-metadata ### file-metadata
Get the file metadata Get the file metadata
``` ```shell
$ mdrs file-metadata neurodata:/NIU/Repository/TEST/dataset/sample.dat mdrs file-metadata neurodata:/NIU/Repository/TEST/dataset/sample.dat
$ mdrs file-metadata -p PW_OPEN_PASSWORD neurodata:/NIU/Repository/PW_Open/Readme.txt mdrs file-metadata -p PW_OPEN_PASSWORD neurodata:/NIU/Repository/PW_Open/Readme.txt
``` ```
### help ### help
Show the help message and exit Show the help message and exit
``` ```shell
$ mdrs -h mdrs -h
``` ```

View File

@ -13,14 +13,16 @@ class LoginCommand(BaseCommand):
@classmethod @classmethod
def register(cls, parsers: Any) -> None: def register(cls, parsers: Any) -> None:
login_parser = parsers.add_parser("login", help="login to remote host") login_parser = parsers.add_parser("login", help="login to remote host")
login_parser.add_argument("-u", "--username", help="login username")
login_parser.add_argument("-p", "--password", help="login password")
login_parser.add_argument("remote", help="label of remote host") login_parser.add_argument("remote", help="label of remote host")
login_parser.set_defaults(func=cls.func) login_parser.set_defaults(func=cls.func)
@classmethod @classmethod
def func(cls, args: Namespace) -> None: def func(cls, args: Namespace) -> None:
remote = str(args.remote) remote = str(args.remote)
username = input("Username: ").strip() username = str(args.username) if args.password else input("Username: ").strip()
password = getpass.getpass("Password: ").strip() password = str(args.password) if args.password else getpass.getpass("Password: ").strip()
cls.login(remote, username, password) cls.login(remote, username, password)
@classmethod @classmethod

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "mdrs-client-python" name = "mdrs-client-python"
version = "1.3.1" version = "1.3.2"
description = "The mdrs-client-python is python library and a command-line client for up- and downloading files to and from MDRS based repository." description = "The mdrs-client-python is python library and a command-line client for up- and downloading files to and from MDRS based repository."
authors = ["Yoshihiro OKUMURA <yoshihiro.okumura@riken.jp>"] authors = ["Yoshihiro OKUMURA <yoshihiro.okumura@riken.jp>"]
license = "MIT" license = "MIT"
@ -30,8 +30,8 @@ PyJWT = "^2.8.0"
validators = "^0.22.0" validators = "^0.22.0"
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]
black = "^23.12.0" black = "^24.1.1"
flake8 = "^6.1.0" flake8 = "^7.0.0"
Flake8-pyproject = "^1.2.3" Flake8-pyproject = "^1.2.3"
isort = "^5.13.0" isort = "^5.13.0"
pyright = "^1.1.339" pyright = "^1.1.339"