add instance_id generated at install time (#245)

This commit is contained in:
bmc-msft
2020-11-02 14:27:51 -05:00
committed by GitHub
parent 89ebc7be50
commit 6c598773dd
20 changed files with 83 additions and 21 deletions

View File

@ -63,8 +63,7 @@
"namespace": "onefuzz",
"members": {
"severitiesAtMostInfo": {
"parameters": [
],
"parameters": [],
"output": {
"type": "array",
"value": [
@ -209,8 +208,7 @@
],
"linuxFxVersion": "Python|3.7",
"alwaysOn": true,
"defaultDocuments": [
],
"defaultDocuments": [],
"httpLoggingEnabled": true,
"logsDirectorySizeLimit": 100,
"detailedErrorLoggingEnabled": true,
@ -243,8 +241,7 @@
"type": "Microsoft.Web/serverFarms",
"location": "[resourceGroup().location]",
"kind": "linux",
"dependsOn": [
],
"dependsOn": [],
"properties": {
"name": "[parameters('name')]",
"reserved": true
@ -394,7 +391,6 @@
"properties": {
"workspaceResourceId": "[resourceId('Microsoft.OperationalInsights/workspaces', variables('monitorAccountName'))]"
},
"plan": {
"name": "[concat('VMInsights', '(', variables('monitorAccountName'), ')')]",
"publisher": "Microsoft",
@ -694,20 +690,17 @@
{
"flag": "ServiceMode",
"value": "Serverless",
"properties": {
}
"properties": {}
},
{
"flag": "EnableConnectivityLogs",
"value": "True",
"properties": {
}
"properties": {}
},
{
"flag": "EnableMessagingLogs",
"value": "False",
"properties": {
}
"properties": {}
}
]
}
@ -743,4 +736,4 @@
"value": "[variables('scaleset_identity')]"
}
}
}
}

View File

@ -92,6 +92,7 @@ FUNC_TOOLS_ERROR = (
logger = logging.getLogger("deploy")
def gen_guid():
return str(uuid.uuid4())
@ -464,6 +465,29 @@ class Client:
% json.dumps(result.as_dict(), indent=4, sort_keys=True),
)
def add_instance_id(self):
logger.info("setting instance_id log export")
container_name = "base-config"
blob_name = "instance_id"
account_name = self.results["deploy"]["func-name"]["value"]
key = self.results["deploy"]["func-key"]["value"]
account_url = "https://%s.blob.core.windows.net" % account_name
client = BlobServiceClient(account_url, credential=key)
if container_name not in [x["name"] for x in client.list_containers()]:
client.create_container(container_name)
blob_client = client.get_blob_client(container_name, blob_name)
if blob_client.exists():
logger.debug("instance_id already exists")
instance_id = uuid.UUID(blob_client.download_blob().readall())
else:
logger.debug("creating new instance_id")
instance_id = uuid.uuid4()
blob_client.upload_blob(str(instance_id))
logger.info("instance_id: %s", instance_id)
def add_log_export(self):
if not self.export_appinsights:
logger.info("not exporting appinsights")
@ -683,6 +707,7 @@ def main():
("queues", Client.create_queues),
("eventgrid", Client.create_eventgrid),
("tools", Client.upload_tools),
("add_instance_id", Client.add_instance_id),
("instance-specific-setup", Client.upload_instance_setup),
("third-party", Client.upload_third_party),
("api", Client.deploy_app),