-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: user consent for telemetry * fix: removing unused vars * fix: lint errors * feat: integrate with usage_data_emitter * fix: update API.md * update comment * fix: refactor and move LocalConfigController to platform-core * fix: add encoding when reading config file * fix: adding additional file verification check * fix: update unit test * fix: export all types to update API.md * fix: update API.md * fix: open file using file descriptor * fix: update fs mocks in unit test * fix: update fs.open mock * fix: mock fs open for unit test
- Loading branch information
Showing
22 changed files
with
594 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'create-amplify': patch | ||
--- | ||
|
||
Adding message about usage data tracking when creating new project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@aws-amplify/backend-cli': patch | ||
--- | ||
|
||
Added subcommands under configure data tracking preferences |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@aws-amplify/platform-core': patch | ||
'@aws-amplify/backend-cli': patch | ||
--- | ||
|
||
integrate usage data tracking consent with usage-data-emitter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ | |
"localhost", | ||
"lsof", | ||
"lstat", | ||
"macos", | ||
"matchers", | ||
"mfas", | ||
"mkdtemp", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/cli/src/commands/configure/telemetry/configure_telemetry_command.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Printer } from '@aws-amplify/cli-core'; | ||
import { beforeEach, describe, it, mock } from 'node:test'; | ||
import yargs, { CommandModule } from 'yargs'; | ||
import assert from 'node:assert'; | ||
import { TestCommandRunner } from '../../../test-utils/command_runner.js'; | ||
import { ConfigureTelemetryCommand } from './configure_telemetry_command.js'; | ||
import { | ||
USAGE_DATA_TRACKING_ENABLED, | ||
configControllerFactory, | ||
} from '@aws-amplify/platform-core'; | ||
|
||
void describe('configure command', () => { | ||
const mockedConfigControllerSet = mock.fn(); | ||
mock.method(configControllerFactory, 'getInstance', () => ({ | ||
set: mockedConfigControllerSet, | ||
})); | ||
const telemetryCommand = new ConfigureTelemetryCommand( | ||
configControllerFactory.getInstance('usage_data_preferences.json') | ||
); | ||
const parser = yargs().command(telemetryCommand as unknown as CommandModule); | ||
const commandRunner = new TestCommandRunner(parser); | ||
|
||
const mockedPrint = mock.method(Printer, 'print'); | ||
|
||
beforeEach(() => { | ||
mockedPrint.mock.resetCalls(); | ||
mockedConfigControllerSet.mock.resetCalls(); | ||
}); | ||
|
||
void it('enable telemetry & updates local config', async () => { | ||
await commandRunner.runCommand(`telemetry enable`); | ||
assert.match( | ||
mockedPrint.mock.calls[0].arguments[0], | ||
/You have enabled telemetry data collection/ | ||
); | ||
assert.strictEqual( | ||
mockedConfigControllerSet.mock.calls[0].arguments[0], | ||
USAGE_DATA_TRACKING_ENABLED | ||
); | ||
assert.strictEqual( | ||
mockedConfigControllerSet.mock.calls[0].arguments[1], | ||
true | ||
); | ||
}); | ||
|
||
void it('disables telemetry & updates local config', async () => { | ||
await commandRunner.runCommand(`telemetry disable`); | ||
assert.match( | ||
mockedPrint.mock.calls[0].arguments[0], | ||
/You have disabled telemetry data collection/ | ||
); | ||
assert.strictEqual( | ||
mockedConfigControllerSet.mock.calls[0].arguments[0], | ||
USAGE_DATA_TRACKING_ENABLED | ||
); | ||
assert.strictEqual( | ||
mockedConfigControllerSet.mock.calls[0].arguments[1], | ||
false | ||
); | ||
}); | ||
|
||
void it('if subcommand is not defined, it should list of subcommands and demandCommand', async () => { | ||
await commandRunner.runCommand(`telemetry`); | ||
assert.match( | ||
mockedPrint.mock.calls[0].arguments[0], | ||
/Not enough non-option arguments: got 0, need at least 1/ | ||
); | ||
assert.strictEqual(mockedConfigControllerSet.mock.callCount(), 0); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
packages/cli/src/commands/configure/telemetry/configure_telemetry_command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Printer } from '@aws-amplify/cli-core'; | ||
import { | ||
ConfigurationController, | ||
USAGE_DATA_TRACKING_ENABLED, | ||
} from '@aws-amplify/platform-core'; | ||
import { Argv, CommandModule } from 'yargs'; | ||
import { handleCommandFailure } from '../../../command_failure_handler.js'; | ||
/** | ||
* Command to configure AWS Amplify profile. | ||
*/ | ||
export class ConfigureTelemetryCommand implements CommandModule<object> { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
readonly command: string; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
readonly describe: string; | ||
|
||
/** | ||
* Configure profile command. | ||
*/ | ||
constructor(private readonly configController: ConfigurationController) { | ||
this.command = 'telemetry'; | ||
this.describe = 'Configure anonymous usage data collection'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
handler = () => { | ||
// CommandModule requires handler implementation. But this is never called if top level command | ||
// is configured to require subcommand. | ||
// Help is printed by default in that case before ever attempting to call handler. | ||
throw new Error('Top level generate handler should never be called'); | ||
}; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
builder = (yargs: Argv) => { | ||
return yargs | ||
.command('enable', 'Enable anonymous data collection', {}, async () => { | ||
await this.configController.set(USAGE_DATA_TRACKING_ENABLED, true); | ||
|
||
Printer.print('You have enabled telemetry data collection'); | ||
}) | ||
.command('disable', 'Disable anonymous data collection', {}, async () => { | ||
await this.configController.set(USAGE_DATA_TRACKING_ENABLED, false); | ||
|
||
Printer.print('You have disabled telemetry data collection'); | ||
}) | ||
.demandCommand() | ||
.strictCommands() | ||
.recommendCommands() | ||
.fail((msg, err) => { | ||
handleCommandFailure(msg, err, yargs); | ||
yargs.exit(1, err); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.