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

Enhance flow run list, flow environment get and flow environment list output #5349

Closed
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions docs/docs/cmd/flow/run/run-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ m365 flow run list --environmentName Default-d87a7535-dd31-4437-bfe1-95340acd55c
},
"status": "Succeeded"
}
},
"startTime": "2022-11-17T14:33:45.2763872Z",
"status": "Running"
}
}
]
```
Expand Down
16 changes: 16 additions & 0 deletions docs/docs/v7-upgrade-guidance.mdx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged your two sections into one.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ In version 6 of the CLI for Microsoft 365, for setting the list commandset, you

Since the option `id` was mandatory in V6 and if your scripts are dependent on the default mandatory error output which the command would return, you may have to update your scripts accordingly.

## Enhanced `flow run list` and `flow environment list` output

In version 7 of the CLI for Microsoft 365, we have made an enhancement for the data returned by the `flow run list` and `flow environment list` commands. Currently, when no items were found, we would only log an output when `--verbose` was specified. This made this command very unpredictable to use in scripts. This has now been changed so an empty array will be logged when no items were found. Also, when specifying `--output json`, we would have duplicate properties in the result. These properties have been removed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of currently we should use previously because we are talking about the previous version.


### What action do I need to take?

Make sure that your scripts will now expect an empty array instead of nothing when no results are found and if using `--output json`, make sure that the removed properties are remapped to the correct properties.

## Enhanced `flow environment get` output

In version 7 of the CLI for Microsoft 365, we have made an enhancement for the data returned by the `flow environment get` command. Currently, when specifying `--output json`, we would have duplicate properties on the results object. Those have been removed from the result.

### What action do I need to take?

Make sure that the removed properties are remapped to the correct properties when using `--output json`.

## Aligned options with naming convention

In version 7 of the CLI for Microsoft 365, we have made updates to the options for certain commands, aligning with our naming convention. This includes renaming options to ensure consistency and improve the CLI experience. For example, the option `--environment` for the command `m365 pa app consent set` has been changed to `--environmentName`. These changes aim to make it easier for you to use the CLI.
Expand Down
58 changes: 44 additions & 14 deletions src/m365/flow/commands/environment/environment-get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ describe(commands.ENVIRONMENT_GET, () => {
let logger: Logger;
let loggerLogSpy: sinon.SinonSpy;
const flowResponse: FlowEnvironmentDetails = {
name: "Default-d87a7535-dd31-4437-bfe1-95340acd55c5",
location: "europe",
type: "Microsoft.ProcessSimple/environments",
id: "/providers/Microsoft.ProcessSimple/environments/Default-d87a7535-dd31-4437-bfe1-95340acd55c5",
properties: {
displayName: "Contoso (default)",
createdTime: "2018-03-22T20:20:46.08653Z",
createdBy: {
id: "SYSTEM",
displayName: "SYSTEM",
type: "NotSpecified"
},
provisioningState: "Succeeded",
creationType: "DefaultTenant",
environmentSku: "Default",
environmentType: "Production",
isDefault: true,
azureRegionHint: "westeurope",
runtimeEndpoints: {
"microsoft.BusinessAppPlatform": "https://europe.api.bap.microsoft.com",
"microsoft.CommonDataModel": "https://europe.api.cds.microsoft.com",
"microsoft.PowerApps": "https://europe.api.powerapps.com",
"microsoft.Flow": "https://europe.api.flow.microsoft.com"
}
}
};

const flowResponseText: FlowEnvironmentDetails = {
displayName: "Contoso (default)",
provisioningState: "Succeeded",
environmentSku: "Default",
Expand Down Expand Up @@ -105,7 +133,7 @@ describe(commands.ENVIRONMENT_GET, () => {
throw 'Invalid request';
});

await command.action(logger, { options: { debug: true, name: 'Default-d87a7535-dd31-4437-bfe1-95340acd55c5' } });
await command.action(logger, { options: { output: 'json', debug: true, name: 'Default-d87a7535-dd31-4437-bfe1-95340acd55c5' } });
assert(loggerLogSpy.calledWith(flowResponse));
});

Expand All @@ -118,10 +146,23 @@ describe(commands.ENVIRONMENT_GET, () => {
throw 'Invalid request';
});

await command.action(logger, { options: { name: 'Default-d87a7535-dd31-4437-bfe1-95340acd55c5' } });
await command.action(logger, { options: { output: 'json', name: 'Default-d87a7535-dd31-4437-bfe1-95340acd55c5' } });
assert(loggerLogSpy.calledWith(flowResponse));
});

it('retrieves information about the specified environment with output text', async () => {
sinon.stub(request, 'get').callsFake(async opts => {
if ((opts.url === `https://management.azure.com/providers/Microsoft.ProcessSimple/environments/Default-d87a7535-dd31-4437-bfe1-95340acd55c5?api-version=2016-11-01`)) {
return flowResponse;
}

throw 'Invalid request';
});

await command.action(logger, { options: { output: 'text', name: 'Default-d87a7535-dd31-4437-bfe1-95340acd55c5' } });
assert(loggerLogSpy.calledWith(flowResponseText));
});

it('retrieves information about the default environment', async () => {
sinon.stub(request, 'get').callsFake(async opts => {
if ((opts.url === `https://management.azure.com/providers/Microsoft.ProcessSimple/environments/~default?api-version=2016-11-01`)) {
Expand All @@ -131,7 +172,7 @@ describe(commands.ENVIRONMENT_GET, () => {
throw 'Invalid request';
});

await command.action(logger, { options: { verbose: true } });
await command.action(logger, { options: { output: 'json', verbose: true } });
assert(loggerLogSpy.calledWith(flowResponse));
});

Expand Down Expand Up @@ -162,15 +203,4 @@ describe(commands.ENVIRONMENT_GET, () => {
await assert.rejects(command.action(logger, { options: { name: 'Default-d87a7535-dd31-4437-bfe1-95340acd55c5' } } as any),
new CommandError('An error has occurred'));
});

it('supports specifying name', () => {
const options = command.options;
let containsOption = false;
options.forEach(o => {
if (o.option.indexOf('--name') > -1) {
containsOption = true;
}
});
assert(containsOption);
});
});
13 changes: 8 additions & 5 deletions src/m365/flow/commands/environment/environment-get.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update the docs as well.

Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ class FlowEnvironmentGetCommand extends AzmgmtCommand {

try {
const flowItem = await request.get<FlowEnvironmentDetails>(requestOptions);
flowItem.displayName = flowItem.properties.displayName;
flowItem.provisioningState = flowItem.properties.provisioningState;
flowItem.environmentSku = flowItem.properties.environmentSku;
flowItem.azureRegionHint = flowItem.properties.azureRegionHint;
flowItem.isDefault = flowItem.properties.isDefault;

if (args.options.output !== 'json') {
flowItem.displayName = flowItem.properties.displayName;
flowItem.provisioningState = flowItem.properties.provisioningState;
flowItem.environmentSku = flowItem.properties.environmentSku;
flowItem.azureRegionHint = flowItem.properties.azureRegionHint;
flowItem.isDefault = flowItem.properties.isDefault;
}

logger.log(flowItem);
}
Expand Down
141 changes: 134 additions & 7 deletions src/m365/flow/commands/environment/environment-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe(commands.ENVIRONMENT_LIST, () => {
throw 'Invalid request';
});

await command.action(logger, { options: { debug: true } });
await command.action(logger, { options: { output: 'json', debug: true } });
assert(loggerLogSpy.calledWith([
{
"name": "Default-d87a7535-dd31-4437-bfe1-95340acd55c5",
Expand All @@ -160,8 +160,7 @@ describe(commands.ENVIRONMENT_LIST, () => {
"microsoft.PowerApps": "https://europe.api.powerapps.com",
"microsoft.Flow": "https://europe.api.flow.microsoft.com"
}
},
"displayName": "Contoso (default)"
}
},
{
"name": "Test-d87a7535-dd31-4437-bfe1-95340acd55c5",
Expand All @@ -188,8 +187,7 @@ describe(commands.ENVIRONMENT_LIST, () => {
"microsoft.PowerApps": "https://europe.api.powerapps.com",
"microsoft.Flow": "https://europe.api.flow.microsoft.com"
}
},
"displayName": "Contoso (test)"
}
}
]));
});
Expand Down Expand Up @@ -264,7 +262,136 @@ describe(commands.ENVIRONMENT_LIST, () => {
throw 'Invalid request';
});

await command.action(logger, { options: {} });
await command.action(logger, { options: { output: 'json' } });
assert(loggerLogSpy.calledWith([
{
"name": "Default-d87a7535-dd31-4437-bfe1-95340acd55c5",
"location": "europe",
"type": "Microsoft.ProcessSimple/environments",
"id": "/providers/Microsoft.ProcessSimple/environments/Default-d87a7535-dd31-4437-bfe1-95340acd55c5",
"properties": {
"displayName": "Contoso (default)",
"createdTime": "2018-03-22T20:20:46.08653Z",
"createdBy": {
"id": "SYSTEM",
"displayName": "SYSTEM",
"type": "NotSpecified"
},
"provisioningState": "Succeeded",
"creationType": "DefaultTenant",
"environmentSku": "Default",
"environmentType": "Production",
"isDefault": true,
"azureRegionHint": "westeurope",
"runtimeEndpoints": {
"microsoft.BusinessAppPlatform": "https://europe.api.bap.microsoft.com",
"microsoft.CommonDataModel": "https://europe.api.cds.microsoft.com",
"microsoft.PowerApps": "https://europe.api.powerapps.com",
"microsoft.Flow": "https://europe.api.flow.microsoft.com"
}
}
},
{
"name": "Test-d87a7535-dd31-4437-bfe1-95340acd55c5",
"location": "europe",
"type": "Microsoft.ProcessSimple/environments",
"id": "/providers/Microsoft.ProcessSimple/environments/Test-d87a7535-dd31-4437-bfe1-95340acd55c5",
"properties": {
"displayName": "Contoso (test)",
"createdTime": "2018-03-22T20:20:46.08653Z",
"createdBy": {
"id": "SYSTEM",
"displayName": "SYSTEM",
"type": "NotSpecified"
},
"provisioningState": "Succeeded",
"creationType": "DefaultTenant",
"environmentSku": "Default",
"environmentType": "Production",
"isDefault": false,
"azureRegionHint": "westeurope",
"runtimeEndpoints": {
"microsoft.BusinessAppPlatform": "https://europe.api.bap.microsoft.com",
"microsoft.CommonDataModel": "https://europe.api.cds.microsoft.com",
"microsoft.PowerApps": "https://europe.api.powerapps.com",
"microsoft.Flow": "https://europe.api.flow.microsoft.com"
}
}
}
]));
});

it('retrieves Microsoft Flow environments with output text', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if ((opts.url as string).indexOf(`/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01`) > -1) {
if (opts.headers &&
opts.headers.accept &&
(opts.headers.accept as string).indexOf('application/json') === 0) {
return {
value: [
{
"name": "Default-d87a7535-dd31-4437-bfe1-95340acd55c5",
"location": "europe",
"type": "Microsoft.ProcessSimple/environments",
"id": "/providers/Microsoft.ProcessSimple/environments/Default-d87a7535-dd31-4437-bfe1-95340acd55c5",
"properties": {
"displayName": "Contoso (default)",
"createdTime": "2018-03-22T20:20:46.08653Z",
"createdBy": {
"id": "SYSTEM",
"displayName": "SYSTEM",
"type": "NotSpecified"
},
"provisioningState": "Succeeded",
"creationType": "DefaultTenant",
"environmentSku": "Default",
"environmentType": "Production",
"isDefault": true,
"azureRegionHint": "westeurope",
"runtimeEndpoints": {
"microsoft.BusinessAppPlatform": "https://europe.api.bap.microsoft.com",
"microsoft.CommonDataModel": "https://europe.api.cds.microsoft.com",
"microsoft.PowerApps": "https://europe.api.powerapps.com",
"microsoft.Flow": "https://europe.api.flow.microsoft.com"
}
}
},
{
"name": "Test-d87a7535-dd31-4437-bfe1-95340acd55c5",
"location": "europe",
"type": "Microsoft.ProcessSimple/environments",
"id": "/providers/Microsoft.ProcessSimple/environments/Test-d87a7535-dd31-4437-bfe1-95340acd55c5",
"properties": {
"displayName": "Contoso (test)",
"createdTime": "2018-03-22T20:20:46.08653Z",
"createdBy": {
"id": "SYSTEM",
"displayName": "SYSTEM",
"type": "NotSpecified"
},
"provisioningState": "Succeeded",
"creationType": "DefaultTenant",
"environmentSku": "Default",
"environmentType": "Production",
"isDefault": false,
"azureRegionHint": "westeurope",
"runtimeEndpoints": {
"microsoft.BusinessAppPlatform": "https://europe.api.bap.microsoft.com",
"microsoft.CommonDataModel": "https://europe.api.cds.microsoft.com",
"microsoft.PowerApps": "https://europe.api.powerapps.com",
"microsoft.Flow": "https://europe.api.flow.microsoft.com"
}
}
}
]
};
}
}

throw 'Invalid request';
});

await command.action(logger, { options: { output: 'text' } });
assert(loggerLogSpy.calledWith([
{
"name": "Default-d87a7535-dd31-4437-bfe1-95340acd55c5",
Expand Down Expand Up @@ -339,7 +466,7 @@ describe(commands.ENVIRONMENT_LIST, () => {
});

await command.action(logger, { options: {} });
assert(loggerLogSpy.notCalled);
assert(loggerLogSpy.calledWith([]));
});

it('correctly handles API OData error', async () => {
Expand Down
9 changes: 5 additions & 4 deletions src/m365/flow/commands/environment/environment-list.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update the docs as well.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CommandArgs } from '../../../../Command';
import { Logger } from '../../../../cli/Logger';
import request, { CliRequestOptions } from '../../../../request';
import AzmgmtCommand from '../../../base/AzmgmtCommand';
Expand All @@ -16,7 +17,7 @@ class FlowEnvironmentListCommand extends AzmgmtCommand {
return ['name', 'displayName'];
}

public async commandAction(logger: Logger): Promise<void> {
public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
if (this.verbose) {
logger.logToStderr(`Retrieving list of Microsoft Flow environments...`);
}
Expand All @@ -32,13 +33,13 @@ class FlowEnvironmentListCommand extends AzmgmtCommand {
try {
const res = await request.get<{ value: [{ name: string, displayName: string; properties: { displayName: string } }] }>(requestOptions);

if (res.value && res.value.length > 0) {
if (args.options.output !== 'json' && res.value.length > 0) {
res.value.forEach(e => {
e.displayName = e.properties.displayName;
});

logger.log(res.value);
}

logger.log(res.value);
}
catch (err: any) {
this.handleRejectedODataJsonPromise(err);
Expand Down