From c6dbbf33af0a019b7d8261bcbc20482f7b6e5c46 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Wed, 9 Jun 2021 16:25:49 -0700 Subject: [PATCH] allow different endpoing/sigv4 service names This seems silly, but I guess in AWS it is a thing that these two values may be different. Consumers of awshttp have the option of ignoring this, which should be correct most of the time. Aws.zig will, however, use the service metadata to do the right thing --- src/aws.zig | 16 ++++++++++++++-- src/awshttp.zig | 5 +++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/aws.zig b/src/aws.zig index e2cc7f3..d6e5ec9 100644 --- a/src/aws.zig +++ b/src/aws.zig @@ -6,7 +6,10 @@ const servicemodel = @import("servicemodel.zig"); const log = std.log.scoped(.aws); -pub const Options = awshttp.Options; +pub const Options = struct { + region: []const u8 = "aws-global", + dualstack: bool = false, +}; pub const services = servicemodel.services; @@ -39,7 +42,16 @@ pub const Aws = struct { log.debug("service sigv4 name {s}", .{service.sigv4_name}); log.debug("version {s}", .{service.version}); log.debug("action {s}", .{action.action_name}); - const response = try self.aws_http.callApi(action_info.service, service.version, action.action_name, options); + const response = try self.aws_http.callApi( + service.endpoint_prefix, + service.version, + action.action_name, + .{ + .region = options.region, + .dualstack = options.dualstack, + .sigv4_service_name = service.sigv4_name, + }, + ); defer response.deinit(); // TODO: Check status code for badness var stream = json.TokenStream.init(response.body); diff --git a/src/awshttp.zig b/src/awshttp.zig index f8b17a6..3e38b22 100644 --- a/src/awshttp.zig +++ b/src/awshttp.zig @@ -67,9 +67,10 @@ pub const AwsError = error{ pub const Options = struct { region: []const u8 = "aws-global", dualstack: bool = false, + sigv4_service_name: ?[]const u8 = null, }; -pub const SigningOptions = struct { +const SigningOptions = struct { region: []const u8 = "aws-global", service: []const u8, }; @@ -240,7 +241,7 @@ pub const AwsHttp = struct { httplog.debug("Calling {s}.{s}, endpoint {s}", .{ service, action, endpoint.uri }); const signing_options: SigningOptions = .{ .region = options.region, - .service = service, + .service = if (options.sigv4_service_name) |name| name else service, }; return try self.makeRequest(endpoint, "POST", "/", body, signing_options); }