microsoft / devcenter-catalog

MIT License
26 stars 78 forks source link

Add support for inline base64-encoded winget configuration content #63

Closed DavidObando closed 5 months ago

DavidObando commented 5 months ago

Changes done

How testing was done

Most changes were trivial to test. For "RunAsUser" as well as the classically supported provisioning context, I ran a terminal as system via psexec -s pwsh, confirming I'm running as system by seeing that whoami returns nt authority\system. I then ran all the scenarios in the examples of task.yaml by manually invoking main.ps1 with the adequate parameters.

For the new functionality, I tested running it under the user context, not system, and did so by having a winget configuration file and running the following commands:

$base64 = [Convert]::ToBase64String([IO.File]::ReadAllBytes("C:\GitHub\Microsoft\devcenter-catalog\Tasks\winget\configuration.dsc.yaml"))
.\main.ps1 -InlineConfigurationBase64 $base64

The machine was configured as expected. For my configuration file, I used these contents:

# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
properties:
  ########################################
  ### ASSERTIONS: System Requirements
  ########################################
  assertions:
    ### Assertion: OS Version
    ### -------------------------------------
    - resource: Microsoft.Windows.Developer/OsVersion
      id: OsVersion
      directives:
        description: Minimum OS version requirement
        allowPrerelease: true
      settings:
        MinVersion: "10.0.22000"

  ########################################
  ### RESOURCES: System Configuration
  ########################################
  resources:
    ### Enable: Developer Mode
    ### -------------------------------------
    - resource: Microsoft.Windows.Developer/DeveloperMode
      id: DeveloperMode
      directives:
        description: Enable Developer Mode
        allowPrerelease: true
      settings:
        Ensure: Present

    ### Install: NotePad++
    ### -------------------------------------
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: Notepad++
      directives:
        description: Install Notepad++
        allowPrerelease: true
      settings:
        id: Notepad++.Notepad++
        source: winget
        ensure: Present

    ### Install: 7Zip
    ### -------------------------------------
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: 7Zip
      directives:
        description: Install 7Zip
        allowPrerelease: true
        minimumVersion: "23.01"
      settings:
        id: "7zip.7zip"
        source: winget
        ensure: Absent

    ### Install: NVAccess.NVDA
    ### -------------------------------------
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: NVDA
      directives:
        description: Install NVAccess.NVDA
        allowPrerelease: true
      settings:
        id: NVAccess.NVDA
        source: winget
        ensure: Present

    ### Install: Freedom Scientific JAWS 2023
    ### -------------------------------------
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: JAWS
      directives:
        description: Freedom Scientific JAWS 2023
        allowPrerelease: true
      settings:
        id: FreedomScientific.JAWS.2023
        source: winget
        ensure: Present

    ### Install: Git
    ### -------------------------------------
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: Git
      directives:
        description: Install Git
        allowPrerelease: true
      settings:
        id: Git.Git
        source: winget
        ensure: Present

    ### Install: Python 3.10
    ### -------------------------------------
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: Python
      directives:
        description: Install Python 3.10
        minimumVersion: "3.8.10"
        maximumVersion: "3.10.0"
        allowPrerelease: true
      settings:
        id: Python.Python.3.10
        source: winget
        ensure: Present

    ### Install: Visual Studio Code
    ### -------------------------------------
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: VSCode
      directives:
        description: Install Visual Studio Code
        allowPrerelease: true
        minimumVersion: "1.85.1"
      settings:
        id: Microsoft.VisualStudioCode
        source: winget
        ensure: Present

    ### Install: Visual Studio Code Extensions
    ### -------------------------------------
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: VSCodeExtensions
      dependsOn:
        - VSCode
      directives:
        description: Install Visual Studio Code Extensions
        allowPrerelease: true
      settings:
        id: Microsoft.VisualStudioCode
        source: winget
        ensure: Present
      extensions:
        - ms-python.python
        - ms-vscode.powershell
        - GitHub.copilot

    ### Install: Microsoft.PowerShell
    ### -------------------------------------
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: PowerShell
      directives:
        description: Install Microsoft.PowerShell
        allowPrerelease: true
        minimumVersion: "7.4.0.0"
        maximumVersion: "7.4.0.0"
      settings:
        id: Microsoft.PowerShell
        source: winget
        ensure: Present

    ### Install: Microsoft.PowerShell Modules
    ### -------------------------------------
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: PowerShellModules
      dependsOn:
        - PowerShell
      directives:
        description: Install Microsoft.PowerShell Modules
        allowPrerelease: true
      settings:
        id: Microsoft.PowerShell
        source: winget
        ensure: Present
      extensions:
        - Microsoft.PowerShell.DSC
        - Microsoft.PowerShell.PSDesiredStateConfiguration
        - Microsoft.PowerShell.PowerShellGet
        #- Microsoft.PowerShell.SecretManagement
        #- Microsoft.PowerShell.SDK
        #- Microsoft.PowerShell.UnmanagedPSResources
        #- Microsoft.PowerShell.Utility
        #- Microsoft.PowerShell.Management
        #- Microsoft.PowerShell.Security
        #- Microsoft.PowerShell.ConsoleHost
        #- Microsoft.PowerShell.Core
        #- Microsoft.PowerShell.Diagnostics
        #- Microsoft.PowerShell.Host
        #- Microsoft.PowerShell.LocalAccounts
        #- Microsoft.PowerShell.Management
        #- Microsoft.PowerShell.Security
        #- Microsoft.PowerShell.Utility
        #- Microsoft.PowerShell.Workflow
        #- Microsoft.PowerShell.ISE
        #- Microsoft.PowerShell.Archive
        #- Microsoft.PowerShell.Extension.VSCode
        #- Microsoft.PowerShell.Operation.Validation

    #- resource: Microsoft.PowerShell.DSC/PSDesiredStateConfiguration
    #  dependsOn:
    #    - PowerShell
    #  directives:
    #    description: Install Microsoft.PowerShell Modules
    #    allowPrerelease: true
    #  settings:
    #    Ensure: Present
    #    Name: PSDesiredStateConfiguration
    #    ModuleVersion: ""

    ### Install: Visual Studio 2022 Community
    ### -------------------------------------
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: VisualStudioCommunity2022
      directives:
        description: Visual Studio Community 2022
        allowPrerelease: true
      settings:
        id: Microsoft.VisualStudio.2022.Community
        source: winget
        ensure: Present

    #### Install: Python Workload for Visual Studio 2022
    #### -------------------------------------
    - resource: Microsoft.VisualStudio.DSC/VSComponents
      dependsOn:
        - VisualStudioCommunity2022
      directives:
        description: Install Python Workload for Visual Studio 2022
        allowPrerelease: true
      settings:
        productId: Microsoft.VisualStudio.Product.Community
        channelId: VisualStudio.17.Release
        includeRecommended: true
        components:
          - Microsoft.VisualStudio.Workload.Python

    ### Install: Windows Package Manager Manifest Creator
    ### -------------------------------------
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: WinGetCreate
      directives:
        description: Install Microsoft.WingetCreate
        allowPrerelease: true
      settings:
        id: Microsoft.WingetCreate
        source: winget
        ensure: Present

  configurationVersion: 0.2.0