2021-05-30 02:33:08 +00:00
|
|
|
const std = @import("std");
|
2021-06-30 16:21:08 +00:00
|
|
|
const service_list = @import("models/service_manifest.zig");
|
2021-06-09 23:22:44 +00:00
|
|
|
const expectEqualStrings = std.testing.expectEqualStrings;
|
2021-05-30 02:33:08 +00:00
|
|
|
|
2023-08-04 17:06:54 +00:00
|
|
|
pub fn Services(comptime service_imports: anytype) type {
|
2021-06-30 20:40:20 +00:00
|
|
|
if (service_imports.len == 0) return services;
|
2021-06-09 23:22:44 +00:00
|
|
|
// 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;
|
2021-06-10 21:23:11 +00:00
|
|
|
|
2023-08-04 23:39:15 +00:00
|
|
|
for (&fields, 0..) |*item, i| {
|
2021-06-30 20:40:20 +00:00
|
|
|
const import_field = @field(service_list, @tagName(service_imports[i]));
|
2021-06-30 16:21:08 +00:00
|
|
|
item.* = .{
|
|
|
|
.name = @tagName(service_imports[i]),
|
2023-08-04 23:39:15 +00:00
|
|
|
.type = @TypeOf(import_field),
|
2023-08-04 17:06:54 +00:00
|
|
|
.default_value = &import_field,
|
2021-06-30 16:21:08 +00:00
|
|
|
.is_comptime = false,
|
|
|
|
.alignment = 0,
|
|
|
|
};
|
2021-06-09 23:22:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// finally, generate the type
|
2021-05-30 02:33:08 +00:00
|
|
|
return @Type(.{
|
|
|
|
.Struct = .{
|
|
|
|
.layout = .Auto,
|
2021-06-09 23:22:44 +00:00
|
|
|
.fields = &fields,
|
2023-08-04 23:39:15 +00:00
|
|
|
.decls = &[_]std.builtin.Type.Declaration{},
|
2021-05-30 02:33:08 +00:00
|
|
|
.is_tuple = false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2021-06-10 21:09:22 +00:00
|
|
|
|
2021-06-30 16:21:08 +00:00
|
|
|
fn serviceCount(desired_services: anytype) usize {
|
|
|
|
if (desired_services.len == 0) return @TypeOf(service_list).Struct.fields.len;
|
2021-06-10 21:09:22 +00:00
|
|
|
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}){};
|
2021-06-30 20:40:20 +00:00
|
|
|
pub const services = service_list;
|
2021-05-30 02:33:08 +00:00
|
|
|
|
2021-06-09 23:22:44 +00:00
|
|
|
test "services includes sts" {
|
2021-06-10 21:09:22 +00:00
|
|
|
try expectEqualStrings("2011-06-15", services.sts.version);
|
2021-05-30 02:33:08 +00:00
|
|
|
}
|
2021-06-09 23:22:44 +00:00
|
|
|
test "sts includes get_caller_identity" {
|
2021-06-10 21:09:22 +00:00
|
|
|
try expectEqualStrings("GetCallerIdentity", services.sts.get_caller_identity.action_name);
|
2021-06-09 23:22:44 +00:00
|
|
|
}
|
|
|
|
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();
|
2021-06-30 20:40:20 +00:00
|
|
|
try expectEqualStrings("2011-06-15", metadata.service_metadata.version);
|
2021-05-30 02:33:08 +00:00
|
|
|
}
|
2021-06-10 21:09:22 +00:00
|
|
|
test "can filter services" {
|
2021-07-27 16:40:11 +00:00
|
|
|
const filtered_services = Services(.{ .sts, .wafv2 }){};
|
2021-06-10 21:09:22 +00:00
|
|
|
try expectEqualStrings("2011-06-15", filtered_services.sts.version);
|
|
|
|
}
|