PureBasic
PureBasic
Azure List Storage Accounts
See more Azure Storage Accounts Examples
Demonstrates how to list Azure storage accounts.Chilkat PureBasic Downloads
IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
Procedure ChilkatExample()
success.i = 0
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Load an OAuth2 access token previously fetched by this example: Get Azure OAuth2 Access Token
jsonToken.i = CkJsonObject::ckCreate()
If jsonToken.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkJsonObject::ckLoadFile(jsonToken,"qa_data/tokens/azureToken.json")
; Assuming success..
CkHttp::setCkAuthToken(http, CkJsonObject::ckStringOf(jsonToken,"access_token"))
Debug "AuthToken: " + CkHttp::ckAuthToken(http)
CkHttp::setCkAccept(http, "application/json")
url.s = "https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Storage/storageAccounts?api-version=2018-11-01"
jsonResp.s = CkHttp::ckQuickGetStr(http,url)
If CkHttp::ckLastMethodSuccess(http) <> 1
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(jsonToken)
ProcedureReturn
EndIf
Debug "Response Status Code: " + Str(CkHttp::ckLastStatus(http))
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoad(json,jsonResp)
CkJsonObject::setCkEmitCompact(json, 0)
Debug CkJsonObject::ckEmit(json)
If CkHttp::ckLastStatus(http) <> 200
Debug "Failed."
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(jsonToken)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndIf
; Sample output...
; (See the parsing code below..)
;
; Use this online tool to generate parsing code from sample JSON:
; Generate Parsing Code from JSON
; {
; "value": [
; {
; "sku": {
; "name": "Standard_LRS",
; "tier": "Standard"
; },
; "kind": "Storage",
; "id": "/subscriptions/6c42643b-ebef-45e0-b917-b3583b84a57f/resourceGroups/gchilkat/providers/Microsoft.Storage/storageAccounts/chilkat",
; "name": "chilkat",
; "type": "Microsoft.Storage/storageAccounts",
; "location": "eastus",
; "tags": {},
; "properties": {
; "networkAcls": {
; "bypass": "AzureServices",
; "virtualNetworkRules": [
; ],
; "ipRules": [
; ],
; "defaultAction": "Allow"
; },
; "supportsHttpsTrafficOnly": true,
; "encryption": {
; "services": {
; "file": {
; "enabled": true,
; "lastEnabledTime": "2017-12-28T11:02:10.6840887Z"
; },
; "blob": {
; "enabled": true,
; "lastEnabledTime": "2017-12-28T11:02:10.6840887Z"
; }
; },
; "keySource": "Microsoft.Storage"
; },
; "provisioningState": "Succeeded",
; "creationTime": "2016-04-18T22:57:36.5377065Z",
; "primaryEndpoints": {
; "blob": "https://chilkat.blob.core.windows.net/",
; "queue": "https://chilkat.queue.core.windows.net/",
; "table": "https://chilkat.table.core.windows.net/",
; "file": "https://chilkat.file.core.windows.net/"
; },
; "primaryLocation": "eastus",
; "statusOfPrimary": "available"
; }
; }
; ]
; }
;
i.i
count_i.i
skuName.s
skuTier.s
kind.s
id.s
name.s
v_type.s
location.s
propertiesNetworkAclsBypass.s
propertiesNetworkAclsDefaultAction.s
propertiesSupportsHttpsTrafficOnly.i
propertiesEncryptionServicesFileEnabled.i
propertiesEncryptionServicesFileLastEnabledTime.s
propertiesEncryptionServicesBlobEnabled.i
propertiesEncryptionServicesBlobLastEnabledTime.s
propertiesEncryptionKeySource.s
propertiesProvisioningState.s
propertiesCreationTime.s
propertiesPrimaryEndpointsBlob.s
propertiesPrimaryEndpointsQueue.s
propertiesPrimaryEndpointsTable.s
propertiesPrimaryEndpointsFile.s
propertiesPrimaryLocation.s
propertiesStatusOfPrimary.s
i = 0
count_i = CkJsonObject::ckSizeOfArray(json,"value")
While i < count_i
CkJsonObject::setCkI(json, i)
skuName = CkJsonObject::ckStringOf(json,"value[i].sku.name")
skuTier = CkJsonObject::ckStringOf(json,"value[i].sku.tier")
kind = CkJsonObject::ckStringOf(json,"value[i].kind")
id = CkJsonObject::ckStringOf(json,"value[i].id")
name = CkJsonObject::ckStringOf(json,"value[i].name")
v_type = CkJsonObject::ckStringOf(json,"value[i].type")
location = CkJsonObject::ckStringOf(json,"value[i].location")
propertiesNetworkAclsBypass = CkJsonObject::ckStringOf(json,"value[i].properties.networkAcls.bypass")
propertiesNetworkAclsDefaultAction = CkJsonObject::ckStringOf(json,"value[i].properties.networkAcls.defaultAction")
propertiesSupportsHttpsTrafficOnly = CkJsonObject::ckBoolOf(json,"value[i].properties.supportsHttpsTrafficOnly")
propertiesEncryptionServicesFileEnabled = CkJsonObject::ckBoolOf(json,"value[i].properties.encryption.services.file.enabled")
propertiesEncryptionServicesFileLastEnabledTime = CkJsonObject::ckStringOf(json,"value[i].properties.encryption.services.file.lastEnabledTime")
propertiesEncryptionServicesBlobEnabled = CkJsonObject::ckBoolOf(json,"value[i].properties.encryption.services.blob.enabled")
propertiesEncryptionServicesBlobLastEnabledTime = CkJsonObject::ckStringOf(json,"value[i].properties.encryption.services.blob.lastEnabledTime")
propertiesEncryptionKeySource = CkJsonObject::ckStringOf(json,"value[i].properties.encryption.keySource")
propertiesProvisioningState = CkJsonObject::ckStringOf(json,"value[i].properties.provisioningState")
propertiesCreationTime = CkJsonObject::ckStringOf(json,"value[i].properties.creationTime")
propertiesPrimaryEndpointsBlob = CkJsonObject::ckStringOf(json,"value[i].properties.primaryEndpoints.blob")
propertiesPrimaryEndpointsQueue = CkJsonObject::ckStringOf(json,"value[i].properties.primaryEndpoints.queue")
propertiesPrimaryEndpointsTable = CkJsonObject::ckStringOf(json,"value[i].properties.primaryEndpoints.table")
propertiesPrimaryEndpointsFile = CkJsonObject::ckStringOf(json,"value[i].properties.primaryEndpoints.file")
propertiesPrimaryLocation = CkJsonObject::ckStringOf(json,"value[i].properties.primaryLocation")
propertiesStatusOfPrimary = CkJsonObject::ckStringOf(json,"value[i].properties.statusOfPrimary")
i = i + 1
Wend
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(jsonToken)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure