Skip to content

Commit

Permalink
Merge pull request #26 from d365collaborative/development
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
Splaxi authored Jun 19, 2024
2 parents c1d05ca + a657143 commit ae4d55b
Show file tree
Hide file tree
Showing 19 changed files with 873 additions and 74 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/build-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ on:
- $True
skipghrelease:
description: "Determines if creation of a GitHub release is skipped"
default: $False
default: false
required: false
type: choice
options:
- $False
- $True
type: boolean
skipValidation:
description: "Determines if the module validation is skipped"
default: false
required: false
type: boolean

jobs:
call-tmpl-build-release:
uses: ./.github/workflows/tmpl-build-release.yml
uses: fh-inway/d365.psmodule-alm/.github/workflows/tmpl-build-release.yml@main
with:
module: 'd365bap.tools'
skippublish: ${{ inputs.skippublish }}
skipghrelease: ${{ inputs.skipghrelease }}
skipValidation: ${{ inputs.skipValidation }}
secrets:
apikey: ${{ secrets.ApiKey }}
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

jobs:
call-tmpl-build-release:
uses: ./.github/workflows/tmpl-build-release.yml
uses: fh-inway/d365.psmodule-alm/.github/workflows/tmpl-build-release.yml@main
with:
skippublish: $False
skipghrelease: $False
module: 'd365bap.tools'
secrets:
apikey: ${{ secrets.ApiKey }}
63 changes: 0 additions & 63 deletions .github/workflows/tmpl-build-release.yml

This file was deleted.

4 changes: 4 additions & 0 deletions d365bap.tools/d365bap.tools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
, 'Get-BapEnvironmentApplicationUser'

, 'Get-BapEnvironmentD365App'

, 'Get-BapEnvironmentLinkEnterprisePolicy'

, 'Get-BapEnvironmentSecurityRole'
, 'Get-BapEnvironmentSolution'

, 'Get-BapEnvironmentUser'
Expand All @@ -63,6 +66,7 @@

, 'Invoke-BapEnvironmentInstallD365App'

, 'Set-BapEnvironmentLinkEnterprisePolicy'
, 'Set-BapEnvironmentVirtualEntity'

, 'Update-BapEnvironmentVirtualEntityMetadata'
Expand Down
2 changes: 2 additions & 0 deletions d365bap.tools/functions/Get-BapEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
.PARAMETER EnvironmentId
The id of the environment that you want to work against
Default value is "*" - which translates into all available environments
.PARAMETER AsExcelOutput
Instruct the cmdlet to output all details directly to an Excel file
Expand Down
109 changes: 109 additions & 0 deletions d365bap.tools/functions/Get-BapEnvironmentLinkEnterprisePolicy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

<#
.SYNOPSIS
Get Enterprise Policy
.DESCRIPTION
Get all registered Enterprise Policies from a Dataverse environment and its linked status
.PARAMETER EnvironmentId
The id of the environment that you want to work against
.PARAMETER AsExcelOutput
Instruct the cmdlet to output all details directly to an Excel file
This makes it easier to deep dive into all the details returned from the API, and makes it possible for the user to persist the current state
.EXAMPLE
PS C:\> Get-BapEnvironmentLinkEnterprisePolicy -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6
This will get all Enterprise Policy informations from the Dataverse environment.
Sample output:
PpacEnvId : eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6
PpacEnvName : new-test
Type : identity
policyId : d3e06308-e287-42bb-ad6d-a588ef77d6e8
location : europe
id : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-01/providers/Microsoft.PowerPlatfor
m/enterprisePolicies/EnterprisePolicy-Dataverse
systemId : /regions/europe/providers/Microsoft.PowerPlatform/enterprisePolicies/d3e06308-e287-42bb-ad6d-a588ef77d6e8
linkStatus : Linked
.EXAMPLE
PS C:\> Get-BapEnvironmentLinkEnterprisePolicy -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -AsExcelOutput
This will get all Enterprise Policy informations from the Dataverse environment.
Will output all details into an Excel file, that will auto open on your machine.
.NOTES
Author: Mötz Jensen (@Splaxi)
#>
function Get-BapEnvironmentLinkEnterprisePolicy {
[CmdletBinding()]
[OutputType('System.Object[]')]
param (
[parameter (mandatory = $true)]
[string] $EnvironmentId,

[switch] $AsExcelOutput
)

begin {
# Make sure all *BapEnvironment* cmdlets will validate that the environment exists prior running anything.
$envObj = Get-BapEnvironment -EnvironmentId $EnvironmentId | Select-Object -First 1

if ($null -eq $envObj) {
$messageString = "The supplied EnvironmentId: <c='em'>$EnvironmentId</c> didn't return any matching environment details. Please verify that the EnvironmentId is correct - try running the <c='em'>Get-BapEnvironment</c> cmdlet."
Write-PSFMessage -Level Host -Message $messageString
Stop-PSFFunction -Message "Stopping because environment was NOT found based on the id." -Exception $([System.Exception]::new($($messageString -replace '<[^>]+>', '')))
}

if (Test-PSFFunctionInterrupt) { return }

$tokenBap = Get-AzAccessToken -ResourceUrl "https://service.powerapps.com/"
$headers = @{
"Authorization" = "Bearer $($tokenBap.Token)"
}
}

process {
$body = [PsCustomObject]@{
"SystemId" = $EnterprisePolicyResourceId
} | ConvertTo-Json

# 2019-10-01
$uriLinkEnterprisePolicy = "https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/environments/$EnvironmentId`?api-version=2024-05-01"

$resObj = Invoke-RestMethod -Method Get -Uri $uriLinkEnterprisePolicy -Headers $headers -Body $body -ContentType "application/json"

$resCol = @(
if ($null -ne $resObj.properties.enterprisePolicies) {
foreach ($prop in $resObj.properties.enterprisePolicies.psobject.Properties) {
$enterprisePolicyObj = [ordered]@{
PpacEnvId = $envObj.PpacEnvId
PpacEnvName = $envObj.PpacEnvName
Type = $prop.Name
}

foreach ($innerProp in $prop.Value.psobject.properties) {
$enterprisePolicyObj."$($innerProp.Name)" = $innerProp.Value
}

([PSCustomObject]$enterprisePolicyObj) | Select-PSFObject -TypeName "D365Bap.Tools.Environment.EnterprisePolicy"
}
}
)

if ($AsExcelOutput) {
$resCol | Export-Excel
return
}

$resCol
}

end {

}
}
113 changes: 113 additions & 0 deletions d365bap.tools/functions/Get-BapEnvironmentSecurityRole.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

<#
.SYNOPSIS
Get Security Roles from environment
.DESCRIPTION
Get Security Roles from the Dataverse environment
.PARAMETER EnvironmentId
The id of the environment that you want to work against
.PARAMETER Name
Name of the Security Role that you want to work against
Supports wildcard search
Default value is "*" - which translates into all available Security Roles
.PARAMETER AsExcelOutput
Instruct the cmdlet to output all details directly to an Excel file
This makes it easier to deep dive into all the details returned from the API, and makes it possible for the user to persist the current state
.EXAMPLE
PS C:\> Get-BapEnvironmentSecurityRole -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6
This will list all Security Roles from the Dataverse environment.
Sample output:
Id Name ModifiedOn
-- ---- ----------
5a8c8098-b933-eb11-a813-000d3a8e7ded (Deprecated) Marketing Realti… 03/02/2023 10.11.13
1cbf96a1-b933-eb11-a813-000d3a8e7ded (Deprecated) Marketing Realti… 03/02/2023 10.11.14
d364ba1c-1bfb-eb11-94f0-0022482381ee Accounts Payable Admin 17/08/2023 07.06.15
.EXAMPLE
PS C:\> Get-BapEnvironmentSecurityRole -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -Name "Environment*"
This will list all Security Roles, which matches the "Environment*" pattern, from the Dataverse environment.
Sample output:
Id Name ModifiedOn
-- ---- ----------
d58407f2-48d5-e711-a82c-000d3a37c848 Environment Maker 15/06/2024 21.12.56
.EXAMPLE
PS C:\> Get-BapEnvironmentSecurityRole -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -AsExcelOutput
This will list all Security Roles from the Dataverse environment.
Will output all details into an Excel file, that will auto open on your machine.
.NOTES
General notes
#>
function Get-BapEnvironmentSecurityRole {
[CmdletBinding()]
param (
[parameter (mandatory = $true)]
[string] $EnvironmentId,

[string] $Name = "*",

[switch] $AsExcelOutput
)

begin {
# Make sure all *BapEnvironment* cmdlets will validate that the environment exists prior running anything.
$envObj = Get-BapEnvironment -EnvironmentId $EnvironmentId | Select-Object -First 1

if ($null -eq $envObj) {
$messageString = "The supplied EnvironmentId: <c='em'>$EnvironmentId</c> didn't return any matching environment details. Please verify that the EnvironmentId is correct - try running the <c='em'>Get-BapEnvironment</c> cmdlet."
Write-PSFMessage -Level Host -Message $messageString
Stop-PSFFunction -Message "Stopping because environment was NOT found based on the id." -Exception $([System.Exception]::new($($messageString -replace '<[^>]+>', '')))
}

if (Test-PSFFunctionInterrupt) { return }

$baseUri = $envObj.LinkedMetaPpacEnvUri
$tokenWebApi = Get-AzAccessToken -ResourceUrl $baseUri
$headersWebApi = @{
"Authorization" = "Bearer $($tokenWebApi.Token)"
}
}

process {
if (Test-PSFFunctionInterrupt) { return }

$resRoles = Invoke-RestMethod -Method Get -Uri $($baseUri + '/api/data/v9.2/roles') -Headers $headersWebApi

$resCol = @(
foreach ($roleObj in $($resRoles.value | Sort-Object -Property name)) {
if (-not ($roleObj.Name -like $Name)) { continue }

$roleObj | Select-PSFObject -TypeName "D365Bap.Tools.Role" -ExcludeProperty "@odata.etag" -Property "roleid as Id", *
}
)

if (-not $IncludeAppIds) {
$resCol = $resCol | Where-Object applicationid -eq $null
}

if ($AsExcelOutput) {
$resCol | Export-Excel
return
}

$resCol
}

end {

}
}
Loading

0 comments on commit ae4d55b

Please sign in to comment.