Skip to content

Commit

Permalink
Phpdev async with amphp (#592)
Browse files Browse the repository at this point in the history
* go full async

---------

Co-authored-by: PT-ATA No One <[email protected]>
Co-authored-by: Verdict-as-a-Service Team <[email protected]>
Co-authored-by: doxthree <[email protected]>
  • Loading branch information
4 people authored Oct 14, 2024
1 parent bf1596d commit a339887
Show file tree
Hide file tree
Showing 17 changed files with 2,234 additions and 922 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/ci-php.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- phpdev-*
paths:
- "php/**"
- ".github/workflows/ci-php.yaml"
Expand Down Expand Up @@ -129,8 +130,14 @@ jobs:
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/php}" >> $GITHUB_ENV
echo $RELEASE_VERSION
- name: extract version
if: startsWith(github.ref, 'refs/heads/phpdev-')
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/phpdev-}" >> $GITHUB_ENV
echo $RELEASE_VERSION
- name: checkout
if: startsWith(github.ref, 'refs/tags/php')
if: startsWith(github.ref, 'refs/tags/php') || startsWith(github.ref, 'refs/heads/phpdev-')
uses: actions/checkout@v4

- name: publish on site repo
Expand All @@ -151,8 +158,25 @@ jobs:
git remote add origin https://ata-no-one:[email protected]/GDATASoftwareAG/vaas-php
git push origin main --tags --force
- name: publish on site repo
if: startsWith(github.ref, 'refs/heads/phpdev-')
env:
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
working-directory: php/src/vaas
run: |
git config --global user.email "[email protected]"
git config --global user.name "Version Bot"
sed -i "s/\"version\": \"[0-9]\+\.[0-9]\+\.[0-9]\+\"/\"version\": \"$RELEASE_VERSION\"/g" ./composer.json
cp ../../../Readme.md .
git init
git add .
git commit -m"publish php $RELEASE_VERSION"
git branch -M $RELEASE_VERSION
git remote add origin https://ata-no-one:[email protected]/GDATASoftwareAG/vaas-php
git push origin $RELEASE_VERSION --force
- name: sync packagist
if: startsWith(github.ref, 'refs/tags/php')
if: startsWith(github.ref, 'refs/tags/php') || startsWith(github.ref, 'refs/heads/phpdev-')
env:
PACKAGIST_API_TOKEN: ${{ secrets.PACKAGIST_API_TOKEN }}
run: curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=gdatacyberdefense&apiToken=$PACKAGIST_API_TOKEN" -d'{"repository":{"url":"https://packagist.org/packages/gdata/vaas"}}'
Expand Down
5 changes: 5 additions & 0 deletions php/composer-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
find . -name composer.json -not -path */vendor/* | while read composer; do
dir=$(dirname $composer)
echo "Updating $dir"
composer --working-dir=$dir update
done
8 changes: 4 additions & 4 deletions php/examples/VaasExample/GetVerdictByFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
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"
);
$vaas = (new Vaas())
->withAuthenticator($authenticator)
->withUrl(getenv("VAAS_URL") ?? "wss://gateway.production.vaas.gdatasecurity.de")
->build();

$vaas->Connect($authenticator->getToken());
$scanPath = getenv("SCAN_PATH");
$vaasVerdict = $vaas->ForFile($scanPath);

Expand Down
8 changes: 4 additions & 4 deletions php/examples/VaasExample/GetVerdictByHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
getenv("CLIENT_SECRET"),
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"
);
$vaas->Connect($authenticator->getToken());
$vaas = (new Vaas())
->withAuthenticator($authenticator)
->withUrl(getenv("VAAS_URL") ?? "wss://gateway.production.vaas.gdatasecurity.de")
->build();

// EICAR
$vaasVerdict = $vaas->ForSha256("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8");
Expand Down
8 changes: 4 additions & 4 deletions php/examples/VaasExample/GetVerdictByUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
getenv("CLIENT_SECRET"),
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"
);
$vaas->Connect($authenticator->getToken());
$vaas = (new Vaas())
->withAuthenticator($authenticator)
->withUrl(getenv("VAAS_URL") ?? "wss://gateway.production.vaas.gdatasecurity.de")
->build();

// EICAR
$vaasVerdict = $vaas->ForUrl("https://secure.eicar.org/eicar.com");
Expand Down
20 changes: 19 additions & 1 deletion php/examples/wordpress/src/gd-scan/Vaas/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@

namespace WpGdScan\Vaas;

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

class Client
{
private Vaas $vaas;

public function __construct()
{
$authenticator = new ClientCredentialsGrantAuthenticator(
getenv("CLIENT_ID"),
getenv("CLIENT_SECRET"),
getenv("TOKEN_URL") ?: "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
);
$this->vaas = (new Vaas())
->withAuthenticator($authenticator)
->build();
}

public function scanSingleFile(string $fileName): void
{
file_put_contents(\plugin_dir_path(__FILE__) . "/log", "Filename: $fileName\n", FILE_APPEND);

file_put_contents(\plugin_dir_path(__FILE__) . "/log", "Try to get Verdict: $fileName\n", FILE_APPEND);
if ((new \VaasSdk\Vaas("Token"))->ForFile($fileName) == \VaasSdk\Message\Verdict::MALICIOUS) {

if ($this->vaas->ForFile($fileName) == \VaasSdk\Message\Verdict::MALICIOUS) {
file_put_contents(
\plugin_dir_path(__FILE__) . "/log",
\VaasSdk\Message\Verdict::MALICIOUS . ": $fileName\n",
Expand Down
Loading

0 comments on commit a339887

Please sign in to comment.