231 lines
7.9 KiB
PHP
231 lines
7.9 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Intune;
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
class EnrollmentAutopilotPolicyNormalizer implements PolicyTypeNormalizer
|
|
{
|
|
public function __construct(private readonly DefaultPolicyNormalizer $defaultNormalizer) {}
|
|
|
|
public function supports(string $policyType): bool
|
|
{
|
|
return in_array($policyType, [
|
|
'windowsAutopilotDeploymentProfile',
|
|
'windowsEnrollmentStatusPage',
|
|
'enrollmentRestriction',
|
|
], true);
|
|
}
|
|
|
|
/**
|
|
* @return array{status: string, settings: array<int, array<string, mixed>>, settings_table?: array<string, mixed>, warnings: array<int, string>}
|
|
*/
|
|
public function normalize(?array $snapshot, string $policyType, ?string $platform = null): array
|
|
{
|
|
$snapshot = is_array($snapshot) ? $snapshot : [];
|
|
|
|
$displayName = Arr::get($snapshot, 'displayName') ?? Arr::get($snapshot, 'name');
|
|
$description = Arr::get($snapshot, 'description');
|
|
|
|
$warnings = [];
|
|
|
|
if ($policyType === 'enrollmentRestriction') {
|
|
$warnings[] = 'Restore is preview-only for Enrollment Restrictions.';
|
|
}
|
|
|
|
$generalEntries = [
|
|
['key' => 'Type', 'value' => $policyType],
|
|
];
|
|
|
|
if (is_string($displayName) && $displayName !== '') {
|
|
$generalEntries[] = ['key' => 'Display name', 'value' => $displayName];
|
|
}
|
|
|
|
if (is_string($description) && $description !== '') {
|
|
$generalEntries[] = ['key' => 'Description', 'value' => $description];
|
|
}
|
|
|
|
$odataType = Arr::get($snapshot, '@odata.type');
|
|
if (is_string($odataType) && $odataType !== '') {
|
|
$generalEntries[] = ['key' => '@odata.type', 'value' => $odataType];
|
|
}
|
|
|
|
$roleScopeTagIds = Arr::get($snapshot, 'roleScopeTagIds');
|
|
if (is_array($roleScopeTagIds) && $roleScopeTagIds !== []) {
|
|
$generalEntries[] = ['key' => 'Scope tag IDs', 'value' => array_values($roleScopeTagIds)];
|
|
}
|
|
|
|
$settings = [
|
|
[
|
|
'type' => 'keyValue',
|
|
'title' => 'General',
|
|
'entries' => $generalEntries,
|
|
],
|
|
];
|
|
|
|
$typeBlock = match ($policyType) {
|
|
'windowsAutopilotDeploymentProfile' => $this->buildAutopilotBlock($snapshot),
|
|
'windowsEnrollmentStatusPage' => $this->buildEnrollmentStatusPageBlock($snapshot),
|
|
'enrollmentRestriction' => $this->buildEnrollmentRestrictionBlock($snapshot),
|
|
default => null,
|
|
};
|
|
|
|
if ($typeBlock !== null) {
|
|
$settings[] = $typeBlock;
|
|
}
|
|
|
|
$settings = array_values(array_filter($settings));
|
|
|
|
return [
|
|
'status' => 'ok',
|
|
'settings' => $settings,
|
|
'warnings' => $warnings,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array{type: string, title: string, entries: array<int, array{key: string, value: mixed}>}|null
|
|
*/
|
|
private function buildAutopilotBlock(array $snapshot): ?array
|
|
{
|
|
$entries = [];
|
|
|
|
foreach ([
|
|
'deviceNameTemplate' => 'Device name template',
|
|
'language' => 'Language',
|
|
'locale' => 'Locale',
|
|
'deploymentMode' => 'Deployment mode',
|
|
'deviceType' => 'Device type',
|
|
'enableWhiteGlove' => 'Pre-provisioning (White Glove)',
|
|
'hybridAzureADJoinSkipConnectivityCheck' => 'Skip Hybrid AAD connectivity check',
|
|
] as $key => $label) {
|
|
$value = Arr::get($snapshot, $key);
|
|
|
|
if (is_string($value) && $value !== '') {
|
|
$entries[] = ['key' => $label, 'value' => $value];
|
|
} elseif (is_bool($value)) {
|
|
$entries[] = ['key' => $label, 'value' => $value ? 'Enabled' : 'Disabled'];
|
|
}
|
|
}
|
|
|
|
$oobe = Arr::get($snapshot, 'outOfBoxExperienceSettings');
|
|
if (is_array($oobe) && $oobe !== []) {
|
|
$entries[] = ['key' => 'Out-of-box experience', 'value' => Arr::except($oobe, ['@odata.type'])];
|
|
}
|
|
|
|
$assignments = Arr::get($snapshot, 'assignments');
|
|
if (is_array($assignments) && $assignments !== []) {
|
|
$entries[] = ['key' => 'Assignments (snapshot)', 'value' => '[present]'];
|
|
}
|
|
|
|
if ($entries === []) {
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'type' => 'keyValue',
|
|
'title' => 'Autopilot profile',
|
|
'entries' => $entries,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array{type: string, title: string, entries: array<int, array{key: string, value: mixed}>}|null
|
|
*/
|
|
private function buildEnrollmentStatusPageBlock(array $snapshot): ?array
|
|
{
|
|
$entries = [];
|
|
|
|
foreach ([
|
|
'priority' => 'Priority',
|
|
'showInstallationProgress' => 'Show installation progress',
|
|
'blockDeviceSetupRetryByUser' => 'Block retry by user',
|
|
'allowDeviceResetOnInstallFailure' => 'Allow device reset on install failure',
|
|
'installProgressTimeoutInMinutes' => 'Install progress timeout (minutes)',
|
|
'allowLogCollectionOnInstallFailure' => 'Allow log collection on failure',
|
|
] as $key => $label) {
|
|
$value = Arr::get($snapshot, $key);
|
|
|
|
if (is_int($value) || is_float($value)) {
|
|
$entries[] = ['key' => $label, 'value' => $value];
|
|
} elseif (is_string($value) && $value !== '') {
|
|
$entries[] = ['key' => $label, 'value' => $value];
|
|
} elseif (is_bool($value)) {
|
|
$entries[] = ['key' => $label, 'value' => $value ? 'Enabled' : 'Disabled'];
|
|
}
|
|
}
|
|
|
|
$selected = Arr::get($snapshot, 'selectedMobileAppIds');
|
|
if (is_array($selected) && $selected !== []) {
|
|
$entries[] = ['key' => 'Selected mobile app IDs', 'value' => array_values($selected)];
|
|
}
|
|
|
|
$assigned = Arr::get($snapshot, 'assignments');
|
|
if (is_array($assigned) && $assigned !== []) {
|
|
$entries[] = ['key' => 'Assignments (snapshot)', 'value' => '[present]'];
|
|
}
|
|
|
|
if ($entries === []) {
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'type' => 'keyValue',
|
|
'title' => 'Enrollment Status Page (ESP)',
|
|
'entries' => $entries,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array{type: string, title: string, entries: array<int, array{key: string, value: mixed}>}|null
|
|
*/
|
|
private function buildEnrollmentRestrictionBlock(array $snapshot): ?array
|
|
{
|
|
$entries = [];
|
|
|
|
foreach ([
|
|
'priority' => 'Priority',
|
|
'version' => 'Version',
|
|
'deviceEnrollmentConfigurationType' => 'Configuration type',
|
|
] as $key => $label) {
|
|
$value = Arr::get($snapshot, $key);
|
|
|
|
if (is_int($value) || is_float($value)) {
|
|
$entries[] = ['key' => $label, 'value' => $value];
|
|
} elseif (is_string($value) && $value !== '') {
|
|
$entries[] = ['key' => $label, 'value' => $value];
|
|
}
|
|
}
|
|
|
|
$platforms = Arr::get($snapshot, 'platformRestrictions');
|
|
if (is_array($platforms) && $platforms !== []) {
|
|
$entries[] = ['key' => 'Platform restrictions', 'value' => Arr::except($platforms, ['@odata.type'])];
|
|
}
|
|
|
|
$assigned = Arr::get($snapshot, 'assignments');
|
|
if (is_array($assigned) && $assigned !== []) {
|
|
$entries[] = ['key' => 'Assignments (snapshot)', 'value' => '[present]'];
|
|
}
|
|
|
|
if ($entries === []) {
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'type' => 'keyValue',
|
|
'title' => 'Enrollment restrictions',
|
|
'entries' => $entries,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function flattenForDiff(?array $snapshot, string $policyType, ?string $platform = null): array
|
|
{
|
|
$normalized = $this->normalize($snapshot ?? [], $policyType, $platform);
|
|
|
|
return $this->defaultNormalizer->flattenNormalizedForDiff($normalized);
|
|
}
|
|
}
|