Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to whitelist using new 'includes' patterns config. If inc… #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Heyday/Component/Beam/Beam.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ public function hasPath()
{
return is_array($this->options['path']) && count($this->options['path']) > 0;
}
/**
* A helper method for determining if beam is operating with a set of includes
* @return bool
*/
public function hasIncludes()
{
return is_array($this->options['includes']) && count($this->options['includes']) > 0;
}
/**
* Get the server config we are deploying to.
*
Expand Down Expand Up @@ -452,6 +460,14 @@ public function getConfig($config)
);
}
}
/**
* @param $config
* @return boolean
*/
public function hasConfig($config)
{
return array_key_exists($config, $this->config);
}
/**
* Check if the deployment provider implements an interface
* @param $interfaceName
Expand Down
3 changes: 3 additions & 0 deletions src/Heyday/Component/Beam/Command/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$template = array(
'include' => array(
'patterns' => array(),
),
'exclude' => array(
'patterns' => array(),
),
Expand Down
28 changes: 27 additions & 1 deletion src/Heyday/Component/Beam/Config/BeamConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,20 @@ function ($v) use ($self) {
->end()
->end()
->end()
->arrayNode('include')
->children()
->arrayNode('patterns')
->prototype('scalar')->end()
->end()
->end()
->validate()
->always(
function ($v) use ($self) {
return $self->buildIncludes($v);
}
)
->end()
->end()
->arrayNode('exclude')
->children()
->arrayNode('patterns')
Expand Down Expand Up @@ -267,12 +281,24 @@ function ($v) use ($self) {
*/
public function buildExcludes($value)
{
$value = $value ? $value : array(
$value = $value ? $value : array(
'patterns' => array()
);

return array_merge(static::$defaultExcludes, $value['patterns']);
}
/**
* @param $value
* @return array
*/
public function buildIncludes($value)
{
$value = $value ? $value : array(
'patterns' => array()
);

return $value['patterns'];
}
/**
* @param $name
* @param $type
Expand Down
36 changes: 36 additions & 0 deletions src/Heyday/Component/Beam/DeploymentProvider/Rsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public function down(\Closure $output = null, $dryrun = false, DeploymentResult
*/
protected function deploy($command, \Closure $output = null)
{
$this->generateIncludesFile();
$this->generateExcludesFile();
$outputHandler = $this->getOutputStreamHandler($output);
$process = $this->getProcess($command);
Expand Down Expand Up @@ -230,6 +231,13 @@ protected function buildCommand($fromPath, $toPath, $dryrun = false)
$command[] = '--delay-updates';
}

if ($this->beam->hasIncludes()) {
$command[] = array(
'--include-from="%s"',
$this->getIncludesPath()
);
}

$command[] = array(
'--exclude-from="%s"',
$this->getExcludesPath()
Expand Down Expand Up @@ -405,6 +413,30 @@ public function formatOutput($output)

return $changes;
}
/**
* Generate the includes file
*/
protected function generateIncludesFile()
{
if ($this->beam->hasIncludes()) {
$includes = $this->beam->getConfig('include');
file_put_contents(
$this->getIncludesPath(),
implode(PHP_EOL, $includes) . PHP_EOL
);
}
}
/**
* Get the path to the includes file
* @return string
*/
protected function getIncludesPath()
{
return sprintf(
'/tmp/%s.includes',
$this->beam->getLocalPathname()
);
}
/**
* Generate the excludes file
*/
Expand All @@ -420,6 +452,10 @@ protected function generateExcludesFile()
unset($excludes[$idx]);
}
}
// If any includes have been specified we need to exclude everything
if ($this->beam->hasIncludes()) {
$excludes = array_merge(array('/*'), $excludes);
}
file_put_contents(
$this->getExcludesPath(),
implode(PHP_EOL, $excludes) . PHP_EOL
Expand Down