@param string $region
@param mixed $credential

@return Ec2Client|null
188981
public function getEC2($region, $credential)
    {
        if (!$config = $this->getConfigWithCredentials($region, $credential)) {
            return null;
        }

        return $this->aws->createEc2($config);
    }
516224
public function authenticate(string $credential, string $password = null): ?UserInterface
    {
        $user = $this->users->read($credential);

        if ($user) {
            if ($password && !$this->verifyPassword($user, $password)) {
                return null;
            }

            return ($this->userFactory)(
                $this->users->getIdentifier(),
                $this->getRoles($credential),
                $this->getDetails($user)
            );
        }

        return null;
    }
1207224
public function getELB($region, $credential)
    {
        if (!$config = $this->getConfigWithCredentials($region, $credential)) {
            return null;
        }

        return $this->aws->createElasticLoadBalancing($config);
    }
1248854
public function getGoogleClient($credential_id = null, $use_own_certificate = true)
    {
        return $this->getApiModel()->getClient($credential_id, $use_own_certificate);
    }
1277612
public function setRegionDestination(\Core\Entity\DeliveryRegion $region_destination = null) {
        $this->region_destination = $region_destination;

        return $this;
    }
1282783
protected function setCredential(array $credential)
    {
        $cacheKey = $this->getAccessTokenCacheKey();
        $this->cache->set($cacheKey, $credential);

        return $this;
    }
654623
public function isTransversalContextRegion($region, $theme)
    {
        $regions = $this->getThemeRegionConfig($theme);
        return (isset($regions[$region]) && ($regions[$region] === self::CONTEXT_SITE));
    }
123471
public function getClient($credential_id = null, $use_own_certificate = true)
    {
        $this->library->load('gapi');

        if (!class_exists('Google_Client')) {
            throw new LogicException('Class \Google_Client not found');
        }

        $client = new \Google_Client;

        if ($use_own_certificate) {
            $http = new Client(array('verify' => __DIR__ . '/../certificates/cacert.pem'));
            $client->setHttpClient($http);
        }

        if (isset($credential_id)) {

            $credential = $this->credential->get($credential_id);

            if (empty($credential['data']['file'])) {
                throw new OutOfBoundsException('Credential file path is empty');
            }

            $client->setAuthConfig(gplcart_file_absolute($credential['data']['file']));
        }


        return $client;
    }
1248751
public function getRoleCredentials(AWSRoleCredential $credential, $region)
    {
        if (!$sts = $this->getStsWithInternalCredentials($region)) {
            return null;
        }

        $account = $credential->account();
        $role = $credential->role();
        $cacheKey = sprintf('%s_%s', $account, $role);

        $assumeRoleProvider = AWSCredentialProvider::assumeRole([
            'client' => $sts,
            'assume_role_params' => [
                'DurationSeconds' => $this->stsLifetime, # 900 - 3600
                'RoleArn' => sprintf('arn:aws:iam::%s:%s', $account, $role),
                'RoleSessionName' => 'hal-' . bin2hex(random_bytes(4)), # unique identifier for auditing
            ],
        ]);

        $provider = AWSCredentialProvider::memoize($assumeRoleProvider);
        if ($this->credentialCache) {
            $provider = AWSCredentialProvider::cache($provider, $this->credentialCache, $cacheKey);
        }

        return $provider;
    }
441223
private static function _buildConfigArray($keyId = null, $secret = null, $region = null)
    {
        $config = [
            'region' => $region,
            'version' => 'latest'
        ];

        if (empty($keyId) || empty($secret)) {
            // Assume we're running on EC2 and we have an IAM role assigned. Kick back and relax.
        } else {
            $tokenKey = static::CACHE_KEY_PREFIX . md5($keyId . $secret);
            $credentials = new Credentials($keyId, $secret);

            if (Craft::$app->cache->exists($tokenKey)) {
                $cached = Craft::$app->cache->get($tokenKey);
                $credentials->unserialize($cached);
            } else {
                $config['credentials'] = $credentials;
                $stsClient = new StsClient($config);
                $result = $stsClient->getSessionToken(['DurationSeconds' => static::CACHE_DURATION_SECONDS]);
                $credentials = $stsClient->createCredentials($result);
                Craft::$app->cache->set($tokenKey, $credentials->serialize(), static::CACHE_DURATION_SECONDS);
            }

            // TODO Add support for different credential supply methods
            $config['credentials'] = $credentials;
        }

        $client = Craft::createGuzzleClient();
        $config['http_handler'] = new GuzzleHandler($client);

        return $config;
    }
819859
public function authenticate(Credential $credential)
    {
        $username = $credential->username;
        $password = $credential->password;

        if (!$username || !$password) {
            $this->status = Authentication::EMPTY_CREDENTIAL;

            return false;
        }

        foreach ($this->users as $user) {
            if (!isset($user['username'])) {
                continue;
            }

            if ($user['username'] !== $username) {
                continue;
            }

            if (!isset($user['password'])) {
                $this->status = Authentication::INVALID_CREDENTIAL;

                return false;
            }

            $handler = $this->getVerifyHandler();

            if (call_user_func_array($handler, [$password, $user['password']])) {
                $this->status = Authentication::SUCCESS;

                return true;
            }

            $this->status = Authentication::INVALID_CREDENTIAL;

            return false;
        }

        $this->status = Authentication::USER_NOT_FOUND;

        return false;
    }
450160
protected function getClient() {
        if ($this->client === null) {
            $params = [
                'credentials' => [
                    'key' => $this->params['key'],
                    'secret' => $this->params['secret'],
                ],
                'version' => $this->params['version'],
            ];

            if ($this->params['region']) {
                $params['region'] = $this->params['region'];
            }

            $this->client = new S3Client($params);
        }

        return $this->client;
    }
392232
public function create($data, $credentialId = null)
    {
        if (isset($credentialId)) {
            return $this->client()->put($data, 'credentials/{credentialId}', ['credentialId' => $credentialId]);
        }

        return $this->client()->post($data, 'credentials');
    }
778207
public function constructBridge($credential, $service = null, $authMethod = 'credentials')
    {
        // Get credentials array.
        $credentials = $this->getCredentials($credential);

        // Make sure credentials information is available.
        if (! isset($credentials['username']) || ! isset($credentials['password']) || ! isset($credentials['gateway'])) {
            throw new WatsonBridgeException('Could not construct Bridge, missing some information in credentials.',
                                            500);
        }

        // Make bridge.
        $bridge = $this->makeRawBridge()
                       ->setUsername($credentials['username'])
                       ->setPassword($credentials['password'])
                       ->setEndPoint($credentials['gateway'])
                       ->setClient($credentials['gateway'])
                       ->appendHeaders(['X-Watson-Learning-Opt-Out' => config('watson-bridge.x_watson_learning_opt_out')]);

        // Add service.
        $bridge = $this->addServiceToBridge($bridge, $service);

        // Choose an auth method.
        $bridge = $this->chooseAuthMethodForBridge($bridge, $authMethod);

        return $bridge;
    }
350677
public function getCredentials(Request $request)
    {
        $post = json_decode($request->getContent(), true);

        return new CredentialTokenModel($post[self::TOKEN_FIELD]);
    }
887315
private AmazonEC2 getEC2Service() {
        String aWSAccessId = serverConfig.getAWSAccessId();
        String aWSSecretKey = serverConfig.getAWSSecretKey();

        AmazonEC2 ec2Service;
        if (null != aWSAccessId && !"".equals(aWSAccessId)
                && null != aWSSecretKey && !"".equals(aWSSecretKey)) {
            ec2Service = new AmazonEC2Client(new BasicAWSCredentials(aWSAccessId, aWSSecretKey));
        } else {
            ec2Service = new AmazonEC2Client(new InstanceProfileCredentialsProvider());
        }

        String region = clientConfig.getRegion();
        region = region.trim().toLowerCase();
        ec2Service.setEndpoint("ec2." + region + ".amazonaws.com");
        return ec2Service;
    }
750285
public function getS3($region, $credential)
    {
        if (!$config = $this->getConfigWithCredentials($region, $credential)) {
            return null;
        }

        return $this->aws->createS3($config);
    }