From ff81524caa62bb454e01faa526030d3c978f403d Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Mon, 4 Mar 2024 13:35:57 -0800 Subject: [PATCH] get account id printing with leading zeros --- build.zig | 4 ++-- src/Account.zig | 4 ++-- src/createtable.zig | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.zig b/build.zig index 4879639..b2ffab2 100644 --- a/build.zig +++ b/build.zig @@ -215,7 +215,7 @@ fn generateCredentials(s: *std.build.Step, prog_node: *std.Progress.Node) error{ // }, // ) catch return error.MakeFailed; stdout.print( - "# access_key: ELAK{s}, secret_key: {s}, account_number: {d}, db_encryption_key: {s}", + "# access_key: ELAK{s}, secret_key: {s}, account_number: {d:0>12}, db_encryption_key: {s}", .{ access_key_suffix_encoded, encoded_secret, @@ -224,7 +224,7 @@ fn generateCredentials(s: *std.build.Step, prog_node: *std.Progress.Node) error{ }, ) catch return error.MakeFailed; stdout.print( - "\n#\n# You can copy/paste the following line into access_keys.csv:\nELAK{s},{s},{d},{s}\n", + "\n#\n# You can copy/paste the following line into access_keys.csv:\nELAK{s},{s},{d:0>12},{s}\n", .{ access_key_suffix_encoded, encoded_secret, diff --git a/src/Account.zig b/src/Account.zig index cf7b4a9..12d5e32 100644 --- a/src/Account.zig +++ b/src/Account.zig @@ -38,7 +38,7 @@ pub fn accountForId(allocator: std.mem.Allocator, account_id: u40) !Self { } // TODO: Check STS - log.err("Got account id '{d}', but could not find this ('1234' is test account). STS GetAccessKeyInfo not implemented", .{account_id}); + log.err("Got account id '{d:0>12}', but could not find this ('1234' is test account). STS GetAccessKeyInfo not implemented", .{account_id}); return error.NotImplemented; } @@ -66,7 +66,7 @@ pub fn dbForAccount(allocator: std.mem.Allocator, account_id: u40) !*sqlite.Db { // TODO: Need to move this function somewhere central // TODO: Need configuration for what directory to use // TODO: Should this be a pool, and if so, how would we know when to close? - const file_without_path = try std.fmt.allocPrint(allocator, "ddb-{d}.sqlite3", .{account_id}); + const file_without_path = try std.fmt.allocPrint(allocator, "ddb-{d:0>12}.sqlite3", .{account_id}); defer allocator.free(file_without_path); const db_file_name = try std.fs.path.joinZ(allocator, &[_][]const u8{ data_dir, file_without_path }); defer allocator.free(db_file_name); diff --git a/src/createtable.zig b/src/createtable.zig index 73d9074..8f7e5df 100644 --- a/src/createtable.zig +++ b/src/createtable.zig @@ -144,7 +144,7 @@ pub fn handler(request: *AuthenticatedRequest, writer: anytype) ![]const u8 { var al = std.ArrayList(u8).init(allocator); var response_writer = al.writer(); - try response_writer.print("table created for account {d}\n", .{account_id}); + try response_writer.print("table created for account {d:0>12}\n", .{account_id}); return al.toOwnedSlice(); }