File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# register the completion scripts since they are not required to be registered anywhere else
2+ import os
3+ from typing import Optional
4+
25from . import bash_gte_42 , powershell_completion # noqa: F401
6+
7+
8+ def get_tenant_for_api_completion () -> Optional [str ]:
9+ """Resolve the tenant for API completion from environment or config."""
10+ tenant = os .getenv ('BRITIVE_TENANT' )
11+ if not tenant :
12+ from pybritive .helpers .config import ConfigManager # noqa: PLC0415
13+
14+ config = ConfigManager (None )
15+ config .load ()
16+ if config .default_tenant and config .default_tenant in config .tenants :
17+ tenant = config .tenants [config .default_tenant ].get ('name' )
18+ if not tenant :
19+ return None
20+ if not tenant .endswith ('.britive-app.com' ):
21+ tenant = f'{ tenant .strip ()} .britive-app.com'
22+ return tenant
Original file line number Diff line number Diff line change 44from britive .britive import Britive
55from click .shell_completion import CompletionItem
66
7+ from pybritive .completers import get_tenant_for_api_completion
8+
79
810def api_completer (ctx , param , incomplete ):
911 # create an instance of the Britive class, so we can inspect it
10- # this doesn't need to actually connect to any tenant, and we couldn't even if we
11- # wanted to since when performing shell completion we have no tenant/token
12- # context in order to properly establish a connection.
13- b = Britive (token = 'ignore' , tenant = 'britive.com' , query_features = False )
12+ # using the user's configured tenant to avoid DNS resolution issues
13+ tenant = get_tenant_for_api_completion ()
14+ if not tenant :
15+ return []
16+ b = Britive (token = 'ignore' , tenant = tenant , query_features = False )
1417
1518 # parse the incomplete command, so we can determine where in the "hierarchy" we are
1619 # and what commands/subcommands the user should be presented with
Original file line number Diff line number Diff line change 44
55from britive .britive import Britive
66
7+ from pybritive .completers import get_tenant_for_api_completion
8+
79
810def get_dynamic_method_parameters (method ):
911 try :
1012 # create an instance of the Britive class, so we can inspect it
11- # this doesn't need to actually connect to any tenant, and we couldn't even if we
12- # wanted to since when performing shell completion we have no tenant/token
13- # context in order to properly establish a connection.
14- b = Britive (token = 'ignore' , tenant = 'britive.com' , query_features = False )
13+ # using the user's configured tenant to avoid DNS resolution issues
14+ tenant = get_tenant_for_api_completion ()
15+ if not tenant :
16+ return []
17+ b = Britive (token = 'ignore' , tenant = tenant , query_features = False )
1518
1619 # parse the method, so we can determine where in the "hierarchy" we are
1720 # and what commands/subcommands the user should be presented with
You can’t perform that action at this time.
0 commit comments