From 6260849b19cfc8dda7fcf4b9134adc544915b498 Mon Sep 17 00:00:00 2001 From: Dimitris Bozelos Date: Sat, 23 Nov 2024 04:52:02 +0000 Subject: [PATCH] Allow configuring a different parent directory for .aws --- src/AbstractConfigurationProvider.php | 8 ++++++++ src/Configuration/ConfigurationResolver.php | 8 ++++++++ src/Credentials/CredentialProvider.php | 8 ++++++++ src/Token/ParsesIniTrait.php | 8 ++++++++ 4 files changed, 32 insertions(+) diff --git a/src/AbstractConfigurationProvider.php b/src/AbstractConfigurationProvider.php index 78a5cdadaf..28dcd9bd98 100644 --- a/src/AbstractConfigurationProvider.php +++ b/src/AbstractConfigurationProvider.php @@ -85,6 +85,14 @@ public static function chain() */ protected static function getHomeDir() { + // Allow the ".aws" folder containing configuration and credentials to + // exist in another location. In some setups, this allows both the web + // server user (e.g. actions taken via a website UI) and the application + // user (e.g. actions taken via CLI) to properly work. + if ($homeDir = getenv('AWS_HOME')) { + return $homeDir; + } + // On Linux/Unix-like systems, use the HOME environment variable if ($homeDir = getenv('HOME')) { return $homeDir; diff --git a/src/Configuration/ConfigurationResolver.php b/src/Configuration/ConfigurationResolver.php index a08595a75d..42d19d5482 100644 --- a/src/Configuration/ConfigurationResolver.php +++ b/src/Configuration/ConfigurationResolver.php @@ -154,6 +154,14 @@ public static function ini( */ private static function getHomeDir() { + // Allow the ".aws" folder containing configuration and credentials to + // exist in another location. In some setups, this allows both the web + // server user (e.g. actions taken via a website UI) and the application + // user (e.g. actions taken via CLI) to properly work. + if ($homeDir = getenv('AWS_HOME')) { + return $homeDir; + } + // On Linux/Unix-like systems, use the HOME environment variable if ($homeDir = getenv('HOME')) { return $homeDir; diff --git a/src/Credentials/CredentialProvider.php b/src/Credentials/CredentialProvider.php index 57238f0562..48d7966ebd 100644 --- a/src/Credentials/CredentialProvider.php +++ b/src/Credentials/CredentialProvider.php @@ -736,6 +736,14 @@ private static function loadRoleProfile( */ private static function getHomeDir() { + // Allow the ".aws" folder containing configuration and credentials to + // exist in another location. In some setups, this allows both the web + // server user (e.g. actions taken via a website UI) and the application + // user (e.g. actions taken via CLI) to properly work. + if ($homeDir = getenv('AWS_HOME')) { + return $homeDir; + } + // On Linux/Unix-like systems, use the HOME environment variable if ($homeDir = getenv('HOME')) { return $homeDir; diff --git a/src/Token/ParsesIniTrait.php b/src/Token/ParsesIniTrait.php index b96a6d97bc..dbef043ddc 100644 --- a/src/Token/ParsesIniTrait.php +++ b/src/Token/ParsesIniTrait.php @@ -30,6 +30,14 @@ private static function loadProfiles($filename) */ private static function getHomeDir() { + // Allow the ".aws" folder containing configuration and credentials to + // exist in another location. In some setups, this allows both the web + // server user (e.g. actions taken via a website UI) and the application + // user (e.g. actions taken via CLI) to properly work. + if ($homeDir = getenv('AWS_HOME')) { + return $homeDir; + } + // On Linux/Unix-like systems, use the HOME environment variable if ($homeDir = getenv('HOME')) { return $homeDir;