Zig
Zig
Glacier Get Job Information and Status
See more Amazon Glacier Examples
Demonstrates how to get information and status for a glacier job.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const rest = try chilkat.Rest.init();
defer rest.deinit();
// Connect to the Amazon AWS REST server in the desired region.
const b_tls = true;
const port = 443;
const b_auto_reconnect = true;
try rest.connect("glacier.us-west-2.amazonaws.com", port, b_tls, b_auto_reconnect);
// Provide AWS credentials.
const auth_aws = try chilkat.AuthAws.init();
defer auth_aws.deinit();
auth_aws.setAccessKey("AWS_ACCESS_KEY");
auth_aws.setSecretKey("AWS_SECRET_KEY");
auth_aws.setServiceName("glacier");
auth_aws.setRegion("us-west-2");
try rest.setAuthAws(auth_aws);
// --------------------------------------------------------------------------
// 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 Describe Job Reference Documentation
//
rest.addHeader("x-amz-glacier-version", "2012-06-01") catch {};
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
rest.fullRequestNoBodySb("GET", "/AWS_ACCOUNT_ID/vaults/chilkat/jobs/JOB_ID", sb_response_body) catch {
std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
return;
};
const resp_status_code = rest.getResponseStatusCode();
if (resp_status_code >= 400) {
std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try rest.getResponseHeader(alloc)});
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try sb_response_body.getAsString(alloc)});
return;
}
// Success is indicated by a 200 response status.
std.debug.print("response status code = {d}\n", .{resp_status_code});
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.loadSb(sb_response_body) catch {};
json.setEmitCompact(false);
std.debug.print("{s}\n", .{try json.emit(alloc)});
// Sample output:
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "Action": "InventoryRetrieval",
// "ArchiveId": null,
// "ArchiveSHA256TreeHash": null,
// "ArchiveSizeInBytes": null,
// "Completed": false,
// "CompletionDate": null,
// "CreationDate": "2019-04-09T22:48:48.700Z",
// "InventoryRetrievalParameters": {
// "EndDate": null,
// "Format": "CSV",
// "Limit": null,
// "Marker": null,
// "StartDate": null
// },
// "InventorySizeInBytes": null,
// "JobDescription": "My inventory job",
// "JobId": "E-mCnb3j122yvz5PRFGzETmFVXVrkX_pgI8PIuwBKNRyI8pAJqIetKwzkJC5a6blIvYZrrVohiBENQVhZE1a-K-x-uRO",
// "JobOutputPath": null,
// "OutputLocation": null,
// "RetrievalByteRange": null,
// "SHA256TreeHash": null,
// "SNSTopic": null,
// "SelectParameters": null,
// "StatusCode": "InProgress",
// "StatusMessage": null,
// "Tier": null,
// "VaultARN": "arn:aws:glacier:us-west-2:954491834127:vaults/chilkat"
// }
//
_ = try json.stringOf(alloc, "Action");
_ = try json.stringOf(alloc, "ArchiveId");
_ = try json.stringOf(alloc, "ArchiveSHA256TreeHash");
_ = try json.stringOf(alloc, "ArchiveSizeInBytes");
_ = json.boolOf("Completed");
_ = try json.stringOf(alloc, "CompletionDate");
_ = try json.stringOf(alloc, "CreationDate");
_ = try json.stringOf(alloc, "InventoryRetrievalParameters.EndDate");
_ = try json.stringOf(alloc, "InventoryRetrievalParameters.Format");
_ = try json.stringOf(alloc, "InventoryRetrievalParameters.Limit");
_ = try json.stringOf(alloc, "InventoryRetrievalParameters.Marker");
_ = try json.stringOf(alloc, "InventoryRetrievalParameters.StartDate");
_ = try json.stringOf(alloc, "InventorySizeInBytes");
_ = try json.stringOf(alloc, "JobDescription");
_ = try json.stringOf(alloc, "JobId");
_ = try json.stringOf(alloc, "JobOutputPath");
_ = try json.stringOf(alloc, "OutputLocation");
_ = try json.stringOf(alloc, "RetrievalByteRange");
_ = try json.stringOf(alloc, "SHA256TreeHash");
_ = try json.stringOf(alloc, "SNSTopic");
_ = try json.stringOf(alloc, "SelectParameters");
_ = try json.stringOf(alloc, "StatusCode");
_ = try json.stringOf(alloc, "StatusMessage");
_ = try json.stringOf(alloc, "Tier");
_ = try json.stringOf(alloc, "VaultARN");
}