forked from Azure/azure-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_config_reader.py
More file actions
42 lines (34 loc) · 1.38 KB
/
_config_reader.py
File metadata and controls
42 lines (34 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import json
import os
from azure.cli.core.azclierror import BadRequestError
_config = None
def get_config_json():
global _config # pylint:disable=global-statement
if _config is not None:
return _config
script_dir = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(script_dir, "config.json"), "r") as f:
try:
_config = json.load(f)
return _config
except ValueError:
raise BadRequestError("Invalid json file. Make sure that the json file content is properly formatted.")
def get_cloud(cmd):
config = get_config_json()
return config[cmd.cli_ctx.cloud.name]
def get_cloud_cluster(cmd, location, subscription_id):
try:
cloud = get_cloud(cmd)
clusters = cloud[location]
except KeyError:
clusters = None
if clusters is not None:
for cluster in clusters:
if cloud[cluster] is not None:
if subscription_id in cloud[cluster]["subscriptions"]:
return cloud[cluster]
return