Path: blob/master/src/applications/diffusion/gitlfs/DiffusionGitLFSAuthenticateWorkflow.php
12242 views
<?php12final class DiffusionGitLFSAuthenticateWorkflow3extends DiffusionGitSSHWorkflow {45protected function didConstruct() {6$this->setName('git-lfs-authenticate');7$this->setArguments(8array(9array(10'name' => 'argv',11'wildcard' => true,12),13));14}1516protected function identifyRepository() {17return $this->loadRepositoryWithPath(18$this->getLFSPathArgument(),19PhabricatorRepositoryType::REPOSITORY_TYPE_GIT);20}2122private function getLFSPathArgument() {23return $this->getLFSArgument(0);24}2526private function getLFSOperationArgument() {27return $this->getLFSArgument(1);28}2930private function getLFSArgument($position) {31$args = $this->getArgs();32$argv = $args->getArg('argv');3334if (!isset($argv[$position])) {35throw new Exception(36pht(37'Expected `git-lfs-authenticate <path> <operation>`, but received '.38'too few arguments.'));39}4041return $argv[$position];42}4344protected function executeRepositoryOperations() {45$operation = $this->getLFSOperationArgument();4647// NOTE: We aren't checking write access here, even for "upload". The48// HTTP endpoint should be able to do that for us.4950switch ($operation) {51case 'upload':52case 'download':53break;54default:55throw new Exception(56pht(57'Git LFS operation "%s" is not supported by this server.',58$operation));59}6061$repository = $this->getRepository();6263if (!$repository->isGit()) {64throw new Exception(65pht(66'Repository "%s" is not a Git repository. Git LFS is only '.67'supported for Git repositories.',68$repository->getDisplayName()));69}7071if (!$repository->canUseGitLFS()) {72throw new Exception(73pht('Git LFS is not enabled for this repository.'));74}7576// NOTE: This is usually the same as the default URI (which does not77// need to be specified in the response), but the protocol or domain may78// differ in some situations.7980$lfs_uri = $repository->getGitLFSURI('info/lfs');8182// Generate a temporary token to allow the user to access LFS over HTTP.83// This works even if normal HTTP repository operations are not available84// on this host, and does not require the user to have a VCS password.8586$user = $this->getSSHUser();8788$authorization = DiffusionGitLFSTemporaryTokenType::newHTTPAuthorization(89$repository,90$user,91$operation);9293$headers = array(94'authorization' => $authorization,95);9697$result = array(98'header' => $headers,99'href' => $lfs_uri,100);101$result = phutil_json_encode($result);102103$this->writeIO($result);104$this->waitForGitClient();105106return 0;107}108109}110111112