provide consumers a way to change order of precedence based on cli flag
This commit is contained in:
parent
686b18d1f4
commit
31240cd21e
1 changed files with 14 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue