1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

Make "phabricator.silent" disable build steps which rely on external services

Summary:
Depends on D19084. Fixes T13078. When `phabricator.silent` is enabled, immediately fail the "HTTP Request", "CircleCI" and "Buildkite" build steps.

This doesn't feel quite as clean as most of the other behavior of `phabricator.silent`, since these calls are not exactly notifications in the same way that email is, and failing to make these calls means that builds run differently (whereas failing to deliver email doesn't really do anything).

However, I suspect that this behavior is almost always reasonable/correct, and that we can probably get away with it until this grey area between "notifications" and "external service calls" is more clearly defined.

Test Plan:
  - Created a build with HTTP, CircleCI, and Buildkite steps.
  - Put install in `phabricator.silent` mode: all three steps failed with "declining, because silent" messages.
  - Put install back in normal mode: all three steps made HTTP requests.
  - Read updated documentation.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13078

Differential Revision: https://secure.phabricator.com/D19085
This commit is contained in:
epriestley 2018-02-14 11:30:25 -08:00
parent a2453706ab
commit f74e6bbf8d
5 changed files with 47 additions and 15 deletions

View file

@ -37,6 +37,24 @@ final class PhabricatorCoreConfigOptions
$proto_doc_name = pht('User Guide: Prototype Applications');
$applications_app_href = '/applications/';
$silent_description = $this->deformat(pht(<<<EOREMARKUP
This option allows you to stop Phabricator from sending data to most external
services: it will disable email, SMS, repository mirroring, remote builds,
Doorkeeper writes, and webhooks.
This option is intended to allow a Phabricator instance to be exported, copied,
imported, and run in a test environment without impacting users. For example,
if you are migrating to new hardware, you could perform a test migration first
with this flag set, make sure things work, and then do a production cutover
later with higher confidence and less disruption.
Without making use of this flag to silence the temporary test environment,
users would receive duplicate email during the time the test instance and old
production instance were both in operation.
EOREMARKUP
));
return array(
$this->newOption('phabricator.base-uri', 'string', null)
->setLocked(true)
@ -232,21 +250,7 @@ final class PhabricatorCoreConfigOptions
pht('Run Normally'),
))
->setSummary(pht('Stop Phabricator from sending any email, etc.'))
->setDescription(
pht(
'This option allows you to stop Phabricator from sending '.
'any data to external services. Among other things, it will '.
'disable email, SMS, repository mirroring, and HTTP hooks.'.
"\n\n".
'This option is intended to allow a Phabricator instance to '.
'be exported, copied, imported, and run in a test environment '.
'without impacting users. For example, if you are migrating '.
'to new hardware, you could perform a test migration first, '.
'make sure things work, and then do a production cutover '.
'later with higher confidence and less disruption. Without '.
'this flag, users would receive duplicate email during the '.
'time the test instance and old production instance were '.
'both in operation.')),
->setDescription($silent_description),
);
}

View file

@ -295,6 +295,18 @@ abstract class HarbormasterBuildStepImplementation extends Phobject {
->append($body);
}
protected function logSilencedCall(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target,
$label) {
$build_target
->newLog($label, 'silenced')
->append(
pht(
'Declining to make service call because `phabricator.silent` is '.
'enabled in configuration.'));
}
/* -( Automatic Targets )-------------------------------------------------- */

View file

@ -72,6 +72,11 @@ EOTEXT
HarbormasterBuildTarget $build_target) {
$viewer = PhabricatorUser::getOmnipotentUser();
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) {
$this->logSilencedCall($build, $build_target, pht('Buildkite'));
throw new HarbormasterBuildFailureException();
}
$buildable = $build->getBuildable();
$object = $buildable->getBuildableObject();

View file

@ -84,6 +84,11 @@ EOTEXT
HarbormasterBuildTarget $build_target) {
$viewer = PhabricatorUser::getOmnipotentUser();
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) {
$this->logSilencedCall($build, $build_target, pht('CircleCI'));
throw new HarbormasterBuildFailureException();
}
$buildable = $build->getBuildable();
$object = $buildable->getBuildableObject();

View file

@ -43,6 +43,12 @@ final class HarbormasterHTTPRequestBuildStepImplementation
HarbormasterBuildTarget $build_target) {
$viewer = PhabricatorUser::getOmnipotentUser();
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) {
$this->logSilencedCall($build, $build_target, pht('HTTP Request'));
throw new HarbormasterBuildFailureException();
}
$settings = $this->getSettings();
$variables = $build_target->getVariables();