Commit e6e6176e authored by davisben's avatar davisben
Browse files

Issue #3317272 by davisben: Ensure a profile exists before attempting to create a client

parent 07b73816
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Drupal\aws;

use Drupal\aws\Entity\ProfileInterface;
use Drupal\aws\Exception\ProfileException;
use Drupal\aws\Traits\AwsServiceTrait;

/**
@@ -36,15 +37,18 @@ class AwsClientFactory implements AwsClientFactoryInterface {
    $service = $this->aws->getService($service_id);

    if ($this->profile) {
      $client_args = $this->profile->getClientArgs();
      $profile = $this->profile;
    }
    else {
      $profile = $this->aws->getProfile($service_id);
      $client_args = $profile->getClientArgs();
    }

    if (!$profile) {
      throw new ProfileException('No AWS profiles have been configured.');
    }

    $class = "\Aws\\{$service['namespace']}\\{$service['namespace']}Client";
    return new $class($client_args);
    return new $class($profile->getClientArgs());
  }

}
+12 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\aws\Exception;

/**
 * AWS Profile Exception.
 */
class ProfileException extends \Exception {

}