Lua
Lua
Azure Create Storage Account
See more Azure Storage Accounts Examples
Demonstrates how to create an Azure storage account.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- Load an OAuth2 access token previously fetched by this example: Get Azure OAuth2 Access Token
local jsonToken = chilkat.JsonObject.new()
local success = jsonToken:load_file("qa_data/tokens/azureToken.json")
-- Assuming success..
http.auth_token = jsonToken:string_of("access_token")
print("AuthToken: " .. http.auth_token)
http.accept = "application/json"
-- Create the following JSON:
-- {
-- "sku": {
-- "name": "Standard_GRS"
-- },
-- "kind": "StorageV2",
-- "location": "eastus2",
-- }
-- Use this online tool to generate the code from sample JSON:
-- Generate Code to Create JSON
local jsonRequestBody = chilkat.JsonObject.new()
jsonRequestBody:update_string("sku.name", "Standard_GRS")
jsonRequestBody:update_string("kind", "StorageV2")
jsonRequestBody:update_string("location", "eastus2")
local url = "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}?api-version=2018-02-01"
local resp = chilkat.HttpResponse.new()
success = http:http_json("PUT", url, jsonRequestBody, "application/json", resp)
if not success then
print(http.last_error_text)
return
end
print("Response Status Code: " .. resp.status_code)
local json = chilkat.JsonObject.new()
json:load(resp.body_str)
json.emit_compact = false
print(json:emit())
if resp.status_code >= 300 then
print("Failed.")
return
end
-- Successful requests to create a new account return a 202 status code with an empty response body. The storage account is created asynchronously.
-- If the account already exists or is being provisioned, the request response has a 200 return code with the configuration of the existing storage account in the response body.
if resp.status_code == 202 then
print("Azure-AsyncOperation: " .. resp:get_header_field("Azure-AsyncOperation"))
end
if resp.status_code == 200 then
-- Parse a response like this:
-- {
-- "sku": {
-- "name": "Standard_GRS",
-- "tier": "Standard"
-- },
-- "kind": "StorageV2",
-- "id": "/subscriptions/6c42643b-ebef-45f0-b917-b3583b84a57f/resourceGroups/gChilkat/providers/Microsoft.Storage/storageAccounts/chilkatsoftware",
-- "name": "chilkatsoftware",
-- "type": "Microsoft.Storage/storageAccounts",
-- "location": "eastus2",
-- "tags": {},
-- "properties": {
-- "networkAcls": {
-- "bypass": "AzureServices",
-- "virtualNetworkRules": [
-- ],
-- "ipRules": [
-- ],
-- "defaultAction": "Allow"
-- },
-- "supportsHttpsTrafficOnly": false,
-- "encryption": {
-- "services": {
-- "file": {
-- "enabled": true,
-- "lastEnabledTime": "2019-05-14T22:18:33.2246670Z"
-- },
-- "blob": {
-- "enabled": true,
-- "lastEnabledTime": "2019-05-14T22:18:33.2246670Z"
-- }
-- },
-- "keySource": "Microsoft.Storage"
-- },
-- "accessTier": "Hot",
-- "provisioningState": "Succeeded",
--
-- "creationTime": "2019-05-14T22:18:33.1309165Z",
-- "primaryEndpoints": {
-- "dfs": "https://chilkatsoftware.dfs.core.windows.net/",
-- "web": "https://chilkatsoftware.z20.web.core.windows.net/",
-- "blob": "https://chilkatsoftware.blob.core.windows.net/",
-- "queue": "https://chilkatsoftware.queue.core.windows.net/",
-- "table": "https://chilkatsoftware.table.core.windows.net/",
-- "file": "https://chilkatsoftware.file.core.windows.net/"
-- },
-- "primaryLocation": "eastus2",
-- "statusOfPrimary": "available",
-- "secondaryLocation": "centralus",
-- "statusOfSecondary": "available"
-- }
-- }
-- Use this online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON
local i = 0
local count_i = 0
local skuName = json:string_of("sku.name")
local skuTier = json:string_of("sku.tier")
local kind = json:string_of("kind")
local id = json:string_of("id")
local name = json:string_of("name")
local v_type = json:string_of("type")
local location = json:string_of("location")
local propertiesNetworkAclsBypass = json:string_of("properties.networkAcls.bypass")
local propertiesNetworkAclsDefaultAction = json:string_of("properties.networkAcls.defaultAction")
local propertiesSupportsHttpsTrafficOnly = json:bool_of("properties.supportsHttpsTrafficOnly")
local propertiesEncryptionServicesFileEnabled = json:bool_of("properties.encryption.services.file.enabled")
local propertiesEncryptionServicesFileLastEnabledTime = json:string_of("properties.encryption.services.file.lastEnabledTime")
local propertiesEncryptionServicesBlobEnabled = json:bool_of("properties.encryption.services.blob.enabled")
local propertiesEncryptionServicesBlobLastEnabledTime = json:string_of("properties.encryption.services.blob.lastEnabledTime")
local propertiesEncryptionKeySource = json:string_of("properties.encryption.keySource")
local propertiesAccessTier = json:string_of("properties.accessTier")
local propertiesProvisioningState = json:string_of("properties.provisioningState")
local propertiesCreationTime = json:string_of("properties.creationTime")
local propertiesPrimaryEndpointsDfs = json:string_of("properties.primaryEndpoints.dfs")
local propertiesPrimaryEndpointsWeb = json:string_of("properties.primaryEndpoints.web")
local propertiesPrimaryEndpointsBlob = json:string_of("properties.primaryEndpoints.blob")
local propertiesPrimaryEndpointsQueue = json:string_of("properties.primaryEndpoints.queue")
local propertiesPrimaryEndpointsTable = json:string_of("properties.primaryEndpoints.table")
local propertiesPrimaryEndpointsFile = json:string_of("properties.primaryEndpoints.file")
local propertiesPrimaryLocation = json:string_of("properties.primaryLocation")
local propertiesStatusOfPrimary = json:string_of("properties.statusOfPrimary")
local propertiesSecondaryLocation = json:string_of("properties.secondaryLocation")
local propertiesStatusOfSecondary = json:string_of("properties.statusOfSecondary")
end
print("Success.")