Skip to content

Commit ec84d5a

Browse files
committed
usermanager: format by black
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent 891b985 commit ec84d5a

1 file changed

Lines changed: 61 additions & 52 deletions

File tree

scripts/usermanager.py

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
DEFAULT_CONFIG_PATHS = [
1818
os.path.join(os.getcwd(), "usermanager.toml"),
19-
os.path.join(os.path.expanduser("~"), ".config", "kernelci",
20-
"usermanager.toml"),
19+
os.path.join(os.path.expanduser("~"), ".config", "kernelci", "usermanager.toml"),
2120
]
2221

2322

@@ -138,7 +137,8 @@ def _resolve_user_id(user_id, api_url, token):
138137
if not isinstance(payload, list):
139138
raise SystemExit("Unexpected users response")
140139
matches = [
141-
user for user in payload
140+
user
141+
for user in payload
142142
if isinstance(user, dict) and user.get("email") == user_id
143143
]
144144
if not matches:
@@ -163,8 +163,7 @@ def _request_json(method, url, data=None, token=None, form=False):
163163
headers["Content-Type"] = "application/json"
164164
if token:
165165
headers["Authorization"] = f"Bearer {token}"
166-
req = urllib.request.Request(url, data=body, headers=headers,
167-
method=method)
166+
req = urllib.request.Request(url, data=body, headers=headers, method=method)
168167
try:
169168
with urllib.request.urlopen(req) as response:
170169
payload = response.read().decode("utf-8")
@@ -218,12 +217,14 @@ def main():
218217
"--config",
219218
help="Path to usermanager.toml (defaults to first match in the lookup list below)",
220219
)
221-
parser.add_argument("--api-url", help="API base URL, e.g. "
222-
"http://localhost:8001/latest")
220+
parser.add_argument(
221+
"--api-url", help="API base URL, e.g. " "http://localhost:8001/latest"
222+
)
223223
parser.add_argument("--token", help="Bearer token for admin/user actions")
224224
parser.add_argument("--instance", help="Instance name from config")
225-
parser.add_argument("--token-label", default="Auth",
226-
help="Label used when prompting for a token")
225+
parser.add_argument(
226+
"--token-label", default="Auth", help="Label used when prompting for a token"
227+
)
227228

228229
subparsers = parser.add_subparsers(dest="command", required=True)
229230

@@ -237,8 +238,7 @@ def main():
237238
invite.add_argument("--return-token", action="store_true")
238239
invite.add_argument("--resend-if-exists", action="store_true")
239240

240-
invite_url = subparsers.add_parser("invite-url",
241-
help="Preview invite URL base")
241+
invite_url = subparsers.add_parser("invite-url", help="Preview invite URL base")
242242

243243
accept = subparsers.add_parser("accept-invite", help="Accept an invite")
244244
accept.add_argument("--token")
@@ -255,34 +255,40 @@ def main():
255255
get_user = subparsers.add_parser("get-user", help="Get user by id")
256256
get_user.add_argument("user_id")
257257

258-
update_user = subparsers.add_parser("update-user",
259-
help="Patch user by id")
258+
update_user = subparsers.add_parser("update-user", help="Patch user by id")
260259
update_user.add_argument("user_id")
261-
update_user.add_argument("--data",
262-
help="JSON object with fields to update")
260+
update_user.add_argument("--data", help="JSON object with fields to update")
263261
update_user.add_argument("--username", help="Set username")
264262
update_user.add_argument("--email", help="Set email")
265263
update_user.add_argument("--password", help="Set password")
266-
update_user.add_argument("--superuser", dest="is_superuser",
267-
action="store_true",
268-
help="Grant superuser")
269-
update_user.add_argument("--no-superuser", dest="is_superuser",
270-
action="store_false",
271-
help="Revoke superuser")
272-
update_user.add_argument("--active", dest="is_active",
273-
action="store_true",
274-
help="Set is_active true")
275-
update_user.add_argument("--inactive", dest="is_active",
276-
action="store_false",
277-
help="Set is_active false")
278-
update_user.add_argument("--verified", dest="is_verified",
279-
action="store_true",
280-
help="Set is_verified true")
281-
update_user.add_argument("--unverified", dest="is_verified",
282-
action="store_false",
283-
help="Set is_verified false")
284-
update_user.set_defaults(is_active=None, is_verified=None,
285-
is_superuser=None)
264+
update_user.add_argument(
265+
"--superuser", dest="is_superuser", action="store_true", help="Grant superuser"
266+
)
267+
update_user.add_argument(
268+
"--no-superuser",
269+
dest="is_superuser",
270+
action="store_false",
271+
help="Revoke superuser",
272+
)
273+
update_user.add_argument(
274+
"--active", dest="is_active", action="store_true", help="Set is_active true"
275+
)
276+
update_user.add_argument(
277+
"--inactive", dest="is_active", action="store_false", help="Set is_active false"
278+
)
279+
update_user.add_argument(
280+
"--verified",
281+
dest="is_verified",
282+
action="store_true",
283+
help="Set is_verified true",
284+
)
285+
update_user.add_argument(
286+
"--unverified",
287+
dest="is_verified",
288+
action="store_false",
289+
help="Set is_verified false",
290+
)
291+
update_user.set_defaults(is_active=None, is_verified=None, is_superuser=None)
286292
update_user.add_argument(
287293
"--set-groups",
288294
help="Replace all groups with a comma-separated list",
@@ -300,24 +306,24 @@ def main():
300306
help="Remove group(s); can be used multiple times or with commas",
301307
)
302308

303-
delete_user = subparsers.add_parser("delete-user",
304-
help="Delete user by id")
309+
delete_user = subparsers.add_parser("delete-user", help="Delete user by id")
305310
delete_user.add_argument("user_id")
306311

307-
subparsers.add_parser("print-config-example",
308-
help="Print a sample usermanager.toml")
312+
subparsers.add_parser(
313+
"print-config-example", help="Print a sample usermanager.toml"
314+
)
309315

310316
args = parser.parse_args()
311317

312318
if args.command == "print-config-example":
313319
print(
314-
"default_instance = \"local\"\n\n"
320+
'default_instance = "local"\n\n'
315321
"[instances.local]\n"
316-
"url = \"http://localhost:8001/latest\"\n"
317-
"token = \"<admin-or-user-token>\"\n\n"
322+
'url = "http://localhost:8001/latest"\n'
323+
'token = "<admin-or-user-token>"\n\n'
318324
"[instances.staging]\n"
319-
"url = \"https://staging.kernelci.org:9000/latest\"\n"
320-
"token = \"<admin-or-user-token>\"\n"
325+
'url = "https://staging.kernelci.org:9000/latest"\n'
326+
'token = "<admin-or-user-token>"\n'
321327
)
322328
return
323329

@@ -348,8 +354,15 @@ def main():
348354
if not token:
349355
token = _get_setting(None, "KCI_API_TOKEN", config, "api.token")
350356

351-
if args.command in {"invite", "invite-url", "whoami", "list-users",
352-
"get-user", "update-user", "delete-user"}:
357+
if args.command in {
358+
"invite",
359+
"invite-url",
360+
"whoami",
361+
"list-users",
362+
"get-user",
363+
"update-user",
364+
"delete-user",
365+
}:
353366
token = _require_token(token, args)
354367

355368
if args.command == "invite":
@@ -367,9 +380,7 @@ def main():
367380
"POST", f"{api_url}/user/invite", payload, token=token
368381
)
369382
elif args.command == "invite-url":
370-
status, body = _request_json(
371-
"GET", f"{api_url}/user/invite/url", token=token
372-
)
383+
status, body = _request_json("GET", f"{api_url}/user/invite/url", token=token)
373384
elif args.command == "accept-invite":
374385
invite_token = _prompt_if_missing(
375386
args.token,
@@ -382,9 +393,7 @@ def main():
382393
secret=True,
383394
)
384395
payload = {"token": invite_token, "password": password}
385-
status, body = _request_json(
386-
"POST", f"{api_url}/user/accept-invite", payload
387-
)
396+
status, body = _request_json("POST", f"{api_url}/user/accept-invite", payload)
388397
elif args.command == "login":
389398
password = _prompt_if_missing(
390399
args.password,

0 commit comments

Comments
 (0)