Compare commits

..

No commits in common. "a4f9ca969c35cc007b3579a74e83d95d2dd8fa04" and "7c40549200f5bf754a6145037074975598e63920" have entirely different histories.

2 changed files with 33 additions and 78 deletions

View File

@ -184,42 +184,42 @@ pub fn main() anyerror!void {
// fmt.zig:459:5: error: invalid format string 's' for type 'models.ec2.2016-11-15.json.Filter // fmt.zig:459:5: error: invalid format string 's' for type 'models.ec2.2016-11-15.json.Filter
std.log.err("EC2 functions not yet working in 0.11", .{}); std.log.err("EC2 functions not yet working in 0.11", .{});
// // Describe regions is a simpler request and easier to debug // // Describe regions is a simpler request and easier to debug
const result = try client.call(services.ec2.describe_regions.Request{}, options); // const result = try client.call(services.ec2.describe_regions.Request{}, options);
defer result.deinit(); // defer result.deinit();
std.log.info("request id: {any}", .{result.response_metadata.request_id}); // std.log.info("request id: {any}", .{result.response_metadata.request_id});
std.log.info("region count: {d}", .{result.response.regions.?.len}); // std.log.info("region count: {d}", .{result.response.regions.?.len});
}, },
.ec2_query_with_input => { .ec2_query_with_input => {
std.log.err("EC2 functions not yet working in 0.11", .{}); std.log.err("EC2 functions not yet working in 0.11", .{});
// Describe instances is more interesting // Describe instances is more interesting
const result = try client.call(services.ec2.describe_instances.Request{ .max_results = 6 }, options); // const result = try client.call(services.ec2.describe_instances.Request{ .max_results = 6 }, options);
defer result.deinit(); // defer result.deinit();
std.log.info("reservation count: {d}", .{result.response.reservations.?.len}); // std.log.info("reservation count: {d}", .{result.response.reservations.?.len});
var items: usize = 0; // var items: usize = 0;
for (result.response.reservations.?) |reservation| { // for (result.response.reservations.?) |reservation| {
items += reservation.instances.?.len; // items += reservation.instances.?.len;
} // }
std.log.info("items count: {d}", .{items}); // std.log.info("items count: {d}", .{items});
var next = result.response.next_token; // var next = result.response.next_token;
while (next) |next_token| { // while (next) |next_token| {
std.log.info("more results available: fetching again", .{}); // std.log.info("more results available: fetching again", .{});
//
const more = try aws.Request(services.ec2.describe_instances) // const more = try aws.Request(services.ec2.describe_instances)
.call(.{ .next_token = next_token, .max_results = 6 }, options); // .call(.{ .next_token = next_token, .max_results = 6 }, options);
defer more.deinit(); // defer more.deinit();
// we could have exactly 6, which means we have a next token(?!) but not // // we could have exactly 6, which means we have a next token(?!) but not
// any actual additional data // // any actual additional data
if (more.response.reservations == null) break; // if (more.response.reservations == null) break;
std.log.info("reservation count: {d}", .{more.response.reservations.?.len}); // std.log.info("reservation count: {d}", .{more.response.reservations.?.len});
var batch_items: usize = 0; // var batch_items: usize = 0;
for (more.response.reservations.?) |reservation| { // for (more.response.reservations.?) |reservation| {
batch_items += reservation.instances.?.len; // batch_items += reservation.instances.?.len;
} // }
std.log.info("items count: {d}", .{batch_items}); // std.log.info("items count: {d}", .{batch_items});
items += batch_items; // items += batch_items;
std.log.info("total items count: {d}", .{items}); // std.log.info("total items count: {d}", .{items});
next = more.response.next_token; // next = more.response.next_token;
} // }
}, },
.rest_xml_no_input => { .rest_xml_no_input => {
const result = try client.call(services.s3.list_buckets.Request{}, options); const result = try client.call(services.s3.list_buckets.Request{}, options);

View File

@ -44,7 +44,6 @@ pub fn encodeInternal(
writer: anytype, writer: anytype,
comptime options: EncodingOptions, comptime options: EncodingOptions,
) !bool { ) !bool {
// @compileLog(@typeName(@TypeOf(obj)));
// @compileLog(@typeInfo(@TypeOf(obj))); // @compileLog(@typeInfo(@TypeOf(obj)));
var rc = first; var rc = first;
switch (@typeInfo(@TypeOf(obj))) { switch (@typeInfo(@TypeOf(obj))) {
@ -55,7 +54,7 @@ pub fn encodeInternal(
rc = try encodeInternal(allocator, parent, field_name, first, obj.*, writer, options); rc = try encodeInternal(allocator, parent, field_name, first, obj.*, writer, options);
} else { } else {
if (!first) _ = try writer.write("&"); if (!first) _ = try writer.write("&");
try writer.print("{s}{s}={any}", .{ parent, field_name, obj }); try writer.print("{s}{s}={s}", .{ parent, field_name, obj });
rc = false; rc = false;
}, },
.Struct => if (std.mem.eql(u8, "", field_name)) { .Struct => if (std.mem.eql(u8, "", field_name)) {
@ -196,47 +195,3 @@ test "can urlencode a complex object" {
.{}, .{},
); );
} }
const Filter = struct {
name: ?[]const u8 = null,
values: ?[][]const u8 = null,
pub fn fieldNameFor(_: @This(), comptime field_name: []const u8) []const u8 {
const mappings = .{
.name = "Name",
.values = "Value",
};
return @field(mappings, field_name);
}
};
const Request: type = struct {
filters: ?[]Filter = null,
region_names: ?[][]const u8 = null,
dry_run: ?bool = null,
all_regions: ?bool = null,
};
test "can urlencode an EC2 Filter" {
// TODO: Fix this encoding...
testencode(
std.testing.allocator,
"filters={ url.Filter{ .name = { 102, 111, 111 }, .values = { { ... } } } }",
Request{
.filters = @constCast(&[_]Filter{.{ .name = "foo", .values = @constCast(&[_][]const u8{"bar"}) }}),
},
.{},
) catch |err| {
var al = std.ArrayList(u8).init(std.testing.allocator);
defer al.deinit();
try encode(
std.testing.allocator,
Request{
.filters = @constCast(&[_]Filter{.{ .name = "foo", .values = @constCast(&[_][]const u8{"bar"}) }}),
},
al.writer(),
.{},
);
std.log.warn("Error found. Full encoding is '{s}'", .{al.items});
return err;
};
}