diff --git a/src/aws_credentials.zig b/src/aws_credentials.zig index 2e79e7c..cc8ad74 100644 --- a/src/aws_credentials.zig +++ b/src/aws_credentials.zig @@ -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;