This commit is contained in:
Paul Edwards 2020-03-10 01:20:30 +00:00
Родитель d318f0cb45
Коммит da7c7b4874
3 изменённых файлов: 30 добавлений и 26 удалений

Просмотреть файл

@ -125,7 +125,10 @@ class ConfigFile:
elif prefix == "sakey":
res = azutil.get_storage_key(parts[1])
elif prefix == "saskey":
res = azutil.get_storage_saskey(parts[1], parts[2])
v = parts[2].split(",")
if len(v) == 1:
v.append("r")
res = azutil.get_storage_saskey(parts[1], v[0], v[1])
elif prefix == "laworkspace":
res = azutil.get_log_analytics_workspace(parts[1], parts[2])
elif prefix == "lakey":

Просмотреть файл

@ -366,7 +366,7 @@ def do_build(args):
if success:
log.info("Provising succeeded")
else:
logging.error("Provisioning failed")
log.error("Provisioning failed")
for i in res:
props = i["properties"]
status_code = props["statusCode"]

Просмотреть файл

@ -16,7 +16,7 @@ def get_subscription():
cmd = [ "az", "account", "show", "--output", "tsv", "--query", "[name,id]" ]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
sys.exit(1)
return res.stdout
@ -30,7 +30,7 @@ def get_vm_private_ip(resource_group, vm_name):
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
sys.exit(1)
out = res.stdout.splitlines()
return out[0].decode("utf-8")
@ -45,7 +45,7 @@ def get_fqdn(resource_group, public_ip):
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
sys.exit(1)
out = res.stdout.splitlines()
return out[0].decode("utf-8")
@ -60,7 +60,7 @@ def get_vmss_instances(resource_group, vmss_name):
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
sys.exit(1)
names = [ x.decode("utf-8") for x in res.stdout.splitlines() ]
return names
@ -74,7 +74,7 @@ def create_resource_group(resource_group, location):
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
sys.exit(1)
def delete_resource_group(resource_group, nowait):
@ -88,7 +88,7 @@ def delete_resource_group(resource_group, nowait):
log.debug(" ".join(cmd))
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
sys.exit(1)
@ -106,7 +106,7 @@ def deploy(resource_group, arm_template):
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
sys.exit(1)
return deployname
@ -119,7 +119,7 @@ def get_deployment_status(resource_group, deployname):
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
sys.exit(1)
return json.loads(res.stdout)
@ -132,10 +132,10 @@ def get_keyvault_secret(vault, key):
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
out = res.stdout.splitlines()
if len(out) != 1:
logging.error("expected output"+_make_subprocess_error_string(res))
log.error("expected output"+_make_subprocess_error_string(res))
secret = out[0].decode('utf-8')
return secret
@ -148,10 +148,10 @@ def get_storage_url(account):
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
out = res.stdout.splitlines()
if len(out) != 1:
logging.error("unexpected output"+_make_subprocess_error_string(res))
log.error("unexpected output"+_make_subprocess_error_string(res))
url = out[0].decode('utf-8')
return url
@ -164,31 +164,32 @@ def get_storage_key(account):
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
out = res.stdout.splitlines()
if len(out) != 1:
logging.error("unexpected output"+_make_subprocess_error_string(res))
log.error("unexpected output"+_make_subprocess_error_string(res))
key = out[0].decode('utf-8')
return key
def get_storage_saskey(account, container):
def get_storage_saskey(account, container, permissions):
log.debug(f"creating sas key: container={container}, permissions={permissions}")
start = (datetime.datetime.utcnow() - datetime.timedelta(hours=2)).strftime("%Y-%m-%dT%H:%M:%SZ")
expiry = (datetime.datetime.utcnow() + datetime.timedelta(hours=1)).strftime("%Y-%m-%dT%H:%M:%SZ")
cmd = [
"az", "storage", "container", "generate-sas",
"--account-name", account,
"--name", container,
"--permissions", "r",
"--permissions", permissions,
"--start", start,
"--expiry", expiry,
"--output", "tsv"
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
out = res.stdout.splitlines()
if len(out) != 1:
logging.error("unexpected output"+_make_subprocess_error_string(res))
log.error("unexpected output"+_make_subprocess_error_string(res))
saskey = out[0].decode('utf-8')
return saskey
@ -200,10 +201,10 @@ def get_log_analytics_workspace(resource_group, name):
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
out = res.stdout.splitlines()
if len(out) != 1:
logging.error("unexpected output"+_make_subprocess_error_string(res))
log.error("unexpected output"+_make_subprocess_error_string(res))
saskey = out[0].decode('utf-8')
return saskey
@ -217,10 +218,10 @@ def get_log_analytics_key(resource_group, name):
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
out = res.stdout.splitlines()
if len(out) != 1:
logging.error("unexpected output"+_make_subprocess_error_string(res))
log.error("unexpected output"+_make_subprocess_error_string(res))
saskey = out[0].decode('utf-8')
return saskey
@ -233,10 +234,10 @@ def get_acr_key(name):
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
logging.error("invalid returncode"+_make_subprocess_error_string(res))
log.error("invalid returncode"+_make_subprocess_error_string(res))
out = res.stdout.splitlines()
if len(out) != 1:
logging.error("unexpected output"+_make_subprocess_error_string(res))
log.error("unexpected output"+_make_subprocess_error_string(res))
saskey = out[0].decode('utf-8')
return saskey