Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 5m7s
Added jobs, controllers, and PDF generation logic for management report runtime as defined in Spec 379. Includes artifact migrations, payload builders, and testing coverage.
120 lines
3.2 KiB
PHP
120 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Support\Artifacts\ArtifactProviderDetail;
|
|
use App\Support\Artifacts\ArtifactSourceDescriptor;
|
|
use App\Support\Artifacts\ArtifactSourceResolver;
|
|
use App\Support\Concerns\DerivesWorkspaceIdFromTenant;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class StoredReport extends Model
|
|
{
|
|
use DerivesWorkspaceIdFromTenant;
|
|
use HasFactory;
|
|
|
|
public const string REPORT_TYPE_PERMISSION_POSTURE = 'permission_posture';
|
|
|
|
public const string REPORT_TYPE_ENTRA_ADMIN_ROLES = 'entra.admin_roles';
|
|
|
|
public const string REPORT_TYPE_MANAGEMENT_REPORT_PDF = 'management_report.pdf';
|
|
|
|
public const string FORMAT_JSON = 'json';
|
|
|
|
public const string FORMAT_PDF = 'pdf';
|
|
|
|
public const string STATUS_QUEUED = 'queued';
|
|
|
|
public const string STATUS_GENERATING = 'generating';
|
|
|
|
public const string STATUS_READY = 'ready';
|
|
|
|
public const string STATUS_FAILED = 'failed';
|
|
|
|
protected $fillable = [
|
|
'workspace_id',
|
|
'managed_environment_id',
|
|
'source_environment_review_id',
|
|
'source_review_pack_id',
|
|
'operation_run_id',
|
|
'generated_by_user_id',
|
|
'report_type',
|
|
'report_format',
|
|
'status',
|
|
'profile',
|
|
'payload',
|
|
'fingerprint',
|
|
'previous_fingerprint',
|
|
'file_disk',
|
|
'file_path',
|
|
'file_size',
|
|
'sha256',
|
|
'generated_at',
|
|
];
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'payload' => 'array',
|
|
'file_size' => 'integer',
|
|
'generated_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function workspace(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Workspace::class);
|
|
}
|
|
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ManagedEnvironment::class, 'managed_environment_id');
|
|
}
|
|
|
|
public function sourceEnvironmentReview(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EnvironmentReview::class, 'source_environment_review_id');
|
|
}
|
|
|
|
public function sourceReviewPack(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ReviewPack::class, 'source_review_pack_id');
|
|
}
|
|
|
|
public function operationRun(): BelongsTo
|
|
{
|
|
return $this->belongsTo(OperationRun::class);
|
|
}
|
|
|
|
public function generatedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'generated_by_user_id');
|
|
}
|
|
|
|
public function isReadyManagementPdf(): bool
|
|
{
|
|
return $this->report_type === self::REPORT_TYPE_MANAGEMENT_REPORT_PDF
|
|
&& $this->report_format === self::FORMAT_PDF
|
|
&& $this->status === self::STATUS_READY
|
|
&& filled($this->file_disk)
|
|
&& filled($this->file_path);
|
|
}
|
|
|
|
public function artifactSourceDescriptor(): ArtifactSourceDescriptor
|
|
{
|
|
return app(ArtifactSourceResolver::class)->forStoredReport($this);
|
|
}
|
|
|
|
public function artifactProviderDetail(): ArtifactProviderDetail
|
|
{
|
|
return app(ArtifactSourceResolver::class)->providerDetailForStoredReport($this);
|
|
}
|
|
}
|