Differential D15489 Diff 37338 src/applications/diffusion/gitlfs/DiffusionGitLFSAuthenticateWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/gitlfs/DiffusionGitLFSAuthenticateWorkflow.php
| Show First 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | protected function executeRepositoryOperations() { | ||||
| $lfs_uri = $repository->getGitLFSURI('info/lfs'); | $lfs_uri = $repository->getGitLFSURI('info/lfs'); | ||||
| // Generate a temporary token to allow the user to acces LFS over HTTP. | // Generate a temporary token to allow the user to acces LFS over HTTP. | ||||
| // This works even if normal HTTP repository operations are not available | // This works even if normal HTTP repository operations are not available | ||||
| // on this host, and does not require the user to have a VCS password. | // on this host, and does not require the user to have a VCS password. | ||||
| $user = $this->getUser(); | $user = $this->getUser(); | ||||
| $headers = array(); | |||||
| $lfs_user = DiffusionGitLFSTemporaryTokenType::HTTP_USERNAME; | $authorization = DiffusionGitLFSTemporaryTokenType::newHTTPAuthorization( | ||||
| $lfs_pass = Filesystem::readRandomCharacters(32); | $repository, | ||||
| $lfs_hash = PhabricatorHash::digest($lfs_pass); | $user, | ||||
| $operation); | |||||
| $ttl = PhabricatorTime::getNow() + phutil_units('1 day in seconds'); | |||||
| $token = id(new PhabricatorAuthTemporaryToken()) | |||||
| ->setTokenResource($repository->getPHID()) | |||||
| ->setTokenType(DiffusionGitLFSTemporaryTokenType::TOKENTYPE) | |||||
| ->setTokenCode($lfs_hash) | |||||
| ->setUserPHID($user->getPHID()) | |||||
| ->setTemporaryTokenProperty('lfs.operation', $operation) | |||||
| ->setTokenExpires($ttl) | |||||
| ->save(); | |||||
| $authorization_header = base64_encode($lfs_user.':'.$lfs_pass); | $headers = array( | ||||
| $headers['Authorization'] = 'Basic '.$authorization_header; | 'authorization' => $authorization, | ||||
| ); | |||||
| $result = array( | $result = array( | ||||
| 'header' => $headers, | 'header' => $headers, | ||||
| 'href' => $lfs_uri, | 'href' => $lfs_uri, | ||||
| ); | ); | ||||
| $result = phutil_json_encode($result); | $result = phutil_json_encode($result); | ||||
| $this->writeIO($result); | $this->writeIO($result); | ||||
| $this->waitForGitClient(); | $this->waitForGitClient(); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||