Skip to content

Commit f3aae49

Browse files
Samuel Wantheborch
authored andcommitted
fix:tab completion error with invalid tenant
1 parent e199622 commit f3aae49

3 files changed

Lines changed: 34 additions & 8 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
11
# register the completion scripts since they are not required to be registered anywhere else
2+
import os
3+
from typing import Optional
4+
25
from . 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

src/pybritive/completers/api.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
from britive.britive import Britive
55
from click.shell_completion import CompletionItem
66

7+
from pybritive.completers import get_tenant_for_api_completion
8+
79

810
def 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

src/pybritive/completers/api_command.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44

55
from britive.britive import Britive
66

7+
from pybritive.completers import get_tenant_for_api_completion
8+
79

810
def 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

0 commit comments

Comments
 (0)