Compare commits

..

2 Commits

Author SHA1 Message Date
a4f9ca969c
bring EC2 back to par with 0.9.0 implementation
Some checks failed
AWS-Zig Build / build-zig-0.11.0-amd64-host (push) Failing after 1m15s
2023-08-27 17:04:49 -07:00
a580983c89
add failing test, reproducing issue in src/main 2023-08-27 16:29:20 -07:00
2 changed files with 78 additions and 33 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
std.log.err("EC2 functions not yet working in 0.11", .{});
// // Describe regions is a simpler request and easier to debug
// const result = try client.call(services.ec2.describe_regions.Request{}, options);
// defer result.deinit();
// std.log.info("request id: {any}", .{result.response_metadata.request_id});
// std.log.info("region count: {d}", .{result.response.regions.?.len});
const result = try client.call(services.ec2.describe_regions.Request{}, options);
defer result.deinit();
std.log.info("request id: {any}", .{result.response_metadata.request_id});
std.log.info("region count: {d}", .{result.response.regions.?.len});
},
.ec2_query_with_input => {
std.log.err("EC2 functions not yet working in 0.11", .{});
// Describe instances is more interesting
// const result = try client.call(services.ec2.describe_instances.Request{ .max_results = 6 }, options);
// defer result.deinit();
// std.log.info("reservation count: {d}", .{result.response.reservations.?.len});
// var items: usize = 0;
// for (result.response.reservations.?) |reservation| {
// items += reservation.instances.?.len;
// }
// std.log.info("items count: {d}", .{items});
// var next = result.response.next_token;
// while (next) |next_token| {
// std.log.info("more results available: fetching again", .{});
//
// const more = try aws.Request(services.ec2.describe_instances)
// .call(.{ .next_token = next_token, .max_results = 6 }, options);
// defer more.deinit();
// // we could have exactly 6, which means we have a next token(?!) but not
// // any actual additional data
// if (more.response.reservations == null) break;
// std.log.info("reservation count: {d}", .{more.response.reservations.?.len});
// var batch_items: usize = 0;
// for (more.response.reservations.?) |reservation| {
// batch_items += reservation.instances.?.len;
// }
// std.log.info("items count: {d}", .{batch_items});
// items += batch_items;
// std.log.info("total items count: {d}", .{items});
// next = more.response.next_token;
// }
const result = try client.call(services.ec2.describe_instances.Request{ .max_results = 6 }, options);
defer result.deinit();
std.log.info("reservation count: {d}", .{result.response.reservations.?.len});
var items: usize = 0;
for (result.response.reservations.?) |reservation| {
items += reservation.instances.?.len;
}
std.log.info("items count: {d}", .{items});
var next = result.response.next_token;
while (next) |next_token| {
std.log.info("more results available: fetching again", .{});
const more = try aws.Request(services.ec2.describe_instances)
.call(.{ .next_token = next_token, .max_results = 6 }, options);
defer more.deinit();
// we could have exactly 6, which means we have a next token(?!) but not
// any actual additional data
if (more.response.reservations == null) break;
std.log.info("reservation count: {d}", .{more.response.reservations.?.len});
var batch_items: usize = 0;
for (more.response.reservations.?) |reservation| {
batch_items += reservation.instances.?.len;
}
std.log.info("items count: {d}", .{batch_items});
items += batch_items;
std.log.info("total items count: {d}", .{items});
next = more.response.next_token;
}
},
.rest_xml_no_input => {
const result = try client.call(services.s3.list_buckets.Request{}, options);

View File

@ -44,6 +44,7 @@ pub fn encodeInternal(
writer: anytype,
comptime options: EncodingOptions,
) !bool {
// @compileLog(@typeName(@TypeOf(obj)));
// @compileLog(@typeInfo(@TypeOf(obj)));
var rc = first;
switch (@typeInfo(@TypeOf(obj))) {
@ -54,7 +55,7 @@ pub fn encodeInternal(
rc = try encodeInternal(allocator, parent, field_name, first, obj.*, writer, options);
} else {
if (!first) _ = try writer.write("&");
try writer.print("{s}{s}={s}", .{ parent, field_name, obj });
try writer.print("{s}{s}={any}", .{ parent, field_name, obj });
rc = false;
},
.Struct => if (std.mem.eql(u8, "", field_name)) {
@ -195,3 +196,47 @@ 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;
};
}