Skip to content
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

Enhanced entra group/app/administrativeunit get/list commands. Closes #6315 #6394

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 10 additions & 3 deletions docs/docs/cmd/entra/administrativeunit/administrativeunit-get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,29 @@ m365 entra administrativeunit get [options]

`-n, --displayName [displayName]`
: The display name of the administrative unit. Specify either `id` or `displayName` but not both.

`-p, --properties [properties]`
: Comma-separated list of properties to retrieve.
```

<Global />

## Remarks

Using the `--properties` option, you can specify a comma-separated list of administrative unit properties to retrieve from the Microsoft Graph. If you don't specify any properties, the command will output the default properties returned by Graph.

## Examples

Get information about the administrative unit by its id
Get information about the administrative unit by its id.

```sh
m365 entra administrativeunit get --id 03c4c9dc-6f0c-4c4f-a4e6-0c9ed80f54c7
```

Get information about the administrative unit by its display name
Get information about the administrative unit by its display name with specified properties.

```sh
m365 entra administrativeunit get --displayName 'Marketing Division'
m365 entra administrativeunit get --displayName "Marketing Division" --properties "id,displayName"
```

## Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,31 @@ m365 entra administrativeunit list [options]

## Options

```md definition-list
`-p, --properties [properties]`
: Comma-separated list of properties to retrieve.
```

<Global />

## Remarks

Using the `--properties` option, you can specify a comma-separated list of administrative unit properties to retrieve from the Microsoft Graph. If you don't specify any properties, the command will output the default properties returned by Graph.

## Examples

Retrieve a list of administrative units
Retrieve a list of administrative units.

```sh
m365 entra administrativeunit list
```

Retrieve a list of administrative units with specified properties.

```sh
m365 entra administrativeunit list --properties "id,displayName"
```

## Response

<Tabs>
Expand Down
21 changes: 13 additions & 8 deletions docs/docs/cmd/entra/app/app-get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ m365 entra appregistration get [options]

```md definition-list
`--appId [appId]`
: Application (client) ID of the Entra application registration to get. Specify either `appId`, `objectId` or `name`
: Application (client) ID of the Entra application registration to get. Specify either `appId`, `objectId` or `name`.

`--objectId [objectId]`
: Object ID of the Entra application registration to get. Specify either `appId`, `objectId` or `name`
: Object ID of the Entra application registration to get. Specify either `appId`, `objectId` or `name`.

`--name [name]`
: Name of the Entra application registration to get. Specify either `appId`, `objectId` or `name`
: Name of the Entra application registration to get. Specify either `appId`, `objectId` or `name`.

`--save`
: Use to store the information about the created app in a local file
: Use to store the information about the created app in a local file.

`-p, --properties [properties]`
: Comma-separated list of properties to retrieve.
```

<Global />
Expand All @@ -44,24 +47,26 @@ If the command finds multiple Entra application registrations with the specified

If you want to store the information about the Entra app registration, use the `--save` option. This is useful when you build solutions connected to Microsoft 365 and want to easily manage app registrations used with your solution. When you use the `--save` option, after you get the app registration, the command will write its ID and name to the `.m365rc.json` file in the current directory. If the file already exists, it will add the information about the App registration to it if it's not already present, allowing you to track multiple apps. If the file doesn't exist, the command will create it.

Using the `--properties` option, you can specify a comma-separated list of app properties to retrieve from the Microsoft Graph. If you don't specify any properties, the command will output the default properties returned by Graph.

## Examples

Get the Entra application registration by its app (client) ID
Get the Entra application registration by its app (client) ID.

```sh
m365 entra app get --appId d75be2e1-0204-4f95-857d-51a37cf40be8
```

Get the Entra application registration by its object ID
Get the Entra application registration by its object ID.

```sh
m365 entra app get --objectId d75be2e1-0204-4f95-857d-51a37cf40be8
```

Get the Entra application registration by its name
Get the Entra application registration by its name with specified properties.

```sh
m365 entra app get --name "My app"
m365 entra app get --name "My app" --properties "appId,displayName"
```

Get the Entra application registration by its name. Store information about the retrieved app registration in the _.m365rc.json_ file in the current directory.
Expand Down
17 changes: 16 additions & 1 deletion docs/docs/cmd/entra/app/app-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,31 @@ m365 entra appregistration list [options]

## Options

```md definition-list
`-p, --properties [properties]`
: Comma-separated list of properties to retrieve.
```

<Global />

## Remarks

Using the `--properties` option, you can specify a comma-separated list of app properties to retrieve from the Microsoft Graph. If you don't specify any properties, the command will output the default properties returned by Graph.

## Examples

Retrieve a list of Entra app registrations
Retrieve a list of Entra app registrations.

```sh
m365 entra app list
```

Retrieve a list of Entra app registrations with specified properties.

```sh
m365 entra app list --properties "appId,displayName"
```

## Response

<Tabs>
Expand Down
13 changes: 10 additions & 3 deletions docs/docs/cmd/entra/group/group-get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,29 @@ m365 entra group get [options]

`-n, --displayName [displayName]`
: The display name of the Entra group. Specify either `id` or `displayName` but not both.

`-p, --properties [properties]`
: Comma-separated list of properties to retrieve.
```

<Global />

## Remarks

Using the `--properties` option, you can specify a comma-separated list of group properties to retrieve from the Microsoft Graph. If you don't specify any properties, the command will output the default properties returned by Graph.

## Examples

Get information about an Entra Group by id
Get information about an Entra Group by id.

```sh
m365 entra group get --id 1caf7dcd-7e83-4c3a-94f7-932a1299c844
```

Get information about an Entra Group by its display name
Get information about an Entra Group by its display name with specified properties.

```sh
m365 entra group get --displayName Finance
m365 entra group get --displayName Finance --properties "mail,displayName"
```

## Response
Expand Down
11 changes: 9 additions & 2 deletions docs/docs/cmd/entra/group/group-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ m365 entra group list [options]
```md definition-list
`--type [type]`
: Filter the results to only groups of a given type. Allowed values: `microsoft365`, `security`, `distribution`, `mailEnabledSecurity`. By default, all groups are listed.

`-p, --properties [properties]`
: Comma-separated list of properties to retrieve.
```

<Global />

## Remarks

Using the `--properties` option, you can specify a comma-separated list of group properties to retrieve from the Microsoft Graph. If you don't specify any properties, the command will output the default properties returned by Graph.

## Examples

Lists all groups defined in Entra ID.
Expand All @@ -29,10 +36,10 @@ Lists all groups defined in Entra ID.
m365 entra group list
```

List all security groups defined in Entra ID.
List all security groups defined in Entra ID with specified properties.

```sh
m365 entra group list --type security
m365 entra group list --type security --properties "mail,displayName"
```

## Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ describe(commands.ADMINISTRATIVEUNIT_GET, () => {
assert(loggerLogSpy.calledOnceWithExactly(administrativeUnitsReponse.value[0]));
});

it('retrieves information about the specified administrative unit by id with specified properties', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/directory/administrativeUnits/${validId}?$select=id,displayName,visibility`) {
return administrativeUnitsReponse.value[0];
}

throw 'Invalid request';
});

await command.action(logger, { options: { id: validId, properties: 'id,displayName,visibility' } });
assert(loggerLogSpy.calledOnceWithExactly(administrativeUnitsReponse.value[0]));
});

it('retrieves information about the specified administrative unit by displayName', async () => {
sinon.stub(entraAdministrativeUnit, 'getAdministrativeUnitByDisplayName').resolves(administrativeUnitsReponse.value[0]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface CommandArgs {
export interface Options extends GlobalOptions {
id?: string;
displayName?: string;
properties?: string;
}

class EntraAdministrativeUnitGetCommand extends GraphCommand {
Expand All @@ -39,7 +40,8 @@ class EntraAdministrativeUnitGetCommand extends GraphCommand {
this.telemetry.push((args: CommandArgs) => {
Object.assign(this.telemetryProperties, {
id: typeof args.options.id !== 'undefined',
displayName: typeof args.options.displayName !== 'undefined'
displayName: typeof args.options.displayName !== 'undefined',
properties: typeof args.options.properties !== 'undefined'
});
});
}
Expand All @@ -51,6 +53,9 @@ class EntraAdministrativeUnitGetCommand extends GraphCommand {
},
{
option: '-n, --displayName [displayName]'
},
{
option: '-p, --properties [properties]'
}
);
}
Expand Down Expand Up @@ -80,7 +85,7 @@ class EntraAdministrativeUnitGetCommand extends GraphCommand {

try {
if (args.options.id) {
administrativeUnit = await this.getAdministrativeUnitById(args.options.id);
administrativeUnit = await this.getAdministrativeUnitById(args.options.id, args.options.properties);
}
else {
administrativeUnit = await entraAdministrativeUnit.getAdministrativeUnitByDisplayName(args.options.displayName!);
Expand All @@ -93,9 +98,24 @@ class EntraAdministrativeUnitGetCommand extends GraphCommand {
}
}

async getAdministrativeUnitById(id: string): Promise<AdministrativeUnit> {
async getAdministrativeUnitById(id: string, properties?: string): Promise<AdministrativeUnit> {
const queryParameters: string[] = [];

if (properties) {
const allProperties = properties.split(',');
const selectProperties = allProperties.filter(prop => !prop.includes('/'));

if (selectProperties.length > 0) {
queryParameters.push(`$select=${selectProperties}`);
}
}

const queryString = queryParameters.length > 0
? `?${queryParameters.join('&')}`
: '';

const requestOptions: CliRequestOptions = {
url: `${this.resource}/v1.0/directory/administrativeUnits/${id}`,
url: `${this.resource}/v1.0/directory/administrativeUnits/${id}${queryString}`,
headers: {
accept: 'application/json;odata.metadata=none'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,44 @@ describe(commands.ADMINISTRATIVEUNIT_LIST, () => {
);
});

it(`should get a list of administrative units with specified properties`, async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/directory/administrativeUnits?$select=id,displayName`) {
return {
value: [
{
id: 'fc33aa61-cf0e-46b6-9506-f633347202ab',
displayName: 'European Division'
},
{
id: 'a25b4c5e-e8b7-4f02-a23d-0965b6415098',
displayName: 'Asian Division'
}
]
};
}

throw 'Invalid request';
});

await command.action(logger, {
options: { properties: 'id,displayName' }
});

assert(
loggerLogSpy.calledWith([
{
id: 'fc33aa61-cf0e-46b6-9506-f633347202ab',
displayName: 'European Division'
},
{
id: 'a25b4c5e-e8b7-4f02-a23d-0965b6415098',
displayName: 'Asian Division'
}
])
);
});

it('handles error when retrieving administrative units list failed', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/directory/administrativeUnits`) {
Expand Down
Loading