From 549b9be63b0309097776961e0f6151649bd49c3b Mon Sep 17 00:00:00 2001 From: Markus Tacker Date: Thu, 15 Apr 2021 14:40:27 +0200 Subject: [PATCH] feat(cli): add command to export local settings --- arm/resources.ts | 2 ++ cli/cli.ts | 8 +++++++ cli/commands/functions-settings.ts | 36 ++++++++++++++++++++++++++++++ cli/commands/react-config.ts | 4 +++- 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 cli/commands/functions-settings.ts diff --git a/arm/resources.ts b/arm/resources.ts index ec59cce25..da9780112 100644 --- a/arm/resources.ts +++ b/arm/resources.ts @@ -1,6 +1,8 @@ export const resourceGroupName = (): string => process.env.RESOURCE_GROUP ?? 'nrfassettracker' +export const appName = (): string => process.env.APP_NAME ?? 'nrfassettracker' + /** * Returns the name of the Device Provisioning Service */ diff --git a/cli/cli.ts b/cli/cli.ts index 132e10d9e..037327080 100644 --- a/cli/cli.ts +++ b/cli/cli.ts @@ -12,11 +12,13 @@ import { createCAIntermediateCommand } from './commands/create-ca-intermediate' import { iotDeviceProvisioningServiceName, resourceGroupName, + appName, } from '../arm/resources' import { reactConfigCommand } from './commands/react-config' import { flashCommand } from './commands/flash' import { ioTHubDPSInfo } from './iot/ioTHubDPSInfo' import { creds } from './creds' +import { functionsSettingsCommand } from './commands/functions-settings' const version = JSON.parse( fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8'), @@ -80,6 +82,12 @@ const main = async () => { reactConfigCommand({ websiteClient: getWebsiteClient, resourceGroup, + appName: appName(), + }), + functionsSettingsCommand({ + websiteClient: getWebsiteClient, + resourceGroup, + appName: appName(), }), flashCommand({ certsDir, diff --git a/cli/commands/functions-settings.ts b/cli/commands/functions-settings.ts new file mode 100644 index 000000000..0020df94b --- /dev/null +++ b/cli/commands/functions-settings.ts @@ -0,0 +1,36 @@ +import { CommandDefinition } from './CommandDefinition' +import { WebSiteManagementClient } from '@azure/arm-appservice' + +export const functionsSettingsCommand = ({ + websiteClient, + appName, + resourceGroup, +}: { + websiteClient: () => Promise + appName: string + resourceGroup: string +}): CommandDefinition => ({ + command: 'functions-settings', + action: async () => { + const client = await websiteClient() + const { properties } = await client.webApps.listApplicationSettings( + resourceGroup, + `${appName}API`, + ) + console.log( + JSON.stringify( + { + IsEncrypted: false, + Values: properties, + Host: { + CORS: '*', + CORSCredentials: false, + }, + }, + null, + 2, + ), + ) + }, + help: 'Exports the function app setting for local development.', +}) diff --git a/cli/commands/react-config.ts b/cli/commands/react-config.ts index f16659161..01e68d100 100644 --- a/cli/commands/react-config.ts +++ b/cli/commands/react-config.ts @@ -5,16 +5,18 @@ import { WebSiteManagementClient } from '@azure/arm-appservice' export const reactConfigCommand = ({ websiteClient, + appName, resourceGroup, }: { websiteClient: () => Promise + appName: string resourceGroup: string }): CommandDefinition => ({ command: 'react-config', action: async () => { const [{ hostNames }] = await Promise.all([ websiteClient().then(async (client) => - client.webApps.get(resourceGroup, `${resourceGroup}api`), + client.webApps.get(resourceGroup, `${appName}api`), ), ])