Skip to content

Commit b7d85f2

Browse files
authored
Adds Find-MgGraphCommand (#816)
* Features/find mg command (#765) * Add command metadata generation script. * Add Find-MgCommand script. * Handle defaults. * Add Find-MgGraphCommand tests. * Use session object to cache MgCommandMetadata file. * Add ability to filter commands using paramters. * Formart output. * Sort metadata. * Update tests. * Export scripts. * Trip trailing \ or / * Add run script for auth module. * Add pester test for module. * Update AzDO to generate command metadata weekly. * Update pester tests. * Remove unused assets. * Code clean-up. * Remove duplicate copy-item at build. * Remove fully qualified namespaces from actions and functions. * Add Pester tests for FQNamespace actions and functions.
1 parent cb6dab2 commit b7d85f2

30 files changed

Lines changed: 192802 additions & 87 deletions

.azure-pipelines/common-templates/checkout.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4+
parameters:
5+
- name: TargetBranch
6+
type: string
7+
default: ''
8+
49
steps:
510
- checkout: self
611
clean: true
@@ -15,6 +20,18 @@ steps:
1520
git config --global user.email "GraphTooling@service.microsoft.com"
1621
git config --global user.name "Microsoft Graph DevX Tooling"
1722
23+
- task: Bash@3
24+
displayName: "Switch branch to target branch: $(TargetBranch)"
25+
condition: and(succeeded(), eq('${{ parameters.TargetBranch }}', ''))
26+
inputs:
27+
targetType: inline
28+
script: |
29+
git status
30+
git fetch --all
31+
git checkout $(TargetBranch)
32+
git pull
33+
git status
34+
1835
- task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2
1936
displayName: "Run CredScan"
2037
inputs:

.azure-pipelines/common-templates/download-openapi-docs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
pool: $(BuildAgent)
1919
steps:
2020
- template: ./checkout.yml
21+
parameters:
22+
TargetBranch: $(BaseBranch)
2123

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

@@ -36,8 +38,6 @@ jobs:
3638
targetType: inline
3739
script: |
3840
git status
39-
git fetch --all
40-
git checkout $(BaseBranch)
4141
git branch $(ComputeBranch.WeeklyBranch)
4242
git checkout $(ComputeBranch.WeeklyBranch)
4343
git status
@@ -110,7 +110,7 @@ jobs:
110110
. "$(System.DefaultWorkingDirectory)\tools\SetServiceModuleVersion.ps1" -VersionNumber $NewModuleVersion -Modules $_
111111
} catch {
112112
if ($_.Exception.Message -like "No match*") {
113-
Write-Warning "$_. Version will be set to $NewMetaModuleVersion."
113+
Write-Warning "$_. Version will be set to $NewMetaModuleVersion."
114114
}
115115
}
116116
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
- task: PowerShell@2
5+
displayName: Generate command metadata
6+
inputs:
7+
targetType: inline
8+
pwsh: true
9+
script: |
10+
. $(System.DefaultWorkingDirectory)/tools/PostGeneration/NewCommandMetadata.ps1 -SourcePath "$(System.DefaultWorkingDirectory)/src/" -IncludePermissions -Debug
11+
12+
- task: Bash@3
13+
displayName: Push command metadata
14+
enabled: true
15+
env:
16+
GITHUB_TOKEN: $(GITHUB_TOKEN)
17+
inputs:
18+
targetType: inline
19+
script: |
20+
git status
21+
git add "$(System.DefaultWorkingDirectory)/src/Authentication/Authentication/custom/common/MgCommandMetadata.json"
22+
git commit -m 'Add generated MgCommandMetadata.json. [run ci]'
23+
git push
24+
git status

.azure-pipelines/generation-templates/generate-service-modules.yml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ parameters:
1818
- name: PublishToFeed
1919
type: boolean
2020
default: false
21+
- name: GenerateCommandMetadata
22+
type: boolean
23+
default: false
24+
- name: GenerateHelpDocs
25+
type: boolean
26+
default: false
2127
- name: DOCSBRANCH
2228
type: string
2329
default: "DocsGeneration"
@@ -35,20 +41,16 @@ jobs:
3541
ModulePrefix: ${{ parameters.ModulePrefix }}
3642
EnableSigning: ${{ parameters.EnableSigning }}
3743
PublishToFeed: ${{ parameters.PublishToFeed }}
44+
GenerateCommandMetadata: ${{ parameters.GenerateCommandMetadata }}
45+
GenerateHelpDocs: ${{ parameters.GenerateHelpDocs }}
3846
DocsBranch: ${{ parameters.DocsBranch }}
3947
steps:
48+
- template: ../common-templates/checkout.yml
49+
parameters:
50+
TargetBranch: $(Branch)
51+
4052
- template: ../common-templates/install-tools-template.yml
4153
- template: ../common-templates/security-prechecks-template.yml
42-
- task: Bash@3
43-
displayName: "Switch branch to $(Branch)"
44-
inputs:
45-
targetType: inline
46-
script: |
47-
git status
48-
git fetch --all
49-
git checkout $(Branch)
50-
git pull
51-
git status
5254

5355
- task: PowerShell@2
5456
displayName: Build auth module
@@ -143,11 +145,9 @@ jobs:
143145
[bool]$EnableSigning = if ("$(EnableSigning)" -eq "true") { $true } else { $false }
144146
$Modules = "$(ModulesToGenerate)" -split " "
145147
. $(System.DefaultWorkingDirectory)/tools/GenerateModules.ps1 -Build -Test -UpdateAutoRest -EnableSigning:$EnableSigning -ModulesToGenerate $Modules -ExcludeExampleTemplates -ExcludeNotesSection
146-
147-
- template: ./generate-helpdocs-template.yml
148-
parameters:
149-
DOCSBRANCH: $(DocsBranch)
150-
ModulesToGenerate: $(ModulesToGenerate)
148+
149+
- ${{ if eq(parameters.GenerateCommandMetadata, true) }}:
150+
- template: ./generate-command-metadata-template.yml
151151

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

284+
- ${{ if eq(parameters.GenerateHelpDocs, true) }}:
285+
- template: ./generate-helpdocs-template.yml
286+
parameters:
287+
DOCSBRANCH: $(DocsBranch)
288+
ModulesToGenerate: $(ModulesToGenerate)
289+
284290
- template: ../common-templates/security-postchecks-template.yml

.azure-pipelines/weekly-generation.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ stages:
4040
jobs:
4141
- template: generation-templates/generate-service-modules.yml
4242
parameters:
43-
ModulesToGenerate: $[ stageDependencies.DownloadOpenAPIDocs.GetLatestDocs.outputs['OpenAPIDocDiff.ModulesWithChanges'] ]
4443
Branch: $[ stageDependencies.DownloadOpenAPIDocs.GetLatestDocs.outputs['ComputeBranch.WeeklyBranch'] ]
4544
AuthModulePath: "src/Authentication/Authentication"
4645
ServiceModulePath: "src/"
4746
ModulePrefix: "Microsoft.Graph"
4847
EnableSigning: false
4948
PublishToFeed: false
49+
GenerateCommandMetadata: true
50+
GenerateHelpDocs: true

.github/workflows/create-openapidocs-pr-workflow.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ name: "Create Weekly OpenAPIDocs Download PR"
77
# events but only for the master branch
88
on:
99
push:
10-
branches:
10+
branches:
1111
- 'WeeklyOpenApiDocsDownload/*'
1212

1313
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1414
jobs:
1515
createOpenApiDocsPR:
16-
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]')
16+
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]')
1717
# The type of runner that the job will run on
1818
runs-on: ubuntu-latest
1919
# Steps represent a sequence of tasks that will be executed as part of the job
@@ -22,17 +22,17 @@ jobs:
2222
run: |
2323
git config --global user.email "GraphTooling@service.microsoft.com"
2424
git config --global user.name "Microsoft Graph DevX Tooling"
25-
25+
2626
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
2727
- name: Checkout
2828
uses: actions/checkout@v2
29-
29+
3030
- name: List Directory
31-
run: |
31+
run: |
3232
echo $GITHUB_WORKSPACE
3333
ls -lsa $GITHUB_WORKSPACE
3434
ls -lsa $GITHUB_WORKSPACE/tools
35-
35+
3636
# Create a pull request [1]
3737
- name: Create PR using the GitHub REST API via hub
3838
shell: bash

src/Authentication/Authentication.Core/Common/GraphSession.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Microsoft.Graph.PowerShell.Authentication
88
using Microsoft.Graph.PowerShell.Authentication.Interfaces;
99

1010
using System;
11+
using System.Collections;
1112
using System.Security;
1213
using System.Threading;
1314

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

66+
/// <summary>
67+
/// Represents a collection of Microsoft Graph PowerShell meta-info.
68+
/// </summary>
69+
public Hashtable[] MgCommandMetadata { get; set; }
70+
6571
/// <summary>
6672
/// Gets an instance of <see cref="GraphSession"/>.
6773
/// </summary>

src/Authentication/Authentication/Extensions/PSCmdletExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Microsoft.Graph.PowerShell
1010
using System;
1111
using System.Collections.Generic;
1212
using System.Collections.ObjectModel;
13+
using System.Linq;
1314
using System.Linq.Expressions;
1415
using System.Management.Automation;
1516
public static class PSCmdletExtensions
@@ -119,5 +120,14 @@ internal static GraphSettings GetContextSettings(this PSCmdlet cmdlet)
119120
{
120121
return new GraphSettings(ProtectedFileProvider.CreateFileProvider(Constants.SettingFilePath, FileProtection.SharedRead));
121122
}
123+
124+
internal static IEnumerable<T> RunScript<T>(string script)
125+
=> PowerShell.Create().AddScript(script).Invoke<T>();
126+
127+
internal static IEnumerable<T> RunScript<T>(this PSCmdlet cmdlet, string script)
128+
=> cmdlet?.InvokeCommand.RunScript<T>(script) ?? RunScript<T>(script);
129+
130+
internal static IEnumerable<T> RunScript<T>(this CommandInvocationIntrinsics cii, string script)
131+
=> cii.InvokeScript(script).Select(o => o?.BaseObject).Where(o => o != null).OfType<T>();
122132
}
123133
}

src/Authentication/Authentication/Helpers/StringUtil.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace Microsoft.Graph.PowerShell.Authentication.Helpers
2121
{
22-
internal static class StringUtil
22+
public static class StringUtil
2323
{
2424
/// <summary>
2525
/// Formats the specified string, using the current culture.
@@ -79,7 +79,7 @@ internal static string FormatDictionary(this IDictionary content)
7979
/// <param name="error">An error record if the conversion failed.</param>
8080
/// <returns>A <see cref="System.Management.Automation.PSObject"/> or a <see cref="System.Collections.Hashtable"/>
8181
/// if the <paramref name="returnHashtable"/> parameter is true.</returns>
82-
internal static object ConvertFromJson(this string jsonString, bool returnHashtable, int? maxDepth, out ErrorRecord error)
82+
public static object ConvertFromJson(this string jsonString, bool returnHashtable, int? maxDepth, out ErrorRecord error)
8383
{
8484
if (jsonString == null)
8585
{

src/Authentication/Authentication/Microsoft.Graph.Authentication.format.ps1xml

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Configuration>
33
<ViewDefinitions>
44
<View>
5-
<Name>AuthConfigView</Name>
5+
<Name>Microsoft.Graph.PowerShell.Authentication.Models.AuthConfig</Name>
66
<ViewSelectedBy>
77
<TypeName>Microsoft.Graph.PowerShell.Authentication.Models.AuthConfig</TypeName>
88
</ViewSelectedBy>
@@ -33,6 +33,77 @@
3333
</TableControl>
3434
</View>
3535

36+
<View>
37+
<Name>Microsoft.Graph.PowerShell.Authentication.Models.GraphCommand</Name>
38+
<ViewSelectedBy>
39+
<TypeName>Microsoft.Graph.PowerShell.Authentication.Models.GraphCommand</TypeName>
40+
</ViewSelectedBy>
41+
<GroupBy>
42+
<PropertyName>APIVersion</PropertyName>
43+
<Label>APIVersion</Label>
44+
</GroupBy>
45+
<TableControl>
46+
<TableHeaders>
47+
</TableHeaders>
48+
<TableRowEntries>
49+
<TableRowEntry>
50+
<TableColumnItems>
51+
<TableColumnItem>
52+
<PropertyName>Command</PropertyName>
53+
</TableColumnItem>
54+
<TableColumnItem>
55+
<PropertyName>Module</PropertyName>
56+
</TableColumnItem>
57+
<TableColumnItem>
58+
<PropertyName>Method</PropertyName>
59+
</TableColumnItem>
60+
<TableColumnItem>
61+
<PropertyName>URI</PropertyName>
62+
</TableColumnItem>
63+
<TableColumnItem>
64+
<PropertyName>OutputType</PropertyName>
65+
</TableColumnItem>
66+
<TableColumnItem>
67+
<PropertyName>Permissions</PropertyName>
68+
</TableColumnItem>
69+
<TableColumnItem>
70+
<PropertyName>Variants</PropertyName>
71+
</TableColumnItem>
72+
</TableColumnItems>
73+
</TableRowEntry>
74+
</TableRowEntries>
75+
</TableControl>
76+
</View>
77+
78+
<View>
79+
<Name>Microsoft.Graph.PowerShell.Authentication.Models.GraphPermission</Name>
80+
<ViewSelectedBy>
81+
<TypeName>Microsoft.Graph.PowerShell.Authentication.Models.GraphPermission</TypeName>
82+
</ViewSelectedBy>
83+
<TableControl>
84+
<TableHeaders>
85+
</TableHeaders>
86+
<TableRowEntries>
87+
<TableRowEntry>
88+
<TableColumnItems>
89+
<TableColumnItem>
90+
<PropertyName>Name</PropertyName>
91+
</TableColumnItem>
92+
<TableColumnItem>
93+
<PropertyName>IsAdmin</PropertyName>
94+
</TableColumnItem>
95+
<TableColumnItem>
96+
<PropertyName>Description</PropertyName>
97+
</TableColumnItem>
98+
<TableColumnItem>
99+
<PropertyName>FullDescription</PropertyName>
100+
</TableColumnItem>
101+
</TableColumnItems>
102+
</TableRowEntry>
103+
</TableRowEntries>
104+
</TableControl>
105+
</View>
106+
36107
<View>
37108
<Name>Permission</Name>
38109
<ViewSelectedBy>

0 commit comments

Comments
 (0)