24Slides /
laravel-saml2
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Slides\Saml2\Commands; |
||||
| 4 | |||||
| 5 | use Slides\Saml2\Helpers\ConsoleHelper; |
||||
| 6 | use Slides\Saml2\Repositories\TenantRepository; |
||||
| 7 | |||||
| 8 | /** |
||||
| 9 | * Class UpdateTenant |
||||
| 10 | * |
||||
| 11 | * @package Slides\Saml2\Commands |
||||
| 12 | */ |
||||
| 13 | class UpdateTenant extends \Illuminate\Console\Command |
||||
| 14 | { |
||||
| 15 | use RendersTenants, ValidatesInput; |
||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||
| 16 | |||||
| 17 | /** |
||||
| 18 | * The name and signature of the console command. |
||||
| 19 | * |
||||
| 20 | * @var string |
||||
| 21 | */ |
||||
| 22 | protected $signature = 'saml2:update-tenant {id} |
||||
| 23 | { --k|key= : A tenant custom key } |
||||
| 24 | { --entityId= : IdP Issuer URL } |
||||
| 25 | { --loginUrl= : IdP Sign on URL } |
||||
| 26 | { --logoutUrl= : IdP Logout URL } |
||||
| 27 | { --relayStateUrl= : Redirection URL after successful login } |
||||
| 28 | { --nameIdFormat= : Name ID Format ("persistent" by default) } |
||||
| 29 | { --x509cert= : x509 certificate (base64) } |
||||
| 30 | { --metadata= : A custom metadata }'; |
||||
| 31 | |||||
| 32 | /** |
||||
| 33 | * The console command description. |
||||
| 34 | * |
||||
| 35 | * @var string |
||||
| 36 | */ |
||||
| 37 | protected $description = 'Update a Tenant entity (relying identity provider)'; |
||||
| 38 | |||||
| 39 | /** |
||||
| 40 | * @var TenantRepository |
||||
| 41 | */ |
||||
| 42 | protected $tenants; |
||||
| 43 | |||||
| 44 | /** |
||||
| 45 | * DeleteTenant constructor. |
||||
| 46 | * |
||||
| 47 | * @param TenantRepository $tenants |
||||
| 48 | */ |
||||
| 49 | public function __construct(TenantRepository $tenants) |
||||
| 50 | { |
||||
| 51 | $this->tenants = $tenants; |
||||
| 52 | |||||
| 53 | parent::__construct(); |
||||
| 54 | } |
||||
| 55 | |||||
| 56 | /** |
||||
| 57 | * Execute the console command. |
||||
| 58 | * |
||||
| 59 | * @return void |
||||
| 60 | */ |
||||
| 61 | public function handle() |
||||
| 62 | { |
||||
| 63 | if(!$tenant = $this->tenants->findById($this->argument('id'))) { |
||||
|
0 ignored issues
–
show
$this->argument('id') of type array|null|string is incompatible with the type integer expected by parameter $id of Slides\Saml2\Repositorie...tRepository::findById().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 64 | $this->error('Cannot find a tenant #' . $this->argument('id')); |
||||
|
0 ignored issues
–
show
Are you sure
$this->argument('id') of type array|null|string can be used in concatenation?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 65 | return; |
||||
| 66 | } |
||||
| 67 | |||||
| 68 | $tenant->update(array_filter([ |
||||
| 69 | 'key' => $this->option('key'), |
||||
| 70 | 'idp_entity_id' => $this->option('entityId'), |
||||
| 71 | 'idp_login_url' => $this->option('loginUrl'), |
||||
| 72 | 'idp_logout_url' => $this->option('logoutUrl'), |
||||
| 73 | 'idp_x509_cert' => $this->option('x509cert'), |
||||
| 74 | 'relay_state_url' => $this->option('relayStateUrl'), |
||||
| 75 | 'name_id_format' => $this->resolveNameIdFormat(), |
||||
| 76 | 'metadata' => ConsoleHelper::stringToArray($this->option('metadata')) |
||||
| 77 | ])); |
||||
| 78 | |||||
| 79 | if(!$tenant->save()) { |
||||
| 80 | $this->error('Tenant cannot be saved.'); |
||||
| 81 | return; |
||||
| 82 | } |
||||
| 83 | |||||
| 84 | $this->info("The tenant #{$tenant->id} ({$tenant->uuid}) was successfully updated."); |
||||
| 85 | |||||
| 86 | $this->renderTenantCredentials($tenant); |
||||
| 87 | |||||
| 88 | $this->output->newLine(); |
||||
| 89 | } |
||||
| 90 | } |