Skip to content

Commit

Permalink
default universe_domain, credentials for runbook API, handle template…
Browse files Browse the repository at this point in the history
… path for runbook from API service

Change-Id: I1d474d1c4674b7cb8225918d8682aeba2de6f98c
GitOrigin-RevId: 00ae911f2ecb3efdd602253b6c3090498d23ec16
  • Loading branch information
ropeck committed Apr 25, 2024
1 parent 36c96d8 commit 5ac6c68
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gcpdiag/queries/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _request_builder(http, *args, **kwargs):
return googleapiclient.http.HttpRequest(new_http, *args, **kwargs)

universe_domain = config.get('universe_domain')
cred_universe = getattr(credentials, 'universe_domain')
cred_universe = getattr(credentials, 'universe_domain', 'googleapis.com')
if cred_universe != universe_domain:
raise ValueError('credential universe_domain mismatch '
f'{cred_universe} != {universe_domain}')
Expand Down
5 changes: 4 additions & 1 deletion gcpdiag/runbook/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,14 @@ def _initialize_output():
return output


def run_and_get_report(argv=None) -> Tuple[int, dict]:
def run_and_get_report(argv=None, credentials: str = None) -> Tuple[int, dict]:
# Initialize argument parser
parser = _init_runbook_args_parser()
args = parser.parse_args(argv[1:])

if credentials:
apis.set_credentials(credentials)

# Allow to change defaults using a hook function.
hooks.set_lint_args_hook(args)

Expand Down
7 changes: 6 additions & 1 deletion gcpdiag/runbook/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ def load_template_block(module_name, file_name, block_name):
block_name: Load blocks with this prefix
module_name: Ref to module
"""
module = importlib.import_module(module_name)
try:
module = importlib.import_module(module_name)
except (ImportError, ModuleNotFoundError):
# when running in API environment
module_name = re.sub('^gcpdiag', 'google.cloud.gcpdiag', module_name)
module = importlib.import_module(module_name)

current_dir = os.path.dirname(os.path.abspath(module.__file__))
template_file = os.path.join(current_dir, 'templates', f'{file_name}.jinja')
Expand Down

0 comments on commit 5ac6c68

Please sign in to comment.