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) Glacier Delete All Archives in a VaultIterates over a vault inventory retrieval and deletes each archive.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, AuthAws, Rest, StringBuilder, Csv; ... procedure TForm1.Button1Click(Sender: TObject); var rest: HCkRest; bTls: Boolean; port: Integer; bAutoReconnect: Boolean; success: Boolean; authAws: HCkAuthAws; sbResponseBody: HCkStringBuilder; respStatusCode: Integer; csv: HCkCsv; i: Integer; numRows: Integer; archiveId: PWideChar; begin // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. rest := CkRest_Create(); // Connect to the Amazon AWS REST server in the desired region. bTls := True; port := 443; bAutoReconnect := True; success := CkRest_Connect(rest,'glacier.us-west-2.amazonaws.com',port,bTls,bAutoReconnect); // Provide AWS credentials. authAws := CkAuthAws_Create(); CkAuthAws_putAccessKey(authAws,'AWS_ACCESS_KEY'); CkAuthAws_putSecretKey(authAws,'AWS_SECRET_KEY'); CkAuthAws_putServiceName(authAws,'glacier'); CkAuthAws_putRegion(authAws,'us-west-2'); success := CkRest_SetAuthAws(rest,authAws); // -------------------------------------------------------------------------- // Note: The above REST connection and setup of the AWS credentials // can be done once. After connecting, any number of REST calls can be made. // The "auto reconnect" property passed to rest.Connect indicates that if // the connection is lost, a REST method call will automatically reconnect // if needed. // -------------------------------------------------------------------------- // // For more information, see Glacier Retrieve Job Output Reference Documentation // CkRest_AddHeader(rest,'x-amz-glacier-version','2012-06-01'); sbResponseBody := CkStringBuilder_Create(); success := CkRest_FullRequestNoBodySb(rest,'GET','/AWS_ACCOUNT_ID/vaults/chilkat/jobs/JOB_ID/output',sbResponseBody); if (success <> True) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; respStatusCode := CkRest_getResponseStatusCode(rest); if (respStatusCode >= 400) then begin Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode)); Memo1.Lines.Add('Response Header:'); Memo1.Lines.Add(CkRest__responseHeader(rest)); Memo1.Lines.Add('Response Body:'); Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponseBody)); Exit; end; // Success is indicated by a 200 response status. Memo1.Lines.Add('response status code = ' + IntToStr(respStatusCode)); // The inventory retrieval job output is in CSV format. Memo1.Lines.Add('job output:'); Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponseBody)); Memo1.Lines.Add('--'); // The CSV has these fields: ArchiveId,ArchiveDescription,CreationDate,Size,SHA256TreeHash csv := CkCsv_Create(); CkCsv_putHasColumnNames(csv,True); CkCsv_LoadFromString(csv,CkStringBuilder__getAsString(sbResponseBody)); // Iterate over the results and delete each archive from the vault. i := 0; numRows := CkCsv_getNumRows(csv); while i < numRows do begin archiveId := CkCsv__getCellByName(csv,i,'ArchiveId'); Memo1.Lines.Add('Deleting ArchiveId: ' + archiveId); CkRest_AddPathParam(rest,'ArchiveID',archiveId); success := CkRest_FullRequestNoBodySb(rest,'DELETE','/AWS_ACCOUNT_ID/vaults/chilkat/archives/ArchiveID',sbResponseBody); if (success <> True) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; respStatusCode := CkRest_getResponseStatusCode(rest); // Success is indicated by a 204 response status with an empty response body. // A 404 resonse indicates the archive was likely already deleted. Memo1.Lines.Add('response status code = ' + IntToStr(respStatusCode)); i := i + 1; end; CkRest_Dispose(rest); CkAuthAws_Dispose(authAws); CkStringBuilder_Dispose(sbResponseBody); CkCsv_Dispose(csv); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.