mirror of
				https://github.com/sitelease/sugar-cube-client.git
				synced 2025-10-31 12:02:30 +01:00 
			
		
		
		
	Compare commits
	
		
			4 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 5deac6cf55 | |||
| 714d079287 | |||
| ea64578fd9 | |||
| dbdff87baf | 
| @ -25,7 +25,7 @@ | |||||||
|     "php": ">=7.2.0", |     "php": ">=7.2.0", | ||||||
|     "ext-curl": "*", |     "ext-curl": "*", | ||||||
|     "ext-json": "*", |     "ext-json": "*", | ||||||
|     "cedx/enum": "^7.4.0", |     "myclabs/php-enum": "^1.8", | ||||||
|     "guzzlehttp/guzzle": "~6.0" |     "guzzlehttp/guzzle": "~6.0" | ||||||
|   }, |   }, | ||||||
|   "require-dev": { |   "require-dev": { | ||||||
|  | |||||||
| @ -149,7 +149,7 @@ class Repositories extends AbstractAllApiRequester | |||||||
|      * |      * | ||||||
|      * Example: |      * 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 |      * @param string $owner The owner of the repository | ||||||
|  | |||||||
| @ -203,7 +203,7 @@ class Owner extends AbstractApiModel { | |||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public function getIsAdmin(): boolean { |     public function getIsAdmin(): bool { | ||||||
|         return $this->isAdmin; |         return $this->isAdmin; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
| @ -1,11 +1,13 @@ | |||||||
| <?php declare(strict_types=1); | <?php | ||||||
|  |  | ||||||
|  | declare(strict_types=1); | ||||||
|  |  | ||||||
| namespace Gitea\Model; | namespace Gitea\Model; | ||||||
|  |  | ||||||
| use Enum\{EnumTrait}; | use MyCLabs\Enum\Enum; | ||||||
|  |  | ||||||
| /** Defines the state of a Gitea status. */ | /** Defines the state of a Gitea status. */ | ||||||
| final class StatusState { | final class StatusState extends Enum { | ||||||
|     use EnumTrait; |  | ||||||
|  |  | ||||||
|     /** @var string The status is an error. */ |     /** @var string The status is an error. */ | ||||||
|     const error = 'error'; |     const error = 'error'; | ||||||
|  | |||||||
| @ -1,11 +1,10 @@ | |||||||
| <?php declare(strict_types=1); | <?php declare(strict_types=1); | ||||||
| namespace Gitea\Model; | namespace Gitea\Model; | ||||||
|  |  | ||||||
| use Enum\{EnumTrait}; | use MyCLabs\Enum\Enum; | ||||||
|  |  | ||||||
| /** Defines the permission of a team. */ | /** Defines the permission of a team. */ | ||||||
| final class TeamPermission { | final class TeamPermission extends Enum { | ||||||
|     use EnumTrait; |  | ||||||
|  |  | ||||||
|     /** @var string The team has the administrator permission. */ |     /** @var string The team has the administrator permission. */ | ||||||
|     const admin = 'admin'; |     const admin = 'admin'; | ||||||
|  | |||||||
| @ -59,9 +59,10 @@ class PushEvent extends AbstractApiModel { | |||||||
|      * @param array $server The HTTP SERVER array for the push event |      * @param array $server The HTTP SERVER array for the push event | ||||||
|      * @param string $body The raw data from the request body |      * @param string $body The raw data from the request body | ||||||
|      * @param string $secretKey The secret key to from your server |      * @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 |         // Validate request protocol | ||||||
|         if ($server['REQUEST_METHOD'] != 'POST') { |         if ($server['REQUEST_METHOD'] != 'POST') { | ||||||
| @ -80,18 +81,20 @@ class PushEvent extends AbstractApiModel { | |||||||
|             throw new \RuntimeException("FAILED: Empty Body - The request has an empty body"); |             throw new \RuntimeException("FAILED: Empty Body - The request has an empty body"); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // Validate header signature |         if (!$skipSecretValidation) { | ||||||
|         $headerSignature = isset($server['HTTP_X_GITEA_SIGNATURE']) ? $server['HTTP_X_GITEA_SIGNATURE'] : ''; |             // Validate header signature | ||||||
|         if (empty($headerSignature)) { |             $headerSignature = isset($server['HTTP_X_GITEA_SIGNATURE']) ? $server['HTTP_X_GITEA_SIGNATURE'] : ''; | ||||||
|             throw new \RuntimeException("FAILED: Signature Missing - The request is missing the Gitea signature"); |             if (empty($headerSignature)) { | ||||||
|         } |                 throw new \RuntimeException("FAILED: Signature Missing - The request is missing the Gitea signature"); | ||||||
|  |             } | ||||||
|         // calculate payload signature |      | ||||||
|         $payload_signature = hash_hmac('sha256', $rawContent, $secretKey, false); |             // calculate payload signature | ||||||
|  |             $payload_signature = hash_hmac('sha256', $rawContent, $secretKey, false); | ||||||
|         // check payload signature against header signature |      | ||||||
|         if ($headerSignature != $payload_signature) { |             // check payload signature against header signature | ||||||
|             throw new \RuntimeException("FAILED: Access Denied - The push event's secret does not match the expected secret"); |             if ($headerSignature != $payload_signature) { | ||||||
|  |                 throw new \RuntimeException("FAILED: Access Denied - The push event's secret does not match the expected secret"); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return true; |         return true; | ||||||
|  | |||||||
| @ -82,7 +82,7 @@ if ($repository) { | |||||||
| } | } | ||||||
|  |  | ||||||
| // print("Getting contents of \"composer.json\" file \n\n"); | // 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) { | // if ($rawFile) { | ||||||
| //     var_dump(json_encode($rawFile)); | //     var_dump(json_encode($rawFile)); | ||||||
| //     print("\n\n"); | //     print("\n\n"); | ||||||
| @ -91,7 +91,7 @@ if ($repository) { | |||||||
| // } | // } | ||||||
|  |  | ||||||
| // print("Getting contents of \"composer.json\" file \n\n"); | // 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) { | // if ($rawFile) { | ||||||
| //     var_dump($rawFile); | //     var_dump($rawFile); | ||||||
| //     print("\n\n"); | //     print("\n\n"); | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	