clean up output, move to http status

This commit is contained in:
Emil Lerch 2026-02-04 01:02:13 -08:00
parent b07ae58e08
commit 685cb99f1d
Signed by: lobo
GPG key ID: A7B62D657EF764F8
4 changed files with 21 additions and 14 deletions

View file

@ -1,5 +1,5 @@
[tools]
pre-commit = "4.2.0"
zig = "0.15.2"
zls = "0.15.1"
"ubi:DonIsaac/zlint" = "0.7.6"
prek = "0.3.1"

View file

@ -4,8 +4,8 @@
.fingerprint = 0x6e61de08e7e51114,
.dependencies = .{
.aws = .{
.url = "git+https://git.lerch.org/lobo/aws-sdk-for-zig#c1df6ef3a6f4eb4eb75608c3cc6488cffc300793",
.hash = "aws-0.0.1-SbsFcC47CgCWY3bwHxku5J4BAohk-6UJZEUX1B0azJ_D",
.url = "git+https://git.lerch.org/lobo/aws-sdk-for-zig#5c7aed071f6251d53a1627080a21d604ff58f0a5",
.hash = "aws-0.0.1-SbsFcFE7CgDBilPa15i4gIB6Qr5ozBz328O63abDQDDk",
},
},
.paths = .{

View file

@ -278,7 +278,7 @@ fn deployFunction(deploy_opts: DeployOptions, options: RunOptions) !void {
std.log.info("Attempting to create function: {s}", .{deploy_opts.function_name});
var create_diagnostics = aws.Diagnostics{
.http_code = undefined,
.response_status = undefined,
.response_body = undefined,
.allocator = options.allocator,
};
@ -302,10 +302,9 @@ fn deployFunction(deploy_opts: DeployOptions, options: RunOptions) !void {
.environment = if (env_variables) |vars| .{ .variables = vars } else null,
}, create_options) catch |err| {
defer create_diagnostics.deinit();
std.log.info("CreateFunction returned: error={}, HTTP code={}", .{ err, create_diagnostics.http_code });
// Function already exists (409 Conflict) - update it instead
if (create_diagnostics.http_code == 409) {
if (create_diagnostics.response_status == .conflict) {
std.log.info("Function already exists, updating: {s}", .{deploy_opts.function_name});
const update_result = try aws.Request(services.lambda.update_function_code).call(.{
@ -342,8 +341,10 @@ fn deployFunction(deploy_opts: DeployOptions, options: RunOptions) !void {
return;
}
std.log.err("Lambda CreateFunction failed: {} (HTTP {})", .{ err, create_diagnostics.http_code });
std.log.err(
"Lambda CreateFunction failed: {} (HTTP Response code {})",
.{ err, create_diagnostics.response_status },
);
return error.LambdaCreateFunctionFailed;
};
defer create_result.deinit();
@ -483,7 +484,7 @@ fn addPermission(
std.log.info("Adding invoke permission for principal: {s}", .{principal});
var diagnostics = aws.Diagnostics{
.http_code = undefined,
.response_status = undefined,
.response_body = undefined,
.allocator = options.allocator,
};
@ -500,14 +501,17 @@ fn addPermission(
defer diagnostics.deinit();
// 409 Conflict means permission already exists - that's fine
if (diagnostics.http_code == 409) {
if (diagnostics.response_status == .conflict) {
std.log.info("Permission already exists for: {s}", .{principal});
try options.stdout.print("Permission already exists for: {s}\n", .{principal});
try options.stdout.flush();
return;
}
std.log.err("AddPermission failed: {} (HTTP {})", .{ err, diagnostics.http_code });
std.log.err(
"AddPermission failed: {} (HTTP Response code {})",
.{ err, diagnostics.response_status },
);
return error.AddPermissionFailed;
};
defer result.deinit();

View file

@ -61,7 +61,7 @@ pub fn getOrCreateRole(role_name: []const u8, options: RunOptions) ![]const u8 {
const services = aws.Services(.{.iam}){};
var diagnostics = aws.Diagnostics{
.http_code = undefined,
.response_status = undefined,
.response_body = undefined,
.allocator = options.allocator,
};
@ -74,11 +74,14 @@ pub fn getOrCreateRole(role_name: []const u8, options: RunOptions) ![]const u8 {
.role_name = role_name,
}, aws_options) catch |err| {
defer diagnostics.deinit();
if (diagnostics.http_code == 404) {
if (diagnostics.response_status == .not_found) {
// Role doesn't exist, create it
return try createRole(role_name, options);
}
std.log.err("IAM GetRole failed: {} (HTTP {})", .{ err, diagnostics.http_code });
std.log.err(
"IAM GetRole failed: {} (HTTP Response code {})",
.{ err, diagnostics.response_status },
);
return error.IamGetRoleFailed;
};
defer get_result.deinit();