2 Commits
1.0.3 ... 1.0.5

Author SHA1 Message Date
ea64578fd9 PushEvent - Updated the validateRequest() method
+ Added ability to skip secret key validation, which is useful for newer version of gitea (as its depreciated now)
2021-11-04 20:52:06 -06:00
dbdff87baf Hotfix - Renamed occurences of old method name
+ Replaced instances of `getRawFile()` with `getFileContents()`
2021-11-02 14:47:41 -06:00
3 changed files with 20 additions and 17 deletions

View File

@ -149,7 +149,7 @@ class Repositories extends AbstractAllApiRequester
*
* Example:
* ```
* $client->repositories()->getRawFile($owner, $repoName, "README.md", "v2.0.0");
* $client->repositories()->getFileContents($owner, $repoName, "README.md", "v2.0.0");
* ```
*
* @param string $owner The owner of the repository

View File

@ -59,9 +59,10 @@ class PushEvent extends AbstractApiModel {
* @param array $server The HTTP SERVER array for the push event
* @param string $body The raw data from the request body
* @param string $secretKey The secret key to from your server
* @return void
* @param bool $skipSecretValidation If set to true, secret key validation will be skipped (used for newer versions of Gitea)
* @return bool
*/
public static function validateRequest(array $server, string $body, string $secretKey)
public static function validateRequest(array $server, string $body, string $secretKey, bool $skipSecretValidation = false)
{
// Validate request protocol
if ($server['REQUEST_METHOD'] != 'POST') {
@ -80,6 +81,7 @@ class PushEvent extends AbstractApiModel {
throw new \RuntimeException("FAILED: Empty Body - The request has an empty body");
}
if (!$skipSecretValidation) {
// Validate header signature
$headerSignature = isset($server['HTTP_X_GITEA_SIGNATURE']) ? $server['HTTP_X_GITEA_SIGNATURE'] : '';
if (empty($headerSignature)) {
@ -93,6 +95,7 @@ class PushEvent extends AbstractApiModel {
if ($headerSignature != $payload_signature) {
throw new \RuntimeException("FAILED: Access Denied - The push event's secret does not match the expected secret");
}
}
return true;
}

View File

@ -82,7 +82,7 @@ if ($repository) {
}
// print("Getting contents of \"composer.json\" file \n\n");
// $rawFile = $giteaClient->repositories()->getRawFile("Sitelease", "sl-theme-recipe", "composer.json");
// $rawFile = $giteaClient->repositories()->getFileContents("Sitelease", "sl-theme-recipe", "composer.json");
// if ($rawFile) {
// var_dump(json_encode($rawFile));
// print("\n\n");
@ -91,7 +91,7 @@ if ($repository) {
// }
// print("Getting contents of \"composer.json\" file \n\n");
// $rawFile = $giteaClient->repositories()->getRawFile("Sitelease", "sl-theme-recipe", "composer.json");
// $rawFile = $giteaClient->repositories()->getFileContents("Sitelease", "sl-theme-recipe", "composer.json");
// if ($rawFile) {
// var_dump($rawFile);
// print("\n\n");