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

Hide environment keys / Add EnvironmentHasExceededLimit solution #222

Merged
Merged
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
4 changes: 1 addition & 3 deletions src/Commands/Output/DeploymentFailure.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class DeploymentFailure
/**
* Render the output.
*
* @param \Laravel\VaporCli\Models\Deployment $deployment
* @return void
*/
public function render(Deployment $deployment)
Expand All @@ -22,8 +21,7 @@ public function render(Deployment $deployment)

if ($deployment->status_message) {
Helpers::line('');
$message = $deployment->status_message;
Helpers::line(" $message");
Helpers::line($deployment->formattedStatusMessage());
}

$deployment->solutions()->whenNotEmpty(function ($solutions) {
Expand Down
50 changes: 35 additions & 15 deletions src/Models/Deployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ class Deployment
*/
public $deployment;

/**
* Error messsages containing sensitive information.
*
* @var array
*/
protected $senstiveStatusMessages = [
'AWS: Lambda was unable to configure your environment variables because the environment variables you have provided exceeded the 4KB limit',
];

/**
* Create a new model instance.
*
* @param array $deployment
* @return void
*/
public function __construct(array $deployment)
Expand All @@ -28,26 +36,24 @@ public function __construct(array $deployment)
/**
* Get the names of the displayable steps.
*
* @param array $displayedSteps
* @return array
*/
public function displayableSteps(array $displayedSteps = [])
{
return collect($this->steps)
->filter(function ($step) {
return $step['status'] !== 'pending' &&
$step['status'] !== 'cancelled';
})->map(function ($step) {
return $this->formatDeploymentStepName($step['name']);
})->filter(function ($step) use ($displayedSteps) {
return ! in_array($step, $displayedSteps);
})->all();
->filter(function ($step) {
return $step['status'] !== 'pending' &&
$step['status'] !== 'cancelled';
})->map(function ($step) {
return $this->formatDeploymentStepName($step['name']);
})->filter(function ($step) use ($displayedSteps) {
return ! in_array($step, $displayedSteps);
})->all();
}

/**
* Determine if the given deployment step should be displayed.
*
* @param array $step
* @return bool
*/
protected function stepShouldBeDisplayed(array $step)
Expand Down Expand Up @@ -147,13 +153,27 @@ public function solutions()
Solutions\FunctionExceedsMaximumAllowedSize::class,
Solutions\ResourceUpdateInProgress::class,
Solutions\RunDeploymentHooksTimedOut::class,
Solutions\EnvironmentVariableLimitReached::class,
])->map(function ($solutionsClass) {
return new $solutionsClass($this);
})->filter
->applicable()
->map
->all()
->flatten();
->applicable()
->map
->all()
->flatten();
}

/**
* Format the deployment status message removing any sensitive information.
*
* @return string
*/
public function formattedStatusMessage()
{
return collect($this->senstiveStatusMessages)
->first(function ($message) {
return Str::contains($this->status_message, $message);
}) ?: $this->status_message;
}

/**
Expand Down
51 changes: 51 additions & 0 deletions src/Solutions/EnvironmentVariableLimitReached.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Laravel\VaporCli\Solutions;

use Illuminate\Support\Str;
use Laravel\VaporCli\Deployment;

class EnvironmentVariableLimitReached
{
/**
* The deployment that have failed.
*
* @var \Laravel\VaporCli\Deployment
*/
protected $deployment;

/**
* Create a new solution instance.
*
* @param \Laravel\VaporCli\Deployment $deployment
* @return void
*/
public function __construct($deployment)
{
$this->deployment = $deployment;
}

/**
* Checks if the solution is applicable.
*
* @return bool
*/
public function applicable()
{
return Str::contains($this->deployment->status_message, [
'Lambda was unable to configure your environment variables because the environment variables you have provided exceeded the 4KB limit',
]);
}

/**
* Returns the list of solutions based on the deployment.
*
* @return array
*/
public function all()
{
return [
'Use encrypted environment files in place of or in addition to environment variables: https://docs.vapor.build/1.0/projects/environments.html#encrypted-environment-files',
];
}
}
12 changes: 12 additions & 0 deletions tests/SolutionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@ public function test_run_deployment_hooks_timed_out()
$this->assertCount(2, $deployment->solutions());
$this->assertStringContainsString('https://vapor.laravel.com/app/projects/1/environments/foo/logs', $deployment->solutions()[1]);
}

public function test_environment_has_exceeded_limit()
{
$deployment = new Deployment([
'project_id' => 1,
'environment' => ['name' => 'foo'],
'status_message' => 'Lambda was unable to configure your environment variables because the environment variables you have provided exceeded the 4KB limit',
]);

$this->assertCount(1, $deployment->solutions());
$this->assertStringContainsString('Use encrypted environment files in place of or in addition to environment variables', $deployment->solutions()[0]);
}
}