provide consumers a way to change order of precedence based on cli flag

This commit is contained in:
Emil Lerch 2026-02-02 17:11:18 -08:00
parent 686b18d1f4
commit 31240cd21e
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -69,6 +69,11 @@ pub const Profile = struct {
config_file: ?[]const u8 = null,
/// Config file. Defaults to AWS_PROFILE or default
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 {
@ -79,6 +84,15 @@ pub var static_credentials: ?auth.Credentials = null;
pub fn getCredentials(allocator: std.mem.Allocator, options: Options) !auth.Credentials {
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| {
log.debug("Found credentials in environment. Access key: {s}", .{cred.access_key});
return cred;