Compare commits

..

2 commits

Author SHA1 Message Date
4df27142d0
fix issue with config file reading the wrong options
Some checks failed
AWS-Zig Build / build-zig-amd64-host (push) Failing after 14m17s
2026-02-02 17:11:44 -08:00
31240cd21e
provide consumers a way to change order of precedence based on cli flag 2026-02-02 17:11:18 -08:00

View file

@ -69,6 +69,11 @@ pub const Profile = struct {
config_file: ?[]const u8 = null, config_file: ?[]const u8 = null,
/// Config file. Defaults to AWS_PROFILE or default /// Config file. Defaults to AWS_PROFILE or default
profile_name: ?[]const u8 = null, profile_name: ?[]const u8 = null,
/// Profile name specified via command line should change precedence of operation,
/// moves credential file checking to the top. The sdk does not have a
/// way to know if this is coming from a command line, so this field
/// serves as a way to accomplish that task
prefer_profile_from_file: bool = false,
}; };
pub const Options = struct { pub const Options = struct {
@ -79,6 +84,15 @@ pub var static_credentials: ?auth.Credentials = null;
pub fn getCredentials(allocator: std.mem.Allocator, options: Options) !auth.Credentials { pub fn getCredentials(allocator: std.mem.Allocator, options: Options) !auth.Credentials {
if (static_credentials) |c| return c; if (static_credentials) |c| return c;
if (options.profile.prefer_profile_from_file) {
log.debug(
"Command line profile specified. Checking credentials file first. Profile name {s}",
.{options.profile.profile_name orelse "default"},
);
if (try getProfileCredentials(allocator, options.profile)) |cred| return cred;
// Profile not found. We'll mirror the cli here and bail early
return error.CredentialsNotFound;
}
if (try getEnvironmentCredentials(allocator)) |cred| { if (try getEnvironmentCredentials(allocator)) |cred| {
log.debug("Found credentials in environment. Access key: {s}", .{cred.access_key}); log.debug("Found credentials in environment. Access key: {s}", .{cred.access_key});
return cred; return cred;
@ -398,8 +412,8 @@ fn getProfileCredentials(allocator: std.mem.Allocator, options: Profile) !?auth.
default_path = default_path orelse creds_file_path.home; default_path = default_path orelse creds_file_path.home;
const config_file_path = try filePath( const config_file_path = try filePath(
allocator, allocator,
options.credential_file, options.config_file,
"AWS_SHARED_CREDENTIALS_FILE", "AWS_CONFIG_FILE",
default_path, default_path,
"config", "config",
); );