Skip to content

feat: Allows for a user to utilize self-signed certificates #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ class Client
*/
protected $savedRequests;

/**
* @var bool
*/
protected $verifySSLCerts;

/**
* @var bool
*/
Expand All @@ -212,27 +217,30 @@ class Client
/**
* Initialize the client.
*
* @param string $host the base url (e.g. https://api.sendgrid.com)
* @param array $headers global request headers
* @param string $version api version (configurable) - this is specific to the SendGrid API
* @param array $path holds the segments of the url path
* @param array $curlOptions extra options to set during curl initialization
* @param bool $retryOnLimit set default retry on limit flag
* @param string $host the base url (e.g. https://api.sendgrid.com)
* @param array $headers global request headers
* @param string $version api version (configurable) - this is specific to the SendGrid API
* @param array $path holds the segments of the url path
* @param array $curlOptions extra options to set during curl initialization
* @param bool $retryOnLimit set default retry on limit flag
* @param bool $verifySSLCerts set default verify certificates flag
*/
public function __construct(
$host,
$headers = null,
$version = null,
$path = null,
$curlOptions = null,
$retryOnLimit = false
$retryOnLimit = false,
$verifySSLCerts = true
) {
$this->host = $host;
$this->headers = $headers ?: [];
$this->version = $version;
$this->path = $path ?: [];
$this->curlOptions = $curlOptions ?: [];
$this->retryOnLimit = $retryOnLimit;
$this->verifySSLCerts = $verifySSLCerts;
$this->isConcurrentRequest = false;
$this->savedRequests = [];
}
Expand Down Expand Up @@ -306,7 +314,21 @@ public function setRetryOnLimit($retry)
}

/**
* Set concurrent request flag.
* Set default verify certificates flag
*
* @param bool $verifySSLCerts
*
* @return Client
*/
public function setVerifySSLCerts($verifySSLCerts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only has the setVerifySSLCerts method.

Do we need to add the getVerifySSLCerts method?

I think we have this method to get current $verifySSLCerts value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine as-is. We don't have getters for the other options.

{
$this->verifySSLCerts = $verifySSLCerts;

return $this;
}

/**
* Set concurrent request flag
*
* @param bool $isConcurrent
*
Expand Down Expand Up @@ -352,7 +374,7 @@ private function createCurlOptions($method, $body = null, $headers = null)
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_CUSTOMREQUEST => strtoupper($method),
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYPEER => $this->verifySSLCerts,
CURLOPT_FAILONERROR => false,
] + $this->curlOptions;

Expand Down Expand Up @@ -572,6 +594,7 @@ public function _($name = null)
}
$client = new static($this->host, $this->headers, $this->version, $this->path);
$client->setCurlOptions($this->curlOptions);
$client->setVerifySSLCerts($this->verifySSLCerts);
$client->setRetryOnLimit($this->retryOnLimit);
$this->path = [];

Expand Down