public function execute(HarbormasterBuild $build, HarbormasterBuildTarget $build_target)
 {
     $viewer = PhabricatorUser::getOmnipotentUser();
     $settings = $this->getSettings();
     $variables = $build_target->getVariables();
     $uri = $settings['uri'] . '/httpAuth/app/rest/buildQueue';
     $method = 'POST';
     $contentType = 'application/xml';
     $xmlBuilder = new TeamCityXmlBuildBuilder();
     $payload = $xmlBuilder->addBuildId($settings['buildId'])->addBranchName(implode(array("D", $variables['buildable.diff'])))->addDiffId(implode(array("D", $variables['buildable.diff'])))->addHarbormasterPHID($variables['target.phid'])->addRevisionId($variables['buildable.revision'])->build();
     $future = id(new HTTPFuture($uri, $payload))->setMethod($method)->addHeader('Content-Type', $contentType)->setTimeout(60);
     $credential_phid = $this->getSetting('credential');
     if ($credential_phid) {
         $key = PassphrasePasswordKey::loadFromPHID($credential_phid, $viewer);
         $future->setHTTPBasicAuthCredentials($key->getUsernameEnvelope()->openEnvelope(), $key->getPasswordEnvelope());
     }
     $this->resolveFutures($build, $build_target, array($future));
     list($status, $body, $headers) = $future->resolve();
     $header_lines = array();
     // TODO: We don't currently preserve the entire "HTTP" response header, but
     // should. Once we do, reproduce it here faithfully.
     $status_code = $status->getStatusCode();
     $header_lines[] = "HTTP {$status_code}";
     foreach ($headers as $header) {
         list($head, $tail) = $header;
         $header_lines[] = "{$head}: {$tail}";
     }
     $header_lines = implode("\n", $header_lines);
     $build_target->newLog($uri, 'http.head')->append($header_lines);
     $build_target->newLog($uri, 'http.body')->append($body);
     if ($status->isError()) {
         throw new HarbormasterBuildFailureException();
     }
 }
 public function execute(HarbormasterBuild $build, HarbormasterBuildTarget $build_target)
 {
     $viewer = PhabricatorUser::getOmnipotentUser();
     $settings = $this->getSettings();
     $variables = $build_target->getVariables();
     $uri = $this->mergeVariables('vurisprintf', $settings['uri'], $variables);
     $method = nonempty(idx($settings, 'method'), 'POST');
     $future = id(new HTTPSFuture($uri))->setMethod($method)->setTimeout(60);
     $credential_phid = $this->getSetting('credential');
     if ($credential_phid) {
         $key = PassphrasePasswordKey::loadFromPHID($credential_phid, $viewer);
         $future->setHTTPBasicAuthCredentials($key->getUsernameEnvelope()->openEnvelope(), $key->getPasswordEnvelope());
     }
     $this->resolveFutures($build, $build_target, array($future));
     list($status, $body, $headers) = $future->resolve();
     $header_lines = array();
     // TODO: We don't currently preserve the entire "HTTP" response header, but
     // should. Once we do, reproduce it here faithfully.
     $status_code = $status->getStatusCode();
     $header_lines[] = "HTTP {$status_code}";
     foreach ($headers as $header) {
         list($head, $tail) = $header;
         $header_lines[] = "{$head}: {$tail}";
     }
     $header_lines = implode("\n", $header_lines);
     $build_target->newLog($uri, 'http.head')->append($header_lines);
     $build_target->newLog($uri, 'http.body')->append($body);
     if ($status->isError()) {
         throw new HarbormasterBuildFailureException();
     }
 }
 public function execute(HarbormasterBuild $build, HarbormasterBuildTarget $build_target)
 {
     $viewer = PhabricatorUser::getOmnipotentUser();
     $settings = $this->getSettings();
     $variables = $build_target->getVariables();
     $uri = $this->mergeVariables('vurisprintf', $settings['uri'], $variables);
     $method = nonempty(idx($settings, 'method'), 'POST');
     $future = id(new HTTPSFuture($uri))->setMethod($method)->setTimeout(60);
     $credential_phid = $this->getSetting('credential');
     if ($credential_phid) {
         $key = PassphrasePasswordKey::loadFromPHID($credential_phid, $viewer);
         $future->setHTTPBasicAuthCredentials($key->getUsernameEnvelope()->openEnvelope(), $key->getPasswordEnvelope());
     }
     $this->resolveFutures($build, $build_target, array($future));
     $this->logHTTPResponse($build, $build_target, $future, $uri);
     list($status) = $future->resolve();
     if ($status->isError()) {
         throw new HarbormasterBuildFailureException();
     }
 }
 public function execute(HarbormasterBuild $build, HarbormasterBuildTarget $build_target)
 {
     $viewer = PhabricatorUser::getOmnipotentUser();
     $settings = $this->getSettings();
     $variables = $build_target->getVariables();
     $uri = $this->mergeVariables('vurisprintf', $settings['uri'], $variables);
     $log_body = $build->createLog($build_target, $uri, 'http-body');
     $start = $log_body->start();
     $method = nonempty(idx($settings, 'method'), 'POST');
     $future = id(new HTTPSFuture($uri))->setMethod($method)->setTimeout(60);
     $credential_phid = $this->getSetting('credential');
     if ($credential_phid) {
         $key = PassphrasePasswordKey::loadFromPHID($credential_phid, $viewer);
         $future->setHTTPBasicAuthCredentials($key->getUsernameEnvelope()->openEnvelope(), $key->getPasswordEnvelope());
     }
     list($status, $body, $headers) = $this->resolveFuture($build, $build_target, $future);
     $log_body->append($body);
     $log_body->finalize($start);
     if ($status->getStatusCode() != 200) {
         $build->setBuildStatus(HarbormasterBuild::STATUS_FAILED);
     }
 }
コード例 #5
0
 protected function newFormattedCommand($pattern, array $argv)
 {
     $flags = array();
     $args = array();
     $flags[] = '--non-interactive';
     if ($this->isAnyHTTPProtocol() || $this->isSVNProtocol()) {
         $flags[] = '--no-auth-cache';
         if ($this->isAnyHTTPProtocol()) {
             $flags[] = '--trust-server-cert';
         }
         $credential_phid = $this->getCredentialPHID();
         if ($credential_phid) {
             $key = PassphrasePasswordKey::loadFromPHID($credential_phid, PhabricatorUser::getOmnipotentUser());
             $flags[] = '--username %P';
             $args[] = $key->getUsernameEnvelope();
             $flags[] = '--password %P';
             $args[] = $key->getPasswordEnvelope();
         }
     }
     $flags = implode(' ', $flags);
     $pattern = "svn {$flags} {$pattern}";
     return array($pattern, array_merge($args, $argv));
 }
コード例 #6
0
 /**
  * Get the remote URI for this repository, including credentials if they're
  * used by this repository.
  *
  * @return PhutilOpaqueEnvelope URI, possibly including credentials.
  * @task uri
  */
 public function getRemoteURIEnvelope()
 {
     $uri = $this->getRemoteURIObject();
     $remote_protocol = $this->getRemoteProtocol();
     if ($remote_protocol == 'http' || $remote_protocol == 'https') {
         // For SVN, we use `--username` and `--password` flags separately, so
         // don't add any credentials here.
         if (!$this->isSVN()) {
             $credential_phid = $this->getCredentialPHID();
             if ($credential_phid) {
                 $key = PassphrasePasswordKey::loadFromPHID($credential_phid, PhabricatorUser::getOmnipotentUser());
                 $uri->setUser($key->getUsernameEnvelope()->openEnvelope());
                 $uri->setPass($key->getPasswordEnvelope()->openEnvelope());
             }
         }
     }
     return new PhutilOpaqueEnvelope((string) $uri);
 }
コード例 #7
0
 public function getURIEnvelope()
 {
     $uri = $this->getEffectiveURI();
     $command_engine = $this->newCommandEngine();
     $is_http = $command_engine->isAnyHTTPProtocol();
     // For SVN, we use `--username` and `--password` flags separately in the
     // CommandEngine, so we don't need to add any credentials here.
     $is_svn = $this->getRepository()->isSVN();
     $credential_phid = $this->getCredentialPHID();
     if ($is_http && !$is_svn && $credential_phid) {
         $key = PassphrasePasswordKey::loadFromPHID($credential_phid, PhabricatorUser::getOmnipotentUser());
         $uri->setUser($key->getUsernameEnvelope()->openEnvelope());
         $uri->setPass($key->getPasswordEnvelope()->openEnvelope());
     }
     return new PhutilOpaqueEnvelope((string) $uri);
 }
コード例 #8
0
 public static function loadFromPHID($phid, PhabricatorUser $viewer)
 {
     $key = new PassphrasePasswordKey();
     return $key->loadAndValidateFromPHID($phid, $viewer, PassphraseCredentialTypePassword::PROVIDES_TYPE);
 }