-
Notifications
You must be signed in to change notification settings - Fork 54
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
Feature/is expired#58 #59
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple yet effective PR!
Nice one 😄
src/Context/ApiContext.php
Outdated
* | ||
* @return bool | ||
*/ | ||
public function isExpired() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isExpired(): bool
<- strict return type 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aahhh good old strict type 😁 thx
src/Context/ApiContext.php
Outdated
|
||
/** | ||
* Checks if the session has expired |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps rename this function to something like isSessionExpired
which makes this comment unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Fair enough will make this change in all the SDK's then 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments :)
src/Context/ApiContext.php
Outdated
@@ -273,15 +273,19 @@ private function dropSessionContext() | |||
*/ | |||
public function ensureSessionActive() | |||
{ | |||
if (is_null($this->sessionContext)) { | |||
return; | |||
if (!is_null($this->sessionContext) && $this->isSessionExpired()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check for is_null($this->sessionContext)
can go from here, because you do it in isSessionExpired
already :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you follow my suggestion and change isSessionExpired
to isSessionActive
or hasActiveSession
, Please do not forget to add an exclamation mark here (only reset if NOT has an active session :))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhmm AFAIK if we do this then if session is null it will run in an infinite loop resetting the session. At least that was my expiernce in Java 🤔 will double check to make sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yea! The infinite loop:
Maximum function nesting level of '256' reached, aborting!
And it also fails because:
$timeExpiry = $this->sessionContext->getExpiryTime()->getTimestamp();
This will cause an error as of sessionContext
is null! So therefore we need !is_null($this->sessionContext)
in ensureSessionActive
still 🤔. The null sessionContext
will get handled higher up the code before a request is made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah but then based on your suggestion below this can be fixed 👍
src/Context/ApiContext.php
Outdated
if ($timeExpiry - time() < self::TIME_TO_SESSION_EXPIRY_MINIMUM_SECONDS) { | ||
$this->resetSession(); | ||
} | ||
return is_null($this->sessionContext) || $timeExpiry - time() < self::TIME_TO_SESSION_EXPIRY_MINIMUM_SECONDS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you do is_null($this->sessionContext)
check here, the method can be be opposite to what we've had and be called isSessionActive
or hasActiveSession
. This also fits well into our ensureSessionActive
:)
Also, I'd go for an explanatory variable here. I missed it when initially built ensureSessionActive
%).
So something like this:
if (is_null($this->sessionContext)) {
return false;
} else {
$timeExpiry = $this->sessionContext->getExpiryTime()->getTimestamp();
$timeToExpiry = $timeExpiry - time();
return self::TIME_TO_SESSION_EXPIRY_MINIMUM_SECONDS < $timeToExpiry;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bueno
For the changes in my review: let's have this one merged, and then distribute the approach over the other SDKs :) |
@dnl-blkv As we discussed, this pr is not ready. Fixing the issue in client that is causing the infinite loop due to client also resetting session. This must be prevent for endpoints: |
@dnl-blkv All yours 👀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments %)
src/Http/ApiClient.php
Outdated
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
*/ | ||
class ApiClient | ||
{ | ||
/** | ||
* These are the endpoints where there is no need to have an active session for the request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please go for Endpoints not requiring active session for the request to succeed
(less letters :P)
src/Http/ApiClient.php
Outdated
const INSTALLATION_URL = "installation"; | ||
|
||
const URLS_TO_NOT_ENSURE_ACTIVE_SESSION = [ | ||
self::INSTALLATION_URL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make it an associative array:
const URLS_TO_NOT_ENSURE_ACTIVE_SESSION = [
self::INSTALLATION_URL => true,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
src/Http/ApiClient.php
Outdated
* These are the endpoints where there is no need to have an active session for the request | ||
* to succeed. | ||
*/ | ||
const SESSION_SERVER_URL = "session-server"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use single quotes for the constants!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please post the URIS_NOT_REQUIRING_ACTIVE_SESSION
right after the doc header, and the constants right after it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Java struggles 😁
src/Http/ApiClient.php
Outdated
{ | ||
$this->apiContext->ensureSessionActive(); | ||
if (!in_array($uri, self::URLS_TO_NOT_ENSURE_ACTIVE_SESSION, true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once you have an associative array instead of a list, you can use isset(self::URLS_TO_NOT_ENSURE_ACTIVE_SESSION[$uri])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
src/Http/ApiClient.php
Outdated
const DEVICE_SERVER_URL = "device-server"; | ||
const INSTALLATION_URL = "installation"; | ||
|
||
const URLS_TO_NOT_ENSURE_ACTIVE_SESSION = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say URIS_NOT_REQUIRING_ACTIVE_SESSION
for the sake of consistency :)
Context
#58
What has been done
This pr introduces a new way to handle
SessionContext
. Now it is possible to do the following:This way there is no saving an unchanged context.
Closes #58