Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/storage/PhabricatorRepositoryURI.php
| Show First 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | if ($this->isBuiltin()) { | ||||
| } else { | } else { | ||||
| return self::IO_READWRITE; | return self::IO_READWRITE; | ||||
| } | } | ||||
| } | } | ||||
| return self::IO_NONE; | return self::IO_NONE; | ||||
| } | } | ||||
| public function getDisplayURI() { | |||||
| return $this->getURIObject(false); | |||||
| } | |||||
| public function getNormalizedURI() { | public function getNormalizedURI() { | ||||
| $vcs = $this->getRepository()->getVersionControlSystem(); | $vcs = $this->getRepository()->getVersionControlSystem(); | ||||
| $map = array( | $map = array( | ||||
| PhabricatorRepositoryType::REPOSITORY_TYPE_GIT => | PhabricatorRepositoryType::REPOSITORY_TYPE_GIT => | ||||
| PhabricatorRepositoryURINormalizer::TYPE_GIT, | PhabricatorRepositoryURINormalizer::TYPE_GIT, | ||||
| PhabricatorRepositoryType::REPOSITORY_TYPE_SVN => | PhabricatorRepositoryType::REPOSITORY_TYPE_SVN => | ||||
| PhabricatorRepositoryURINormalizer::TYPE_SVN, | PhabricatorRepositoryURINormalizer::TYPE_SVN, | ||||
| PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL => | PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL => | ||||
| PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL, | PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL, | ||||
| ); | ); | ||||
| $type = $map[$vcs]; | $type = $map[$vcs]; | ||||
| $display = (string)$this->getDisplayURI(); | $display = (string)$this->getDisplayURI(); | ||||
| $normal_uri = new PhabricatorRepositoryURINormalizer($type, $display); | $normal_uri = new PhabricatorRepositoryURINormalizer($type, $display); | ||||
| return $normal_uri->getNormalizedURI(); | return $normal_uri->getNormalizedURI(); | ||||
| } | } | ||||
| public function getDisplayURI() { | |||||
| return $this->getURIObject(); | |||||
| } | |||||
| public function getEffectiveURI() { | public function getEffectiveURI() { | ||||
| return $this->getURIObject(true); | return $this->getURIObject(); | ||||
| } | } | ||||
| public function getURIEnvelope() { | public function getURIEnvelope() { | ||||
| $uri = $this->getEffectiveURI(); | $uri = $this->getEffectiveURI(); | ||||
| $command_engine = $this->newCommandEngine(); | $command_engine = $this->newCommandEngine(); | ||||
| $is_http = $command_engine->isAnyHTTPProtocol(); | $is_http = $command_engine->isAnyHTTPProtocol(); | ||||
| Show All 9 Lines | if ($is_http && !$is_svn && $credential_phid) { | ||||
| $uri->setUser($key->getUsernameEnvelope()->openEnvelope()); | $uri->setUser($key->getUsernameEnvelope()->openEnvelope()); | ||||
| $uri->setPass($key->getPasswordEnvelope()->openEnvelope()); | $uri->setPass($key->getPasswordEnvelope()->openEnvelope()); | ||||
| } | } | ||||
| return new PhutilOpaqueEnvelope((string)$uri); | return new PhutilOpaqueEnvelope((string)$uri); | ||||
| } | } | ||||
| private function getURIObject($normalize) { | private function getURIObject() { | ||||
| // Users can provide Git/SCP-style URIs in the form "user@host:path". | // Users can provide Git/SCP-style URIs in the form "user@host:path". | ||||
| // These are equivalent to "ssh://user@host/path". We use the more standard | // In the general case, these are not equivalent to any "ssh://..." form | ||||
| // form internally, and convert to it if we need to specify a port number, | // because the path is relative. | ||||
| // but try to preserve what the user typed when displaying the URI. | |||||
| if ($this->isBuiltin()) { | if ($this->isBuiltin()) { | ||||
| $builtin_protocol = $this->getForcedProtocol(); | $builtin_protocol = $this->getForcedProtocol(); | ||||
| $builtin_domain = $this->getForcedHost(); | $builtin_domain = $this->getForcedHost(); | ||||
| $raw_uri = "{$builtin_protocol}://{$builtin_domain}"; | $raw_uri = "{$builtin_protocol}://{$builtin_domain}"; | ||||
| } else { | } else { | ||||
| $raw_uri = $this->getURI(); | $raw_uri = $this->getURI(); | ||||
| } | } | ||||
| $port = $this->getForcedPort(); | $port = $this->getForcedPort(); | ||||
| $default_ports = array( | $default_ports = array( | ||||
| 'ssh' => 22, | 'ssh' => 22, | ||||
| 'http' => 80, | 'http' => 80, | ||||
| 'https' => 443, | 'https' => 443, | ||||
| ); | ); | ||||
| $uri = new PhutilURI($raw_uri); | $uri = new PhutilURI($raw_uri); | ||||
| // Make sure to remove any password from the URI before we do anything | // Make sure to remove any password from the URI before we do anything | ||||
| // with it; this should always be provided by the associated credential. | // with it; this should always be provided by the associated credential. | ||||
| $uri->setPass(null); | $uri->setPass(null); | ||||
| if (!$uri->getProtocol()) { | |||||
| $git_uri = new PhutilGitURI($raw_uri); | |||||
| // We must normalize this Git-style URI into a normal URI | |||||
| $must_normalize = ($port && ($port != $default_ports['ssh'])); | |||||
| if ($must_normalize || $normalize) { | |||||
| $domain = $git_uri->getDomain(); | |||||
| $uri = id(new PhutilURI("ssh://{$domain}")) | |||||
| ->setUser($git_uri->getUser()) | |||||
| ->setPath($git_uri->getPath()); | |||||
| } else { | |||||
| $uri = $git_uri; | |||||
| } | |||||
| } | |||||
| $is_normal = ($uri instanceof PhutilURI); | |||||
| if ($is_normal) { | |||||
| $protocol = $this->getForcedProtocol(); | $protocol = $this->getForcedProtocol(); | ||||
| if ($protocol) { | if ($protocol) { | ||||
| $uri->setProtocol($protocol); | $uri->setProtocol($protocol); | ||||
| } | } | ||||
| if ($port) { | if ($port) { | ||||
| $uri->setPort($port); | $uri->setPort($port); | ||||
| } | } | ||||
| // Remove any explicitly set default ports. | // Remove any explicitly set default ports. | ||||
| $uri_port = $uri->getPort(); | $uri_port = $uri->getPort(); | ||||
| $uri_protocol = $uri->getProtocol(); | $uri_protocol = $uri->getProtocol(); | ||||
| $uri_default = idx($default_ports, $uri_protocol); | $uri_default = idx($default_ports, $uri_protocol); | ||||
| if ($uri_default && ($uri_default == $uri_port)) { | if ($uri_default && ($uri_default == $uri_port)) { | ||||
| $uri->setPort(null); | $uri->setPort(null); | ||||
| } | } | ||||
| } | |||||
| $user = $this->getForcedUser(); | $user = $this->getForcedUser(); | ||||
| if ($user) { | if ($user) { | ||||
| $uri->setUser($user); | $uri->setUser($user); | ||||
| } | } | ||||
| $host = $this->getForcedHost(); | $host = $this->getForcedHost(); | ||||
| if ($host) { | if ($host) { | ||||
| ▲ Show 20 Lines • Show All 456 Lines • Show Last 20 Lines | |||||