aws-sdk-for-zig/src/servicemodel.zig

56 lines
2.0 KiB
Zig
Raw Normal View History

const std = @import("std");
const service_list = @import("models/service_manifest.zig");
const expectEqualStrings = std.testing.expectEqualStrings;
pub fn Services(comptime service_imports: anytype) type {
if (service_imports.len == 0) return services;
// From here, the fields of our structure can be generated at comptime...
2023-08-04 23:39:15 +00:00
var fields: [serviceCount(service_imports)]std.builtin.Type.StructField = undefined;
2023-08-04 23:39:15 +00:00
for (&fields, 0..) |*item, i| {
const import_field = @field(service_list, @tagName(service_imports[i]));
item.* = .{
.name = @tagName(service_imports[i]),
2023-08-04 23:39:15 +00:00
.type = @TypeOf(import_field),
.default_value = &import_field,
.is_comptime = false,
.alignment = 0,
};
}
// finally, generate the type
return @Type(.{
.Struct = .{
upgrade to nominated zig 2024.3.0-mach (0.12.0-dev.3180+83e578a18) There were significant changes to the way HTTP operates since 0.11, effecting client operations, but more substantially, the server implementation, which effected the test harness. std.http.Headers was removed, including the getFirstValue function, which needed to be replicated. On the plus side, a std.http.Header struct was added, identical to our own structure, so I have removed out own header in favor of stdlib. On the Http client side, I have switched to use the fetch API. Proxy support is built in, but we are using (mostly) our own implementation for now, with the remaining conversion left as a TODO item. Raw URIs are now supported, so the workaround for issue 17015 has been removed. Large payloads should also be fixed, but this has not been tested. The standard library now adds the content-length header (unconditionally), which is a decision of dubious nature. I have removed the addition of content-length, which also means it is not present during signing. This should be allowed. Dependency loop on fieldTransformer was fixed. This should have been a problem on zig 0.11, but was not. This effected the API for the json parsing, but we were not using that. At the call site, these did not need to be specified as references. With the http server no longer doing all the allocations it once was, the test harness now has a lot more allocations to perform. To alleviate the bookeeping, this was moved to an Arena allocator. The client, which is really what is under test, continues to use the allocator passed.
2024-04-02 16:13:45 +00:00
.layout = .Auto, // will be .auto in the future
.fields = &fields,
2023-08-04 23:39:15 +00:00
.decls = &[_]std.builtin.Type.Declaration{},
.is_tuple = false,
},
});
}
fn serviceCount(desired_services: anytype) usize {
if (desired_services.len == 0) return @TypeOf(service_list).Struct.fields.len;
return desired_services.len;
}
/// Using this constant may blow up build times. Recommed using Services()
/// function directly, e.g. const services = Services(.{.sts, .ec2, .s3, .ddb}){};
pub const services = service_list;
test "services includes sts" {
try expectEqualStrings("2011-06-15", services.sts.version);
}
test "sts includes get_caller_identity" {
try expectEqualStrings("GetCallerIdentity", services.sts.get_caller_identity.action_name);
}
test "can get service and action name from request" {
// get request object. This call doesn't have parameters
2021-09-01 15:27:58 +00:00
const metadata = services.sts.get_caller_identity.Request.metaInfo();
try expectEqualStrings("2011-06-15", metadata.service_metadata.version);
}
test "can filter services" {
2021-07-27 16:40:11 +00:00
const filtered_services = Services(.{ .sts, .wafv2 }){};
try expectEqualStrings("2011-06-15", filtered_services.sts.version);
}