Skip to content

Adds Find-MgGraphCommand #816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
38254ee
Features/find mg command (#765)
peombwa Jul 15, 2021
1a56711
Handle defaults.
peombwa Jul 19, 2021
0fb1007
Add Find-MgGraphCommand tests.
peombwa Jul 21, 2021
7368e36
Use session object to cache MgCommandMetadata file.
peombwa Jul 21, 2021
de8f679
Add ability to filter commands using paramters.
peombwa Jul 22, 2021
b7b46b3
Formart output.
peombwa Jul 23, 2021
7fa6be2
Sort metadata.
peombwa Jul 24, 2021
686c097
Merge branch 'dev' into features/FindMgGraphCommand
peombwa Aug 2, 2021
1128578
Update tests.
peombwa Aug 2, 2021
9cdd36d
Export scripts.
peombwa Aug 3, 2021
c1bfdee
Trip trailing \ or /
peombwa Aug 3, 2021
df85c30
Add run script for auth module.
peombwa Aug 3, 2021
05cb004
Add pester test for module.
peombwa Aug 3, 2021
53d5d13
Merge branch 'dev' into features/FindMgGraphCommand
peombwa Aug 6, 2021
564e9c3
Update AzDO to generate command metadata weekly.
peombwa Aug 9, 2021
d7db061
Update pester tests.
peombwa Aug 10, 2021
06e7ed8
Remove unused assets.
peombwa Aug 10, 2021
108e527
Code clean-up.
peombwa Aug 11, 2021
fc50dfe
Merge branch 'dev' into features/FindMgGraphCommand
peombwa Aug 11, 2021
64b98b0
Merge branch 'dev' into features/FindMgGraphCommand
peombwa Aug 12, 2021
ba62235
Merge remote-tracking branch 'origin/dev' into features/FindMgGraphCo…
peombwa Aug 13, 2021
86e909a
Remove duplicate copy-item at build.
peombwa Aug 13, 2021
eae9edb
Merge branch 'dev' into features/FindMgGraphCommand
peombwa Sep 2, 2021
02abf1b
Remove fully qualified namespaces from actions and functions.
peombwa Sep 3, 2021
8515f33
Add Pester tests for FQNamespace actions and functions.
peombwa Sep 3, 2021
d121013
Merge branch 'dev' into features/FindMgGraphCommand
peombwa Sep 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .azure-pipelines/common-templates/checkout.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

parameters:
- name: TargetBranch
type: string
default: ''

steps:
- checkout: self
clean: true
Expand All @@ -15,6 +20,18 @@ steps:
git config --global user.email "[email protected]"
git config --global user.name "Microsoft Graph DevX Tooling"

- task: Bash@3
displayName: "Switch branch to target branch: $(TargetBranch)"
condition: and(succeeded(), eq('${{ parameters.TargetBranch }}', ''))
inputs:
targetType: inline
script: |
git status
git fetch --all
git checkout $(TargetBranch)
git pull
git status

- task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2
displayName: "Run CredScan"
inputs:
Expand Down
6 changes: 3 additions & 3 deletions .azure-pipelines/common-templates/download-openapi-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
pool: $(BuildAgent)
steps:
- template: ./checkout.yml
parameters:
TargetBranch: $(BaseBranch)

- template: ./install-tools-template.yml

Expand All @@ -36,8 +38,6 @@ jobs:
targetType: inline
script: |
git status
git fetch --all
git checkout $(BaseBranch)
git branch $(ComputeBranch.WeeklyBranch)
git checkout $(ComputeBranch.WeeklyBranch)
git status
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
. "$(System.DefaultWorkingDirectory)\tools\SetServiceModuleVersion.ps1" -VersionNumber $NewModuleVersion -Modules $_
} catch {
if ($_.Exception.Message -like "No match*") {
Write-Warning "$_. Version will be set to $NewMetaModuleVersion."
Write-Warning "$_. Version will be set to $NewMetaModuleVersion."
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

- task: PowerShell@2
displayName: Generate command metadata
inputs:
targetType: inline
pwsh: true
script: |
. $(System.DefaultWorkingDirectory)/tools/PostGeneration/NewCommandMetadata.ps1 -SourcePath "$(System.DefaultWorkingDirectory)/src/" -IncludePermissions -Debug

- task: Bash@3
displayName: Push command metadata
enabled: true
env:
GITHUB_TOKEN: $(GITHUB_TOKEN)
inputs:
targetType: inline
script: |
git status
git add "$(System.DefaultWorkingDirectory)/src/Authentication/Authentication/custom/common/MgCommandMetadata.json"
git commit -m 'Add generated MgCommandMetadata.json. [run ci]'
git push
git status
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ parameters:
- name: PublishToFeed
type: boolean
default: false
- name: GenerateCommandMetadata
type: boolean
default: false
- name: GenerateHelpDocs
type: boolean
default: false
- name: DOCSBRANCH
type: string
default: "DocsGeneration"
Expand All @@ -35,20 +41,16 @@ jobs:
ModulePrefix: ${{ parameters.ModulePrefix }}
EnableSigning: ${{ parameters.EnableSigning }}
PublishToFeed: ${{ parameters.PublishToFeed }}
GenerateCommandMetadata: ${{ parameters.GenerateCommandMetadata }}
GenerateHelpDocs: ${{ parameters.GenerateHelpDocs }}
DocsBranch: ${{ parameters.DocsBranch }}
steps:
- template: ../common-templates/checkout.yml
parameters:
TargetBranch: $(Branch)

- template: ../common-templates/install-tools-template.yml
- template: ../common-templates/security-prechecks-template.yml
- task: Bash@3
displayName: "Switch branch to $(Branch)"
inputs:
targetType: inline
script: |
git status
git fetch --all
git checkout $(Branch)
git pull
git status

- task: PowerShell@2
displayName: Build auth module
Expand Down Expand Up @@ -143,11 +145,9 @@ jobs:
[bool]$EnableSigning = if ("$(EnableSigning)" -eq "true") { $true } else { $false }
$Modules = "$(ModulesToGenerate)" -split " "
. $(System.DefaultWorkingDirectory)/tools/GenerateModules.ps1 -Build -Test -UpdateAutoRest -EnableSigning:$EnableSigning -ModulesToGenerate $Modules -ExcludeExampleTemplates -ExcludeNotesSection

- template: ./generate-helpdocs-template.yml
parameters:
DOCSBRANCH: $(DocsBranch)
ModulesToGenerate: $(ModulesToGenerate)

- ${{ if eq(parameters.GenerateCommandMetadata, true) }}:
- template: ./generate-command-metadata-template.yml

- task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@1
displayName: ESRP DLL strong name (Service Modules)
Expand Down Expand Up @@ -281,4 +281,10 @@ jobs:
publishVstsFeed: "0985d294-5762-4bc2-a565-161ef349ca3e/edc337b9-e5ea-49dd-a2cb-e8d66668ca57"
allowPackageConflicts: true

- ${{ if eq(parameters.GenerateHelpDocs, true) }}:
- template: ./generate-helpdocs-template.yml
parameters:
DOCSBRANCH: $(DocsBranch)
ModulesToGenerate: $(ModulesToGenerate)

- template: ../common-templates/security-postchecks-template.yml
3 changes: 2 additions & 1 deletion .azure-pipelines/weekly-generation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ stages:
jobs:
- template: generation-templates/generate-service-modules.yml
parameters:
ModulesToGenerate: $[ stageDependencies.DownloadOpenAPIDocs.GetLatestDocs.outputs['OpenAPIDocDiff.ModulesWithChanges'] ]
Branch: $[ stageDependencies.DownloadOpenAPIDocs.GetLatestDocs.outputs['ComputeBranch.WeeklyBranch'] ]
AuthModulePath: "src/Authentication/Authentication"
ServiceModulePath: "src/"
ModulePrefix: "Microsoft.Graph"
EnableSigning: false
PublishToFeed: false
GenerateCommandMetadata: true
GenerateHelpDocs: true
12 changes: 6 additions & 6 deletions .github/workflows/create-openapidocs-pr-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ name: "Create Weekly OpenAPIDocs Download PR"
# events but only for the master branch
on:
push:
branches:
branches:
- 'WeeklyOpenApiDocsDownload/*'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
createOpenApiDocsPR:
if: github.event_name == 'push' && !contains(toJson(github.event.commits), 'NO_CI') && !contains(toJson(github.event.commits), '[ci skip]') && !contains(toJson(github.event.commits), '[skip ci]')
if: github.event_name == 'push' && contains(toJson(github.event.commits), '[run ci]') && !contains(toJson(github.event.commits), 'NO_CI') && !contains(toJson(github.event.commits), '[ci skip]') && !contains(toJson(github.event.commits), '[skip ci]')
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
Expand All @@ -22,17 +22,17 @@ jobs:
run: |
git config --global user.email "[email protected]"
git config --global user.name "Microsoft Graph DevX Tooling"

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout
uses: actions/checkout@v2

- name: List Directory
run: |
run: |
echo $GITHUB_WORKSPACE
ls -lsa $GITHUB_WORKSPACE
ls -lsa $GITHUB_WORKSPACE/tools

# Create a pull request [1]
- name: Create PR using the GitHub REST API via hub
shell: bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.Graph.PowerShell.Authentication
using Microsoft.Graph.PowerShell.Authentication.Interfaces;

using System;
using System.Collections;
using System.Security;
using System.Threading;

Expand Down Expand Up @@ -62,6 +63,11 @@ public byte[] MSALToken
/// </summary>
public IGraphEnvironment Environment { get; set; }

/// <summary>
/// Represents a collection of Microsoft Graph PowerShell meta-info.
/// </summary>
public Hashtable[] MgCommandMetadata { get; set; }

/// <summary>
/// Gets an instance of <see cref="GraphSession"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Microsoft.Graph.PowerShell
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Linq.Expressions;
using System.Management.Automation;
public static class PSCmdletExtensions
Expand Down Expand Up @@ -119,5 +120,14 @@ internal static GraphSettings GetContextSettings(this PSCmdlet cmdlet)
{
return new GraphSettings(ProtectedFileProvider.CreateFileProvider(Constants.SettingFilePath, FileProtection.SharedRead));
}

internal static IEnumerable<T> RunScript<T>(string script)
=> PowerShell.Create().AddScript(script).Invoke<T>();

internal static IEnumerable<T> RunScript<T>(this PSCmdlet cmdlet, string script)
=> cmdlet?.InvokeCommand.RunScript<T>(script) ?? RunScript<T>(script);

internal static IEnumerable<T> RunScript<T>(this CommandInvocationIntrinsics cii, string script)
=> cii.InvokeScript(script).Select(o => o?.BaseObject).Where(o => o != null).OfType<T>();
}
}
4 changes: 2 additions & 2 deletions src/Authentication/Authentication/Helpers/StringUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace Microsoft.Graph.PowerShell.Authentication.Helpers
{
internal static class StringUtil
public static class StringUtil
{
/// <summary>
/// Formats the specified string, using the current culture.
Expand Down Expand Up @@ -79,7 +79,7 @@ internal static string FormatDictionary(this IDictionary content)
/// <param name="error">An error record if the conversion failed.</param>
/// <returns>A <see cref="System.Management.Automation.PSObject"/> or a <see cref="System.Collections.Hashtable"/>
/// if the <paramref name="returnHashtable"/> parameter is true.</returns>
internal static object ConvertFromJson(this string jsonString, bool returnHashtable, int? maxDepth, out ErrorRecord error)
public static object ConvertFromJson(this string jsonString, bool returnHashtable, int? maxDepth, out ErrorRecord error)
{
if (jsonString == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Configuration>
<ViewDefinitions>
<View>
<Name>AuthConfigView</Name>
<Name>Microsoft.Graph.PowerShell.Authentication.Models.AuthConfig</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Graph.PowerShell.Authentication.Models.AuthConfig</TypeName>
</ViewSelectedBy>
Expand Down Expand Up @@ -33,6 +33,77 @@
</TableControl>
</View>

<View>
<Name>Microsoft.Graph.PowerShell.Authentication.Models.GraphCommand</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Graph.PowerShell.Authentication.Models.GraphCommand</TypeName>
</ViewSelectedBy>
<GroupBy>
<PropertyName>APIVersion</PropertyName>
<Label>APIVersion</Label>
</GroupBy>
<TableControl>
<TableHeaders>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Command</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Module</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Method</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>URI</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>OutputType</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Permissions</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Variants</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

<View>
<Name>Microsoft.Graph.PowerShell.Authentication.Models.GraphPermission</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Graph.PowerShell.Authentication.Models.GraphPermission</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>IsAdmin</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Description</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>FullDescription</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

<View>
<Name>Permission</Name>
<ViewSelectedBy>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<file src="artifacts\Microsoft.Graph.Authentication.dll" />
<file src="artifacts\Microsoft.Graph.Authentication.Core.dll" />
<file src="artifacts\Microsoft.Graph.Core.dll" />
<file src="artifacts\StartupScripts\*" target="StartupScripts" />
<file src="artifacts\StartupScripts\" target="StartupScripts" />
<file src="artifacts\custom\" target="custom" />
<file src="artifacts\Dependencies\Newtonsoft.Json.dll" target="Dependencies" />
<file src="artifacts\Dependencies\Microsoft.Graph.Auth.dll" target="Dependencies" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft
#
# Generated on: 8/4/2021
# Generated on: 8/3/2021
#

@{
Expand Down Expand Up @@ -69,7 +69,7 @@ FormatsToProcess = 'Microsoft.Graph.Authentication.format.ps1xml'
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Find-MgGraphPermission'
FunctionsToExport = 'Find-MgGraphCommand', 'Find-MgGraphPermission'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = 'Connect-MgGraph', 'Disconnect-MgGraph', 'Get-MgContext',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# Load the module dll
$null = Import-Module -Name (Join-Path $PSScriptRoot 'Microsoft.Graph.Authentication.dll')
$ModulePath = (Join-Path $PSScriptRoot 'Microsoft.Graph.Authentication.dll')
$null = Import-Module -Name $ModulePath

# Export nothing to clear implicit exports.
Export-ModuleMember

if (Test-Path -Path "$PSScriptRoot\StartupScripts" -ErrorAction Ignore)
{
Expand All @@ -9,6 +13,9 @@ if (Test-Path -Path "$PSScriptRoot\StartupScripts" -ErrorAction Ignore)
}
}

# Export binary module cmdlets.
Export-ModuleMember -Cmdlet (Get-ModuleCmdlet -ModulePath $ModulePath) -Alias (Get-ModuleCmdlet -ModulePath $ModulePath -AsAlias)

$DependencyPath = (Join-Path $PSScriptRoot -ChildPath "Dependencies")
if (Test-Path $DependencyPath -ErrorAction Ignore)
{
Expand Down
Loading