Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Azure Create Storage AccountDemonstrates how to create an Azure storage account.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, HttpResponse, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var http: HCkHttp; jsonToken: HCkJsonObject; success: Boolean; jsonRequestBody: HCkJsonObject; url: PWideChar; resp: HCkHttpResponse; json: HCkJsonObject; skuName: PWideChar; skuTier: PWideChar; kind: PWideChar; id: PWideChar; name: PWideChar; v_type: PWideChar; location: PWideChar; propertiesNetworkAclsBypass: PWideChar; propertiesNetworkAclsDefaultAction: PWideChar; propertiesSupportsHttpsTrafficOnly: Boolean; propertiesEncryptionServicesFileEnabled: Boolean; propertiesEncryptionServicesFileLastEnabledTime: PWideChar; propertiesEncryptionServicesBlobEnabled: Boolean; propertiesEncryptionServicesBlobLastEnabledTime: PWideChar; propertiesEncryptionKeySource: PWideChar; propertiesAccessTier: PWideChar; propertiesProvisioningState: PWideChar; propertiesCreationTime: PWideChar; propertiesPrimaryEndpointsDfs: PWideChar; propertiesPrimaryEndpointsWeb: PWideChar; propertiesPrimaryEndpointsBlob: PWideChar; propertiesPrimaryEndpointsQueue: PWideChar; propertiesPrimaryEndpointsTable: PWideChar; propertiesPrimaryEndpointsFile: PWideChar; propertiesPrimaryLocation: PWideChar; propertiesStatusOfPrimary: PWideChar; propertiesSecondaryLocation: PWideChar; propertiesStatusOfSecondary: PWideChar; i: Integer; count_i: Integer; begin // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http := CkHttp_Create(); // Load an OAuth2 access token previously fetched by this example: Get Azure OAuth2 Access Token jsonToken := CkJsonObject_Create(); success := CkJsonObject_LoadFile(jsonToken,'qa_data/tokens/azureToken.json'); // Assuming success.. CkHttp_putAuthToken(http,CkJsonObject__stringOf(jsonToken,'access_token')); Memo1.Lines.Add('AuthToken: ' + CkHttp__authToken(http)); CkHttp_putAccept(http,'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 jsonRequestBody := CkJsonObject_Create(); CkJsonObject_UpdateString(jsonRequestBody,'sku.name','Standard_GRS'); CkJsonObject_UpdateString(jsonRequestBody,'kind','StorageV2'); CkJsonObject_UpdateString(jsonRequestBody,'location','eastus2'); url := 'https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}?api-version=2018-02-01'; resp := CkHttp_PText(http,'PUT',url,CkJsonObject__emit(jsonRequestBody),'utf-8','application/json',False,False); if (CkHttp_getLastMethodSuccess(http) <> True) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; Memo1.Lines.Add('Response Status Code: ' + IntToStr(CkHttpResponse_getStatusCode(resp))); json := CkJsonObject_Create(); CkJsonObject_Load(json,CkHttpResponse__bodyStr(resp)); CkJsonObject_putEmitCompact(json,False); Memo1.Lines.Add(CkJsonObject__emit(json)); if (CkHttpResponse_getStatusCode(resp) >= 300) then begin Memo1.Lines.Add('Failed.'); CkHttpResponse_Dispose(resp); Exit; 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 (CkHttpResponse_getStatusCode(resp) = 202) then begin Memo1.Lines.Add('Azure-AsyncOperation: ' + CkHttpResponse__getHeaderField(resp,'Azure-AsyncOperation')); end; if (CkHttpResponse_getStatusCode(resp) = 200) then begin // 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 skuName := CkJsonObject__stringOf(json,'sku.name'); skuTier := CkJsonObject__stringOf(json,'sku.tier'); kind := CkJsonObject__stringOf(json,'kind'); id := CkJsonObject__stringOf(json,'id'); name := CkJsonObject__stringOf(json,'name'); v_type := CkJsonObject__stringOf(json,'type'); location := CkJsonObject__stringOf(json,'location'); propertiesNetworkAclsBypass := CkJsonObject__stringOf(json,'properties.networkAcls.bypass'); propertiesNetworkAclsDefaultAction := CkJsonObject__stringOf(json,'properties.networkAcls.defaultAction'); propertiesSupportsHttpsTrafficOnly := CkJsonObject_BoolOf(json,'properties.supportsHttpsTrafficOnly'); propertiesEncryptionServicesFileEnabled := CkJsonObject_BoolOf(json,'properties.encryption.services.file.enabled'); propertiesEncryptionServicesFileLastEnabledTime := CkJsonObject__stringOf(json,'properties.encryption.services.file.lastEnabledTime'); propertiesEncryptionServicesBlobEnabled := CkJsonObject_BoolOf(json,'properties.encryption.services.blob.enabled'); propertiesEncryptionServicesBlobLastEnabledTime := CkJsonObject__stringOf(json,'properties.encryption.services.blob.lastEnabledTime'); propertiesEncryptionKeySource := CkJsonObject__stringOf(json,'properties.encryption.keySource'); propertiesAccessTier := CkJsonObject__stringOf(json,'properties.accessTier'); propertiesProvisioningState := CkJsonObject__stringOf(json,'properties.provisioningState'); propertiesCreationTime := CkJsonObject__stringOf(json,'properties.creationTime'); propertiesPrimaryEndpointsDfs := CkJsonObject__stringOf(json,'properties.primaryEndpoints.dfs'); propertiesPrimaryEndpointsWeb := CkJsonObject__stringOf(json,'properties.primaryEndpoints.web'); propertiesPrimaryEndpointsBlob := CkJsonObject__stringOf(json,'properties.primaryEndpoints.blob'); propertiesPrimaryEndpointsQueue := CkJsonObject__stringOf(json,'properties.primaryEndpoints.queue'); propertiesPrimaryEndpointsTable := CkJsonObject__stringOf(json,'properties.primaryEndpoints.table'); propertiesPrimaryEndpointsFile := CkJsonObject__stringOf(json,'properties.primaryEndpoints.file'); propertiesPrimaryLocation := CkJsonObject__stringOf(json,'properties.primaryLocation'); propertiesStatusOfPrimary := CkJsonObject__stringOf(json,'properties.statusOfPrimary'); propertiesSecondaryLocation := CkJsonObject__stringOf(json,'properties.secondaryLocation'); propertiesStatusOfSecondary := CkJsonObject__stringOf(json,'properties.statusOfSecondary'); end; Memo1.Lines.Add('Success.'); CkHttpResponse_Dispose(resp); CkHttp_Dispose(http); CkJsonObject_Dispose(jsonToken); CkJsonObject_Dispose(jsonRequestBody); CkJsonObject_Dispose(json); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.