-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateAzureCredentialsFile.ps1
More file actions
54 lines (46 loc) · 2.62 KB
/
CreateAzureCredentialsFile.ps1
File metadata and controls
54 lines (46 loc) · 2.62 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
43
44
45
46
47
48
49
50
51
52
53
54
# Login to Azure and create Azure Credentials File
$Cred_File = 'azure_credentials.json'
az login
az ad sp create-for-rbac --sdk-auth > $Cred_File
# Set Authentication Variable
$Cred_File_Location = (Get-ChildItem $Cred_File).FullName
[Environment]::SetEnvironmentVariable('AZURE_AUTH_LOCATION', $Cred_File_Location, "Machine")
<#
### Azure Authentication using Authentication File in Python
# These modules are used for authenticating to Azure, using resources and managing storage.
# Install them if they are not already on the system: pip install --upgrade --user azure-common azure-mgmt azure-storage
import datetime, os, ftplib, xml.etree.ElementTree as ET
from azure.common.client_factory import get_client_from_cli_profile, get_client_from_auth_file
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.storage import StorageManagementClient
from azure.storage.common import CloudStorageAccount
from azure.storage.file import FileService
from azure.storage.blob import PublicAccess
from azure.mgmt.web import WebSiteManagementClient
from azure.mgmt.web.models import AppServicePlan, SkuDescription, Site, SiteAuthSettings
# Configure Clients for Managing Resources (using Client Profile)
resource_client = get_client_from_cli_profile(ResourceManagementClient)
storage_client = get_client_from_cli_profile(StorageManagementClient)
web_client = get_client_from_cli_profile(WebSiteManagementClient)
# Configure Clients for Managing Resources (using Authentication File)
resource_client = get_client_from_auth_file(ResourceManagementClient)
storage_client = get_client_from_auth_file(StorageManagementClient)
web_client = get_client_from_auth_file(WebSiteManagementClient)
# Configure Variables
nameprefix = 'np' + (datetime.datetime.now()).strftime('%H%M%S')
resourcegroupname = nameprefix + 'rg'
storageaccountname = nameprefix + 'sa'
serverfarmname = nameprefix + 'sf'
websitename = nameprefix + 'web'
location = 'eastus'
sharename = '55264a'
profilefilename = websitename+'.xml'
# create a test file to be uploaded to your blob and file share
os.system('echo "<h1> This is my first Azure web-site. </h1>" > index.html')
filename = 'index.html'
# Create the Resource Group and Storage Account. Use Azure Portal to examine their properties before deleting them.
resource_group_params = {'location':location}
resource_client.resource_groups.create_or_update(resourcegroupname, resource_group_params)
storageaccount = storage_client.storage_accounts.create(resourcegroupname, storageaccountname, {'location':location,'kind':'storage','sku':{'name':'standard_ragrs'}})
storageaccount.wait()
#>