| 42 | display_attributes = ["user", "token", "expiry"] |
| 43 | |
| 44 | def __init__(self, resource, *args, **kwargs): |
| 45 | |
| 46 | kwargs["has_token_opt"] = False |
| 47 | |
| 48 | super(TokenCreateCommand, self).__init__( |
| 49 | resource, |
| 50 | kwargs.pop("name", "create"), |
| 51 | "Authenticate user and acquire access token.", |
| 52 | *args, |
| 53 | **kwargs, |
| 54 | ) |
| 55 | |
| 56 | self.parser.add_argument("username", help="Name of the user to authenticate.") |
| 57 | |
| 58 | self.parser.add_argument( |
| 59 | "-p", |
| 60 | "--password", |
| 61 | dest="password", |
| 62 | help="Password for the user. If password is not provided, " |
| 63 | "it will be prompted for.", |
| 64 | ) |
| 65 | self.parser.add_argument( |
| 66 | "-l", |
| 67 | "--ttl", |
| 68 | type=int, |
| 69 | dest="ttl", |
| 70 | default=None, |
| 71 | help="The life span of the token in seconds. " |
| 72 | "Max TTL configured by the admin supersedes this.", |
| 73 | ) |
| 74 | self.parser.add_argument( |
| 75 | "-t", |
| 76 | "--only-token", |
| 77 | action="store_true", |
| 78 | dest="only_token", |
| 79 | default=False, |
| 80 | help="On successful authentication, print only token to the " "console.", |
| 81 | ) |
| 82 | |
| 83 | def run(self, args, **kwargs): |
| 84 | if not args.password: |