@@ -34,7 +34,7 @@ def db_menu_update_info(ctx: BuilderContext, menu: SingularMenuModel) -> Builder
3434 return ctx
3535
3636
37- def disable_orm (ctx : BuilderContext ) -> MenuEntry :
37+ def disable_orm (ctx : BuilderContext ) -> Optional [ MenuEntry ] :
3838 if ctx .db == "none" :
3939 ctx .orm = "none"
4040 return SKIP_ENTRY
@@ -47,6 +47,12 @@ def do_not_ask_features_if_quite(ctx: BuilderContext) -> Optional[List[MenuEntry
4747 return None
4848
4949
50+ def do_not_ask_features_if_no_users (ctx : BuilderContext ) -> Optional [list [MenuEntry ]]:
51+ if not ctx .add_users :
52+ return [SKIP_ENTRY ]
53+ return None
54+
55+
5056def check_db (allowed_values : List [str ]) -> Callable [[BuilderContext ], bool ]:
5157 def checker (ctx : BuilderContext ) -> bool :
5258 return ctx .db not in allowed_values
@@ -74,7 +80,8 @@ def checker(ctx: BuilderContext) -> bool:
7480 "Choose this option if you want to create a service with {name}.\n "
7581 "It's more suitable for {generic} web-services or services without databases." .format (
7682 name = colored ("REST API" , color = "green" ),
77- generic = colored ("generic" , color = "cyan" , attrs = ["underline" ]),
83+ generic = colored ("generic" , color = "cyan" ,
84+ attrs = ["underline" ]),
7885 )
7986 ),
8087 ),
@@ -145,7 +152,8 @@ def checker(ctx: BuilderContext) -> bool:
145152 "{name} is the most popular database made by oracle.\n "
146153 "It's a good fit for {prod} application." .format (
147154 name = colored ("MySQL" , color = "green" ),
148- prod = colored ("production-grade" , color = "cyan" , attrs = ["underline" ]),
155+ prod = colored ("production-grade" , color = "cyan" ,
156+ attrs = ["underline" ]),
149157 )
150158 ),
151159 additional_info = Database (
@@ -164,7 +172,8 @@ def checker(ctx: BuilderContext) -> bool:
164172 "{name} is second most popular open-source relational database.\n "
165173 "It's a good fit for {prod} application." .format (
166174 name = colored ("PostgreSQL" , color = "green" ),
167- prod = colored ("production-grade" , color = "cyan" , attrs = ["underline" ]),
175+ prod = colored ("production-grade" , color = "cyan" ,
176+ attrs = ["underline" ]),
168177 )
169178 ),
170179 additional_info = Database (
@@ -239,7 +248,8 @@ def checker(ctx: BuilderContext) -> bool:
239248 "If you select this option, you will get only {what}.\n "
240249 "The rest {warn}." .format (
241250 what = colored ("raw database" , color = "green" ),
242- warn = colored ("is up to you" , color = "red" , attrs = ["underline" ]),
251+ warn = colored ("is up to you" , color = "red" ,
252+ attrs = ["underline" ]),
243253 )
244254 ),
245255 ),
@@ -330,7 +340,25 @@ def checker(ctx: BuilderContext) -> bool:
330340 color = "green" ,
331341 ),
332342 purpose1 = colored ("caching" , color = "cyan" ),
333- purpose2 = colored ("storing temporary variables" , color = "cyan" ),
343+ purpose2 = colored (
344+ "storing temporary variables" , color = "cyan" ),
345+ )
346+ ),
347+ ),
348+ MenuEntry (
349+ code = "add_users" ,
350+ cli_name = "add_users" ,
351+ user_view = "Add fastapi-users support" ,
352+ is_hidden = check_orm (["sqlalchemy" ]),
353+ description = (
354+ "{name} is a user management extension.\n "
355+ "Adds {purpose1} JWT or cookie endpoints and {purpose2} models CRUD's." .format (
356+ name = colored (
357+ "Fastapi-users" ,
358+ color = "cyan" ,
359+ ),
360+ purpose1 = colored ("authentication" , color = "cyan" ),
361+ purpose2 = colored ("user" , color = "cyan" ),
334362 )
335363 ),
336364 ),
@@ -383,7 +411,8 @@ def checker(ctx: BuilderContext) -> bool:
383411 "This option will add {what} manifests to your project.\n "
384412 "But this option is {warn}, since if you want to use k8s, please create helm." .format (
385413 what = colored ("kubernetes" , color = "green" ),
386- warn = colored ("deprecated" , color = "red" , attrs = ["underline" ]),
414+ warn = colored ("deprecated" , color = "red" ,
415+ attrs = ["underline" ]),
387416 )
388417 ),
389418 ),
@@ -534,6 +563,42 @@ def checker(ctx: BuilderContext) -> bool:
534563 ],
535564)
536565
566+ users_backend_menu = MultiselectMenuModel (
567+ title = "FastApi Users Backend" ,
568+ code = "users_menu" ,
569+ description = "Available backends for authentication with fastapi_users" ,
570+ multiselect = True ,
571+ before_ask = do_not_ask_features_if_no_users ,
572+ entries = [
573+ MenuEntry (
574+ code = "cookie_auth" ,
575+ cli_name = "cookie auth" ,
576+ user_view = "Add authentication via cookie support" ,
577+ description = (
578+ "Adds {cookie} authentication support." .format (
579+ cookie = colored (
580+ "cookie" ,
581+ color = "green" ,
582+ )
583+ )
584+ ),
585+ ),
586+ MenuEntry (
587+ code = "jwt_auth" ,
588+ cli_name = "jwt auth" ,
589+ user_view = "Add JWT auth support" ,
590+ description = (
591+ "Adds {name} authentication support." .format (
592+ name = colored (
593+ "JWT" ,
594+ color = "green" ,
595+ )
596+ )
597+ ),
598+ ),
599+ ],
600+ )
601+
537602
538603def handle_cli (
539604 menus : List [BaseMenuModel ],
@@ -575,6 +640,7 @@ def run_command(callback: Callable[[BuilderContext], None]) -> None:
575640 orm_menu ,
576641 ci_menu ,
577642 features_menu ,
643+ users_backend_menu ,
578644 ]
579645
580646 cmd = Command (
0 commit comments