File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 3434 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3535 */
3636class aws_sdk {
37+ /**
38+ * Required AWS config names.
39+ */
40+ const REQUIRED_CONFIGS = ['key ' , 'secret ' , 'region ' ];
41+
3742 /**
3843 * Autoload the AWS SDK classes.
3944 */
4045 public static function autoload () {
4146 require_once (__DIR__ .'/../vendor/autoload.php ' );
4247 }
48+
49+ /**
50+ * Extract region, key and secret from CFG global.
51+ *
52+ * @param string $name The CFG config name
53+ * @return array
54+ */
55+ public static function config_from_cfg ($ name ) {
56+ global $ CFG ;
57+
58+ if (empty ($ CFG ->$ name )) {
59+ throw new \coding_exception ('The $CFG-> ' .$ name .' must be set ' );
60+ }
61+ if (!is_array ($ CFG ->$ name )) {
62+ throw new \coding_exception ('The $CFG-> ' .$ name .' must be set to an array ' );
63+ }
64+ $ cfg = $ CFG ->$ name ;
65+ foreach (self ::REQUIRED_CONFIGS as $ key ) {
66+ if (!array_key_exists ($ key , $ cfg )) {
67+ throw new \coding_exception ('The $CFG-> ' .$ name .' is missing the \'' .$ key .'\' option. ' .
68+ 'Required configs: ' .implode (', ' , self ::REQUIRED_CONFIGS ));
69+ }
70+ }
71+
72+ return [
73+ 'region ' => $ cfg ['region ' ],
74+ 'credentials ' => [
75+ 'key ' => $ cfg ['key ' ],
76+ 'secret ' => $ cfg ['secret ' ]
77+ ],
78+ ];
79+ }
4380}
You can’t perform that action at this time.
0 commit comments