Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 46... Línea 46...
46
    const ENV_ARN = 'AWS_ROLE_ARN';
46
    const ENV_ARN = 'AWS_ROLE_ARN';
47
    const ENV_KEY = 'AWS_ACCESS_KEY_ID';
47
    const ENV_KEY = 'AWS_ACCESS_KEY_ID';
48
    const ENV_PROFILE = 'AWS_PROFILE';
48
    const ENV_PROFILE = 'AWS_PROFILE';
49
    const ENV_ROLE_SESSION_NAME = 'AWS_ROLE_SESSION_NAME';
49
    const ENV_ROLE_SESSION_NAME = 'AWS_ROLE_SESSION_NAME';
50
    const ENV_SECRET = 'AWS_SECRET_ACCESS_KEY';
50
    const ENV_SECRET = 'AWS_SECRET_ACCESS_KEY';
-
 
51
    const ENV_ACCOUNT_ID = 'AWS_ACCOUNT_ID';
51
    const ENV_SESSION = 'AWS_SESSION_TOKEN';
52
    const ENV_SESSION = 'AWS_SESSION_TOKEN';
52
    const ENV_TOKEN_FILE = 'AWS_WEB_IDENTITY_TOKEN_FILE';
53
    const ENV_TOKEN_FILE = 'AWS_WEB_IDENTITY_TOKEN_FILE';
53
    const ENV_SHARED_CREDENTIALS_FILE = 'AWS_SHARED_CREDENTIALS_FILE';
54
    const ENV_SHARED_CREDENTIALS_FILE = 'AWS_SHARED_CREDENTIALS_FILE';
Línea 54... Línea 55...
54
 
55
 
Línea 289... Línea 290...
289
    {
290
    {
290
        return function () {
291
        return function () {
291
            // Use credentials from environment variables, if available
292
            // Use credentials from environment variables, if available
292
            $key = getenv(self::ENV_KEY);
293
            $key = getenv(self::ENV_KEY);
293
            $secret = getenv(self::ENV_SECRET);
294
            $secret = getenv(self::ENV_SECRET);
-
 
295
            $accountId = getenv(self::ENV_ACCOUNT_ID) ?: null;
-
 
296
            $token = getenv(self::ENV_SESSION) ?: null;
-
 
297
 
294
            if ($key && $secret) {
298
            if ($key && $secret) {
295
                return Promise\Create::promiseFor(
299
                return Promise\Create::promiseFor(
-
 
300
                    new Credentials(
-
 
301
                        $key,
-
 
302
                        $secret,
-
 
303
                        $token,
-
 
304
                        null,
-
 
305
                        $accountId,
296
                    new Credentials($key, $secret, getenv(self::ENV_SESSION) ?: NULL)
306
                        CredentialSources::ENVIRONMENT
-
 
307
                    )
297
                );
308
                );
298
            }
309
            }
Línea 299... Línea 310...
299
 
310
 
300
            return self::reject('Could not find environment variable '
311
            return self::reject('Could not find environment variable '
Línea 405... Línea 416...
405
                $provider = new AssumeRoleWithWebIdentityCredentialProvider([
416
                $provider = new AssumeRoleWithWebIdentityCredentialProvider([
406
                    'RoleArn' => $arnFromEnv,
417
                    'RoleArn' => $arnFromEnv,
407
                    'WebIdentityTokenFile' => $tokenFromEnv,
418
                    'WebIdentityTokenFile' => $tokenFromEnv,
408
                    'SessionName' => $sessionName,
419
                    'SessionName' => $sessionName,
409
                    'client' => $stsClient,
420
                    'client' => $stsClient,
410
                    'region' => $region
421
                    'region' => $region,
-
 
422
                    'source' => CredentialSources::ENVIRONMENT_STS_WEB_ID_TOKEN
411
                ]);
423
                ]);
Línea 412... Línea 424...
412
 
424
 
413
                return $provider();
425
                return $provider();
Línea 434... Línea 446...
434
                    $provider = new AssumeRoleWithWebIdentityCredentialProvider([
446
                    $provider = new AssumeRoleWithWebIdentityCredentialProvider([
435
                        'RoleArn' => $profile['role_arn'],
447
                        'RoleArn' => $profile['role_arn'],
436
                        'WebIdentityTokenFile' => $profile['web_identity_token_file'],
448
                        'WebIdentityTokenFile' => $profile['web_identity_token_file'],
437
                        'SessionName' => $sessionName,
449
                        'SessionName' => $sessionName,
438
                        'client' => $stsClient,
450
                        'client' => $stsClient,
439
                        'region' => $region
451
                        'region' => $region,
-
 
452
                        'source' => CredentialSources::PROFILE_STS_WEB_ID_TOKEN
440
                    ]);
453
                    ]);
Línea 441... Línea 454...
441
 
454
 
442
                    return $provider();
455
                    return $provider();
443
                }
456
                }
Línea 539... Línea 552...
539
 
552
 
540
            return Promise\Create::promiseFor(
553
            return Promise\Create::promiseFor(
541
                new Credentials(
554
                new Credentials(
542
                    $data[$profile]['aws_access_key_id'],
555
                    $data[$profile]['aws_access_key_id'],
543
                    $data[$profile]['aws_secret_access_key'],
556
                    $data[$profile]['aws_secret_access_key'],
-
 
557
                    $data[$profile]['aws_session_token'],
-
 
558
                    null,
-
 
559
                    $data[$profile]['aws_account_id'] ?? null,
544
                    $data[$profile]['aws_session_token']
560
                    CredentialSources::PROFILE
545
                )
561
                )
546
            );
562
            );
547
        };
563
        };
Línea 614... Línea 630...
614
 
630
 
615
            if (empty($processData['SessionToken'])) {
631
            if (empty($processData['SessionToken'])) {
616
                $processData['SessionToken'] = null;
632
                $processData['SessionToken'] = null;
Línea -... Línea 633...
-
 
633
            }
-
 
634
 
-
 
635
            $accountId = null;
-
 
636
            if (!empty($processData['AccountId'])) {
-
 
637
                $accountId = $processData['AccountId'];
-
 
638
            } elseif (!empty($data[$profile]['aws_account_id'])) {
-
 
639
                $accountId = $data[$profile]['aws_account_id'];
617
            }
640
            }
618
 
641
 
619
            return Promise\Create::promiseFor(
642
            return Promise\Create::promiseFor(
620
                new Credentials(
643
                new Credentials(
621
                    $processData['AccessKeyId'],
644
                    $processData['AccessKeyId'],
622
                    $processData['SecretAccessKey'],
645
                    $processData['SecretAccessKey'],
-
 
646
                    $processData['SessionToken'],
-
 
647
                    $expires,
623
                    $processData['SessionToken'],
648
                    $accountId,
624
                    $expires
649
                    CredentialSources::PROFILE_PROCESS
625
                )
650
                )
626
            );
651
            );
Línea 702... Línea 727...
702
 
727
 
703
        $result = $stsClient->assumeRole([
728
        $result = $stsClient->assumeRole([
704
            'RoleArn' => $roleArn,
729
            'RoleArn' => $roleArn,
705
            'RoleSessionName' => $roleSessionName
730
            'RoleSessionName' => $roleSessionName
-
 
731
        ]);
-
 
732
        $credentials = $stsClient->createCredentials(
-
 
733
            $result,
-
 
734
            CredentialSources::STS_ASSUME_ROLE
Línea 706... Línea -...
706
        ]);
-
 
707
 
735
        );
708
        $credentials = $stsClient->createCredentials($result);
736
 
Línea 709... Línea 737...
709
        return Promise\Create::promiseFor($credentials);
737
        return Promise\Create::promiseFor($credentials);
710
    }
738
    }
Línea 889... Línea 917...
889
            $ssoProfile,
917
            $ssoProfile,
890
            $ssoSession['sso_region'],
918
            $ssoSession['sso_region'],
891
            $token->getToken(),
919
            $token->getToken(),
892
            $config
920
            $config
893
        );
921
        );
-
 
922
 
-
 
923
        //Expiration value is returned in epoch milliseconds. Conversion to seconds
894
        $expiration = $ssoCredentials['expiration'];
924
        $expiration = intdiv($ssoCredentials['expiration'], 1000);
895
        return Promise\Create::promiseFor(
925
        return Promise\Create::promiseFor(
896
            new Credentials(
926
            new Credentials(
897
                $ssoCredentials['accessKeyId'],
927
                $ssoCredentials['accessKeyId'],
898
                $ssoCredentials['secretAccessKey'],
928
                $ssoCredentials['secretAccessKey'],
899
                $ssoCredentials['sessionToken'],
929
                $ssoCredentials['sessionToken'],
900
                $expiration
930
                $expiration,
-
 
931
                $ssoProfile['sso_account_id'],
-
 
932
                CredentialSources::PROFILE_SSO
901
            )
933
            )
902
        );
934
        );
903
    }
935
    }
Línea 904... Línea 936...
904
 
936
 
Línea 954... Línea 986...
954
        return Promise\Create::promiseFor(
986
        return Promise\Create::promiseFor(
955
            new Credentials(
987
            new Credentials(
956
                $ssoCredentials['accessKeyId'],
988
                $ssoCredentials['accessKeyId'],
957
                $ssoCredentials['secretAccessKey'],
989
                $ssoCredentials['secretAccessKey'],
958
                $ssoCredentials['sessionToken'],
990
                $ssoCredentials['sessionToken'],
959
                $expiration
991
                $expiration,
-
 
992
                $ssoProfile['sso_account_id'],
-
 
993
                CredentialSources::PROFILE_SSO_LEGACY
960
            )
994
            )
961
        );
995
        );
962
    }
996
    }
963
    /**
997
    /**
964
     * @param array $ssoProfile
998
     * @param array $ssoProfile