Created
April 21, 2019 22:28
-
-
Save guifcoelho/2779791b09502df7a2b5e3c494fef94f to your computer and use it in GitHub Desktop.
Laravel command to download and decrypt service keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
use Defuse\Crypto\File; | |
use Dotenv\Dotenv; | |
class DecryptServiceKeys extends Command{ | |
protected $signature = 'decrypt-service-keys {serviceName} {outputFileName}'; | |
public function __construct(){ | |
parent::__construct(); | |
} | |
public function handle(){ | |
$service = $this->argument('serviceName'); | |
$encryptedFile = app_path("Services/{$service}/Keys/credentials.encrypt"); | |
$downloadUrl = config('services.'.strtolower($service).'.credentials_file_url'); | |
$password = config('services.'.strtolower($service).'.encryption_password'); | |
file_put_contents($encryptedFile, fopen($downloadUrl, 'r')); | |
$outputFile = dirname($encryptedFile)."/{$this->argument('outputFileName')}"; | |
File::decryptFileWithPassword($encryptedFile, $outputFile, $password); | |
return $this->info("File '{$encryptedFile}' decrypted into '{$outputFile}'"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment