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

Phpdev async with amphp #592

Merged
merged 22 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
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
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