Skip to content

Commit

Permalink
Merge branch 'main' into multi-bucket-support
Browse files Browse the repository at this point in the history
  • Loading branch information
0618 committed Jul 16, 2024
2 parents 4b1a471 + 8f23287 commit 421fd59
Show file tree
Hide file tree
Showing 40 changed files with 9,399 additions and 6,212 deletions.
8 changes: 8 additions & 0 deletions .changeset/cool-coins-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@aws-amplify/cli-core': minor
'@aws-amplify/sandbox': minor
'@aws-amplify/backend-cli': minor
'create-amplify': patch
---

feat: add support for function logs streaming to sandbox
2 changes: 0 additions & 2 deletions .changeset/real-ghosts-dance.md

This file was deleted.

13,717 changes: 7,622 additions & 6,095 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions packages/auth-construct/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @aws-amplify/auth-construct

## 1.1.6

### Patch Changes

- 157175a: Fix a case where domain is not included in outputs if name property is specified

## 1.1.5

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-construct/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-amplify/auth-construct",
"version": "1.1.5",
"version": "1.1.6",
"type": "commonjs",
"publishConfig": {
"access": "public"
Expand Down
48 changes: 48 additions & 0 deletions packages/auth-construct/src/construct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,54 @@ void describe('Auth construct', () => {
'http://logout.com'
);
});

void it('updates oauth domain when name is present', () => {
new AmplifyAuth(stack, 'test', {
name: 'test_name',
loginWith: {
email: true,
externalProviders: {
google: {
clientId: googleClientId,
clientSecret: SecretValue.unsafePlainText(googleClientSecret),
},
domainPrefix: 'test-prefix',
scopes: ['EMAIL', 'PROFILE'],
callbackUrls: ['http://callback.com'],
logoutUrls: ['http://logout.com'],
},
},
});
const template = Template.fromStack(stack);
const outputs = template.findOutputs('*');
const userPoolDomains = template.findResources(
'AWS::Cognito::UserPoolDomain',
{
Properties: {
Domain: 'test-prefix',
},
}
);
let userPoolDomainRefValue = '';
for (const [key] of Object.entries(userPoolDomains)) {
userPoolDomainRefValue = key;
}
assert.deepEqual(outputs['oauthCognitoDomain']['Value'], {
'Fn::Join': [
'',
[
{
Ref: userPoolDomainRefValue,
},
'.auth.',
{
Ref: 'AWS::Region',
},
'.amazoncognito.com',
],
],
});
});
});

void describe('storeOutput strategy', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/auth-construct/src/construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,9 @@ export class AmplifyAuth

output.oauthCognitoDomain = Lazy.string({
produce: () => {
const userPoolDomain =
this.resources.userPool.node.tryFindChild('UserPoolDomain');
const userPoolDomain = this.resources.userPool.node.tryFindChild(
`${this.name}UserPoolDomain`
);
if (!userPoolDomain) {
return '';
}
Expand Down
11 changes: 10 additions & 1 deletion packages/cli-core/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/// <reference types="node" />

import { PackageManagerController } from '@aws-amplify/plugin-types';
import { WriteStream } from 'node:tty';

// @public
export class AmplifyPrompter {
Expand All @@ -21,12 +22,20 @@ export class AmplifyPrompter {
}) => Promise<boolean>;
}

// @public (undocumented)
export type ColorName = (typeof colorNames)[number];

// @public (undocumented)
export const colorNames: readonly ["Green", "Yellow", "Blue", "Magenta", "Cyan"];

// @public
export class Format {
constructor(packageManagerRunnerName?: string);
// (undocumented)
bold: (message: string) => string;
// (undocumented)
color: (message: string, colorName: ColorName) => string;
// (undocumented)
command: (command: string) => string;
// (undocumented)
dim: (message: string) => string;
Expand Down Expand Up @@ -73,7 +82,7 @@ export class PackageManagerControllerFactory {

// @public
export class Printer {
constructor(minimumLogLevel: LogLevel, stdout?: NodeJS.WriteStream, stderr?: NodeJS.WriteStream, refreshRate?: number);
constructor(minimumLogLevel: LogLevel, stdout?: WriteStream | NodeJS.WritableStream, stderr?: WriteStream | NodeJS.WritableStream, refreshRate?: number);
indicateProgress(message: string, callback: () => Promise<void>): Promise<void>;
log(message: string, level?: LogLevel): void;
print: (message: string) => void;
Expand Down
16 changes: 15 additions & 1 deletion packages/cli-core/src/format/format.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import * as os from 'node:os';
import * as assert from 'node:assert';
import { after, before, describe, it } from 'node:test';
import { after, before, beforeEach, describe, it } from 'node:test';
import { Format, format } from './format.js';
import { $, blue, bold, cyan, green, red, underline } from 'kleur/colors';

void describe('format', () => {
beforeEach(() => {
$.enabled = true;
});

void it('should format ampx command with yarn', { concurrency: 1 }, () => {
const formatter = new Format('yarn');
assert.strictEqual(
Expand Down Expand Up @@ -157,3 +161,13 @@ void describe('format when terminal colors disabled', async () => {
assert.strictEqual(coloredMessage, 'npx ampx hello');
});
});

void describe('format.color', async () => {
void it('should format colors as requested', () => {
const input = 'something to color';
const expectedOutput = green(input);
const actualOutput = format.color(input, 'Green');
assert.strictEqual(actualOutput, expectedOutput);
assert.notStrictEqual(actualOutput, red(input)); // confirm that coloring actually works
});
});
23 changes: 23 additions & 0 deletions packages/cli-core/src/format/format.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import * as os from 'node:os';
import {
Colorize,
blue,
bold,
cyan,
dim,
green,
grey,
magenta,
red,
underline,
yellow,
} from 'kleur/colors';
import { AmplifyFault } from '@aws-amplify/platform-core';
import { getPackageManagerRunnerName } from '../package-manager-controller/get_package_manager_name.js';
Expand Down Expand Up @@ -71,6 +74,26 @@ export class Format {
Object.entries(record)
.map(([key, value]) => `${key}: ${String(value)}`)
.join(os.EOL);
color = (message: string, colorName: ColorName) => colors[colorName](message);
}

// Map to connect colorName to kleur color
const colors: Record<ColorName, Colorize> = {
Green: green,
Yellow: yellow,
Blue: blue,
Magenta: magenta,
Cyan: cyan,
};

export const colorNames = [
'Green',
'Yellow',
'Blue',
'Magenta',
'Cyan',
] as const;

export type ColorName = (typeof colorNames)[number];

export const format = new Format();
2 changes: 1 addition & 1 deletion packages/cli-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './prompter/amplify_prompts.js';
export * from './printer/printer.js';
export * from './printer.js';
export { format, Format } from './format/format.js';
export { ColorName, colorNames, format, Format } from './format/format.js';
export * from './package-manager-controller/package_manager_controller_factory.js';
12 changes: 8 additions & 4 deletions packages/cli-core/src/printer/printer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WriteStream } from 'node:tty';
import { EOL } from 'os';

export type RecordValue = string | number | string[] | Date;

/**
Expand All @@ -19,8 +19,12 @@ export class Printer {
*/
constructor(
private readonly minimumLogLevel: LogLevel,
private readonly stdout: NodeJS.WriteStream = process.stdout,
private readonly stderr: NodeJS.WriteStream = process.stderr,
private readonly stdout:
| WriteStream
| NodeJS.WritableStream = process.stdout,
private readonly stderr:
| WriteStream
| NodeJS.WritableStream = process.stderr,
private readonly refreshRate: number = 500
) {}

Expand Down Expand Up @@ -91,7 +95,7 @@ export class Printer {
* Checks if the environment is TTY
*/
private isTTY() {
return this.stdout.isTTY;
return this.stdout instanceof WriteStream && this.stdout.isTTY;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @aws-amplify/backend-cli

## 1.1.1

### Patch Changes

- 44ca7d7: refactor top level cli error handling
- Updated dependencies [44ca7d7]
- Updated dependencies [ca92f23]
- @aws-amplify/platform-core@1.0.2
- @aws-amplify/sandbox@1.0.6

## 1.1.0

### Minor Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-amplify/backend-cli",
"version": "1.1.0",
"version": "1.1.1",
"description": "Command line interface for various Amplify tools",
"bin": {
"ampx": "lib/ampx.js",
Expand Down Expand Up @@ -38,8 +38,8 @@
"@aws-amplify/deployed-backend-client": "^1.0.1",
"@aws-amplify/form-generator": "^1.0.0",
"@aws-amplify/model-generator": "^1.0.1",
"@aws-amplify/platform-core": "^1.0.1",
"@aws-amplify/sandbox": "^1.0.5",
"@aws-amplify/platform-core": "^1.0.2",
"@aws-amplify/sandbox": "^1.0.6",
"@aws-amplify/schema-generator": "^1.1.0",
"@aws-sdk/client-amplify": "^3.465.0",
"@aws-sdk/client-cloudformation": "^3.465.0",
Expand Down
21 changes: 10 additions & 11 deletions packages/cli/src/ampx.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#!/usr/bin/env node
import { createMainParser } from './main_parser_factory.js';
import { attachUnhandledExceptionListeners } from './error_handler.js';
import {
attachUnhandledExceptionListeners,
generateCommandFailureHandler,
} from './error_handler.js';
import { extractSubCommands } from './extract_sub_commands.js';
import {
AmplifyFault,
PackageJsonReader,
UsageDataEmitterFactory,
} from '@aws-amplify/platform-core';
import { fileURLToPath } from 'node:url';
import { LogLevel, format, printer } from '@aws-amplify/cli-core';
import { verifyCommandName } from './verify_command_name.js';
import { parseAsyncSafely } from './parse_async_safely.js';
import { hideBin } from 'yargs/helpers';
import { format } from '@aws-amplify/cli-core';

const packageJson = new PackageJsonReader().read(
fileURLToPath(new URL('../package.json', import.meta.url))
Expand All @@ -32,11 +35,11 @@ attachUnhandledExceptionListeners(usageDataEmitter);

verifyCommandName();

const parser = createMainParser(libraryVersion, usageDataEmitter);

await parseAsyncSafely(parser);
const parser = createMainParser(libraryVersion);
const errorHandler = generateCommandFailureHandler(parser, usageDataEmitter);

try {
await parser.parseAsync(hideBin(process.argv));
const metricDimension: Record<string, string> = {};
const subCommands = extractSubCommands(parser);

Expand All @@ -47,10 +50,6 @@ try {
await usageDataEmitter.emitSuccess({}, metricDimension);
} catch (e) {
if (e instanceof Error) {
printer.log(format.error('Failed to emit usage metrics'), LogLevel.DEBUG);
printer.log(format.error(e), LogLevel.DEBUG);
if (e.stack) {
printer.log(e.stack, LogLevel.DEBUG);
}
await errorHandler(format.error(e), e);
}
}
37 changes: 35 additions & 2 deletions packages/cli/src/commands/sandbox/sandbox_command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { AmplifyPrompter, format, printer } from '@aws-amplify/cli-core';
import { EventHandler, SandboxCommand } from './sandbox_command.js';
import { createSandboxCommand } from './sandbox_command_factory.js';
import { SandboxDeleteCommand } from './sandbox-delete/sandbox_delete_command.js';
import { Sandbox, SandboxSingletonFactory } from '@aws-amplify/sandbox';
import {
Sandbox,
SandboxFunctionStreamingOptions,
SandboxSingletonFactory,
} from '@aws-amplify/sandbox';
import { createSandboxSecretCommand } from './sandbox-secret/sandbox_secret_command_factory.js';
import { ClientConfigGeneratorAdapter } from '../../client-config/client_config_generator_adapter.js';
import { CommandMiddleware } from '../../command_middleware.js';
Expand Down Expand Up @@ -118,6 +122,9 @@ void describe('sandbox command', () => {
assert.match(output, /--outputs-format/);
assert.match(output, /--outputs-out-dir/);
assert.match(output, /--once/);
assert.match(output, /--stream-function-logs/);
assert.match(output, /--logs-filter/);
assert.match(output, /--logs-out-file/);
assert.equal(mockHandleProfile.mock.callCount(), 0);
});

Expand Down Expand Up @@ -341,7 +348,7 @@ void describe('sandbox command', () => {
);
});

void it('--once flag is mutually exclusive with dir-to-watch & exclude', async () => {
void it('--once flag is mutually exclusive with dir-to-watch, exclude and stream-function-logs', async () => {
assert.match(
await commandRunner.runCommand(
'sandbox --once --dir-to-watch nonExistentDir'
Expand All @@ -352,5 +359,31 @@ void describe('sandbox command', () => {
await commandRunner.runCommand('sandbox --once --exclude test'),
/Arguments once and exclude are mutually exclusive/
);
assert.match(
await commandRunner.runCommand('sandbox --once --stream-function-logs'),
/Arguments once and stream-function-logs are mutually exclusive/
);
});

void it('fails if --logs-out-file is provided without enabling --stream-function-logs', async () => {
assert.match(
await commandRunner.runCommand('sandbox --logs-out-file someFile'),
/Missing dependent arguments:\n logs-out-file -> stream-function-logs/
);
});

void it('starts sandbox with log watching options', async () => {
await commandRunner.runCommand(
'sandbox --stream-function-logs --logs-filter func1 --logs-filter func2 --logs-out-file someFile'
);
assert.equal(sandboxStartMock.mock.callCount(), 1);
assert.deepStrictEqual(
sandboxStartMock.mock.calls[0].arguments[0].functionStreamingOptions,
{
enabled: true,
logsFilters: ['func1', 'func2'],
logsOutFile: 'someFile',
} as SandboxFunctionStreamingOptions
);
});
});
Loading

0 comments on commit 421fd59

Please sign in to comment.