Skip to content
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

replace guzzle with amphp/http-client and revolt/event-loop #500

Merged
merged 30 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1be28f3
SQUASH: ping on upload
Jun 27, 2024
94b6711
fixes defaulting the environment variables
unglaublicherdude Jun 28, 2024
225fc83
constantly ping while uploading
unglaublicherdude Jun 28, 2024
d1d7b3a
leave Guzzle Behind and use React/Http instead
unglaublicherdude Jun 28, 2024
2abfed5
Adding a Test for 64MB upload
unglaublicherdude Jun 29, 2024
7892c05
add debug output
unglaublicherdude Jun 29, 2024
f5715aa
use async await
ata-no-one Jun 29, 2024
d2a2b1e
cancel timer
ata-no-one Jun 29, 2024
a018da8
set the minimum elapsed time since the last ping to 15 seconds, so we…
ata-no-one Jun 30, 2024
ccdf370
refactor logging
ata-no-one Jul 1, 2024
8484d4f
change parameter position
ata-no-one Jul 1, 2024
15251af
Add bootstrap
ata-no-one Jul 1, 2024
b5f0ff5
add a test for "long" uploads
ata-no-one Jul 1, 2024
7b974eb
remove the ChunkedStringStreamer
ata-no-one Jul 1, 2024
948d3b6
actually it are 11 seconds
ata-no-one Jul 1, 2024
9c73978
use browsers built-in timeout
ata-no-one Jul 1, 2024
0125bcb
replace guzzle http
unglaublicherdude Jul 2, 2024
cd04192
cd
ata-no-one Jul 2, 2024
15ec3bd
the order matters, or we have to basically control how the stream is …
ata-no-one Jul 2, 2024
bd282fa
to get an understanding on what happens within the loop I added an ad…
ata-no-one Jul 2, 2024
901a69d
pausing the body stream from the first request does not work either
ata-no-one Jul 3, 2024
e4e4141
replace react with amphp and revolt
ata-no-one Jul 3, 2024
cf465bf
remove the branch filter
unglaublicherdude Jul 4, 2024
e6a9a8e
Revert "remove the branch filter"
unglaublicherdude Jul 4, 2024
f4311b6
Update php/src/vaas/Vaas.php
unglaublicherdude Jul 4, 2024
4289216
Update php/src/vaas/Vaas.php
unglaublicherdude Jul 4, 2024
562674b
Update php/tests/vaas/VaasTest.php
unglaublicherdude Jul 4, 2024
d25d66f
Update php/src/vaas/Authentication/OAuth2TokenReceiver.php
unglaublicherdude Jul 5, 2024
3c717c5
remove unused function
unglaublicherdude Jul 5, 2024
c0e043c
remove GuzzleException
ata-no-one Jul 10, 2024
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
3 changes: 3 additions & 0 deletions .github/workflows/image-retention.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
branches:
- "*"
- "!main" # excludes main
paths:
GermanCoding marked this conversation as resolved.
Show resolved Hide resolved
- "github-actions/cleanup-packages/**"
- ".github/workflows/image-retention.yaml"
workflow_dispatch:

jobs:
Expand Down
2 changes: 1 addition & 1 deletion php/examples/VaasExample/AuthenticationExamples.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace VaasExamples;

use VaasSdk\ClientCredentialsGrantAuthenticator;
use VaasSdk\Authentication\ClientCredentialsGrantAuthenticator;
use VaasSdk\Exceptions\InvalidSha256Exception;
use VaasSdk\Exceptions\TimeoutException;
use VaasSdk\Exceptions\VaasAuthenticationException;
Expand Down
4 changes: 2 additions & 2 deletions php/examples/VaasExample/GetVerdictByFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace VaasExamples;

use VaasSdk\ClientCredentialsGrantAuthenticator;
use VaasSdk\Authentication\ClientCredentialsGrantAuthenticator;
use VaasSdk\Vaas;

include_once("./vendor/autoload.php");

$authenticator = new ClientCredentialsGrantAuthenticator(
getenv("CLIENT_ID"),
getenv("CLIENT_SECRET"),
getenv("TOKEN_URL") ?? "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
getenv("TOKEN_URL") ?: "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
);

$vaas = new Vaas(
Expand Down
6 changes: 3 additions & 3 deletions php/examples/VaasExample/GetVerdictByHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace VaasExamples;

use VaasSdk\ClientCredentialsGrantAuthenticator;
use VaasSdk\Authentication\ClientCredentialsGrantAuthenticator;
use VaasSdk\Vaas;

include_once("./vendor/autoload.php");

$authenticator = new ClientCredentialsGrantAuthenticator(
getenv("CLIENT_ID"),
getenv("CLIENT_SECRET"),
getenv("TOKEN_URL") ?? "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
getenv("TOKEN_URL") ?: "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
);
$vaas = new Vaas(
getenv("VAAS_URL") ?? "wss://gateway.production.vaas.gdatasecurity.de"
getenv("VAAS_URL") ?: "wss://gateway.production.vaas.gdatasecurity.de"
);
$vaas->Connect($authenticator->getToken());

Expand Down
6 changes: 3 additions & 3 deletions php/examples/VaasExample/GetVerdictByUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace VaasExamples;

use VaasSdk\ClientCredentialsGrantAuthenticator;
use VaasSdk\Authentication\ClientCredentialsGrantAuthenticator;
use VaasSdk\Vaas;

include_once("./vendor/autoload.php");

$authenticator = new ClientCredentialsGrantAuthenticator(
getenv("CLIENT_ID"),
getenv("CLIENT_SECRET"),
getenv("TOKEN_URL") ?? "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
getenv("TOKEN_URL") ?: "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
);
$vaas = new Vaas(
getenv("VAAS_URL") ?? "wss://gateway.production.vaas.gdatasecurity.de"
getenv("VAAS_URL") ?: "wss://gateway.production.vaas.gdatasecurity.de"
);
$vaas->Connect($authenticator->getToken());

Expand Down
1 change: 1 addition & 0 deletions php/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<phpunit>
<testsuites>
<testsuite name="VaasTesting">
<file>tests/vaas/StreamsInLoopTest.php</file>
<file>tests/vaas/Sha256Test.php</file>
<file>tests/vaas/VaasTest.php</file>
<file>tests/vaas/ProtocolTest.php</file>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace VaasSdk\Authentication;

class ClientCredentialsGrantAuthenticator
{
private OAuth2TokenReceiver $_tokenReceiver;
public function __construct(
string $clientId,
string $clientSecret,
string $tokenEndpoint = "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
) {
$this->_tokenReceiver = new OAuth2TokenReceiver($tokenEndpoint, $clientId, $clientSecret);
}

public function getToken(): string
{
return $this->_tokenReceiver->GetToken();
}
}
69 changes: 69 additions & 0 deletions php/src/vaas/Authentication/OAuth2TokenReceiver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace VaasSdk\Authentication;

use Amp\Http\Client\Form;
use Amp\Http\Client\HttpClient;
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Request;
use Amp\TimeoutCancellation;
use Exception;
use VaasSdk\Exceptions\VaasAuthenticationException;

class OAuth2TokenReceiver {
private string $_tokenEndpoint;
private string $_clientId;
private string $_clientSecret;
private string $_username;
private string $_password;
private string $_grantType;
private Form $_formParams;
private HttpClient $_browser;
private int $_receiveTokenTimeout = 30;

public function __construct(
string $tokenEndpoint, string $clientId, string $clientSecret = "",
string $username = "", string $password = "")
{
$this->_browser = HttpClientBuilder::buildDefault();
$this->_tokenEndpoint = $tokenEndpoint;
$this->_clientId = $clientId;
$this->_clientSecret = $clientSecret;
$this->_username = $username;
$this->_password = $password;
$this->_grantType = $this->_clientSecret == "" ? "password" : "client_credentials";

$this->_formParams = new Form();
$this->_formParams->addField('client_id', $this->_clientId);
$this->_formParams->addField('grant_type', $this->_grantType);

switch($this->_grantType) {
case "password":
$this->_formParams->addField('username', $this->_username);
$this->_formParams->addField('password', $this->_password);
break;
case "client_credentials":
$this->_formParams->addField('client_secret', $this->_clientSecret);
break;
default:
throw new VaasAuthenticationException("Invalid grant type");
}
}

public function getToken() {
try {
$request = new Request($this->_tokenEndpoint, 'POST');
$request->addHeader('Content-Type', 'application/x-www-form-urlencoded');
$request->setBody($this->_formParams);
$response = $this->_browser->request($request, new TimeoutCancellation($this->_receiveTokenTimeout));
if ($response->getStatus() != 200) {
throw new VaasAuthenticationException($response->getReason(), $response->getStatus());
}
} catch (Exception $e) {
throw new VaasAuthenticationException($e->getMessage(), $e->getCode());
}
$body = $response->getBody()->buffer();
$response_body = json_decode($body);
return $response_body->access_token;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace VaasSdk\Authentication;

use VaasSdk\Authentication\OAuth2TokenReceiver;
use VaasSdk\Exceptions\VaasAuthenticationException;

class ResourceOwnerPasswordGrantAuthenticator {
private OAuth2TokenReceiver $_tokenReceiver;

public function __construct($clientId, $userName, $password, $tokenEndpoint) {
$this->_tokenReceiver = new OAuth2TokenReceiver($tokenEndpoint, $clientId, "", $userName, $password);
}

/**
* @throws VaasAuthenticationException
*/
public function getToken() {
return $this->_tokenReceiver->GetToken();
}
}
53 changes: 0 additions & 53 deletions php/src/vaas/ClientCredentialsGrantAuthenticator.php

This file was deleted.

46 changes: 0 additions & 46 deletions php/src/vaas/ResourceOwnerPasswordGrantAuthenticator.php

This file was deleted.

Loading