Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
22812b6
build and tests passing
edwardfoyle Jan 31, 2024
07dc8ea
resource path tweaks
edwardfoyle Feb 1, 2024
3cb6446
add changeset
edwardfoyle Feb 1, 2024
5800bdb
update api extract
edwardfoyle Feb 1, 2024
725ad0f
fix exports
edwardfoyle Feb 1, 2024
d7dea9c
use lazy for lambda config
edwardfoyle Feb 1, 2024
fdae2da
rename AuthRole => AuthRoleName
edwardfoyle Feb 1, 2024
aa76491
use inject instead of banner
edwardfoyle Feb 2, 2024
ee5c4e4
fix tests
edwardfoyle Feb 2, 2024
c1ff538
rename symbol
edwardfoyle Feb 2, 2024
4c84065
update api extract
edwardfoyle Feb 2, 2024
2f78155
Merge remote-tracking branch 'origin/main' into storage-auth
edwardfoyle Feb 6, 2024
4fbd13b
update api extract
edwardfoyle Feb 6, 2024
7d55ab3
move policy generation to construct generator
edwardfoyle Feb 6, 2024
d228c6c
cleanup from merge
edwardfoyle Feb 6, 2024
26fa8e7
update api extract
edwardfoyle Feb 6, 2024
c8d08d1
update api extract
edwardfoyle Feb 6, 2024
c0ec180
remove unused
edwardfoyle Feb 6, 2024
2a2351d
small renaming and refactoring
edwardfoyle Feb 6, 2024
15eb93a
move SsmEnvironmentEntriesGenerator to generateContainerEntry props
edwardfoyle Feb 6, 2024
ee32ecd
refactor ssmEnvironmentEntriesGenerator
edwardfoyle Feb 6, 2024
ef99dcf
update api extract
edwardfoyle Feb 6, 2024
34d2195
use storage name in env var name
edwardfoyle Feb 6, 2024
ca49a30
fix api extract
edwardfoyle Feb 6, 2024
28009c0
fix api extract
edwardfoyle Feb 6, 2024
225363d
Merge remote-tracking branch 'origin/main' into storage-auth
edwardfoyle Feb 8, 2024
bc40d66
Merge remote-tracking branch 'origin/main' into storage-auth
edwardfoyle Feb 8, 2024
442e5ba
add e2e test
edwardfoyle Feb 8, 2024
5ac6685
first round of unit tests
edwardfoyle Feb 8, 2024
62e08a9
refactoring for testability
edwardfoyle Feb 8, 2024
bf193e4
add policy generation unit tests
edwardfoyle Feb 9, 2024
3ac9927
function unit tests
edwardfoyle Feb 9, 2024
669ef7d
more unit tests
edwardfoyle Feb 9, 2024
9b082f8
one more test
edwardfoyle Feb 9, 2024
8673171
Merge remote-tracking branch 'origin/main' into storage-auth
edwardfoyle Feb 9, 2024
924fb22
update api extract
edwardfoyle Feb 9, 2024
b76e555
update changeset
edwardfoyle Feb 9, 2024
bad305e
hopefully fix package lock
edwardfoyle Feb 9, 2024
00e3aa9
try again
edwardfoyle Feb 9, 2024
0ff9090
maybe this?
edwardfoyle Feb 9, 2024
719b45c
fix access
edwardfoyle Feb 9, 2024
1f05b73
fix env var
edwardfoyle Feb 9, 2024
db7670e
refactor resource access acceptor to define* layer
edwardfoyle Feb 9, 2024
ff895b7
remove unnecessary types and refactor triggers
edwardfoyle Feb 9, 2024
b2cf063
polyfill fetch for node16 test lambda
edwardfoyle Feb 9, 2024
80f2aaf
fix hotswap
edwardfoyle Feb 9, 2024
ae0451a
some refactoring and adding tests
edwardfoyle Feb 12, 2024
3bceb6b
policy arbiter refactor and more unit tests
edwardfoyle Feb 12, 2024
dfa0d90
Merge remote-tracking branch 'origin/main' into storage-auth
edwardfoyle Feb 12, 2024
0a7f398
update api extract
edwardfoyle Feb 12, 2024
8fa5904
renaming
edwardfoyle Feb 13, 2024
13f1fee
one more rename
edwardfoyle Feb 13, 2024
8903119
Merge remote-tracking branch 'origin/main' into storage-auth
edwardfoyle Feb 13, 2024
76e75b5
Merge remote-tracking branch 'origin/main' into storage-auth
edwardfoyle Feb 13, 2024
1e5d6d8
trying to fix package lock
edwardfoyle Feb 13, 2024
e8a6a23
try this
edwardfoyle Feb 13, 2024
63aa2fd
Merge remote-tracking branch 'origin/main' into storage-auth
edwardfoyle Feb 15, 2024
7bc474e
add test for refactored trigger code
edwardfoyle Feb 15, 2024
af8707d
update api extract
edwardfoyle Feb 15, 2024
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
14 changes: 14 additions & 0 deletions .changeset/smooth-tigers-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@aws-amplify/backend-function': minor
'@aws-amplify/backend-storage': minor
'@aws-amplify/auth-construct-alpha': minor
'@aws-amplify/platform-core': minor
'@aws-amplify/backend-auth': minor
'@aws-amplify/backend-data': minor
'@aws-amplify/plugin-types': minor
'@aws-amplify/backend': minor
'@aws-amplify/backend-cli': minor
---

Introduce initial iteration of access control mechanism between backend resources.
The APIs and functioality are NOT final and are subject to change without notice.
2 changes: 2 additions & 0 deletions .eslint_dictionary.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[
"acceptor",
"acceptors",
"aggregator",
"amazonaws",
"amazoncognito",
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ expected-cdk-out
.changeset/pre.json
concurrent_workspace_script_cache.json
scripts/components/api-changes-validator/test-resources/working-directory
test-projects
/test-projects
testDir
758 changes: 411 additions & 347 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions packages/auth-construct/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

```ts

import { AmplifyFunction } from '@aws-amplify/plugin-types';
import { AuthOutput } from '@aws-amplify/backend-output-schemas';
import { AuthResources } from '@aws-amplify/plugin-types';
import { aws_cognito } from 'aws-cdk-lib';
import { BackendOutputStorageStrategy } from '@aws-amplify/plugin-types';
import { Construct } from 'constructs';
import { IFunction } from 'aws-cdk-lib/aws-lambda';
import { ResourceProvider } from '@aws-amplify/plugin-types';
import { SecretValue } from 'aws-cdk-lib';
import { StandardAttributes } from 'aws-cdk-lib/aws-cognito';
Expand All @@ -22,7 +20,6 @@ export type AmazonProviderProps = Omit<aws_cognito.UserPoolIdentityProviderAmazo
// @public
export class AmplifyAuth extends Construct implements ResourceProvider<AuthResources> {
constructor(scope: Construct, id: string, props?: AuthProps);
addTrigger: (event: TriggerEvent, handler: IFunction | AmplifyFunction) => void;
readonly resources: AuthResources;
}

Expand Down
81 changes: 0 additions & 81 deletions packages/auth-construct/src/construct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { App, SecretValue, Stack } from 'aws-cdk-lib';
import { Match, Template } from 'aws-cdk-lib/assertions';
import assert from 'node:assert';
import {
AmplifyFunction,
BackendOutputEntry,
BackendOutputStorageStrategy,
} from '@aws-amplify/plugin-types';
Expand All @@ -16,7 +15,6 @@ import {
UserPoolClient,
} from 'aws-cdk-lib/aws-cognito';
import { authOutputKey } from '@aws-amplify/backend-output-schemas';
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
import { DEFAULTS } from './defaults.js';

const googleClientId = 'googleClientId';
Expand Down Expand Up @@ -2359,83 +2357,4 @@ void describe('Auth construct', () => {
assert.equal(name.startsWith(expectedPrefix), true);
});
});

void describe('addTrigger', () => {
void it('attaches lambda function to UserPool Lambda config', () => {
const app = new App();
const stack = new Stack(app);
const testFunc = new Function(stack, 'testFunc', {
code: Code.fromInline('test code'),
handler: 'index.handler',
runtime: Runtime.NODEJS_18_X,
});
const authConstruct = new AmplifyAuth(stack, 'testAuth', {
loginWith: { email: true },
});
authConstruct.addTrigger('createAuthChallenge', testFunc);
const template = Template.fromStack(stack);
const lambdas = template.findResources('AWS::Lambda::Function');
if (Object.keys(lambdas).length !== 1) {
assert.fail(
'Expected one and only one lambda function in the template'
);
}
const handlerLogicalId = Object.keys(lambdas)[0];
template.hasResourceProperties('AWS::Cognito::UserPool', {
LambdaConfig: {
CreateAuthChallenge: {
['Fn::GetAtt']: [handlerLogicalId, 'Arn'],
},
},
});
});

void it('attaches AmplifyFunction to UserPool Lambda config', () => {
const app = new App();
const stack = new Stack(app);
const testFunc = new Function(stack, 'testFunc', {
code: Code.fromInline('test code'),
handler: 'index.handler',
runtime: Runtime.NODEJS_18_X,
});
const amplifyFuncStub: AmplifyFunction = {
resources: {
lambda: testFunc,
},
};
const authConstruct = new AmplifyAuth(stack, 'testAuth', {
loginWith: { email: true },
});
authConstruct.addTrigger('createAuthChallenge', amplifyFuncStub);
const template = Template.fromStack(stack);
const lambdas = template.findResources('AWS::Lambda::Function');
if (Object.keys(lambdas).length !== 1) {
assert.fail(
'Expected one and only one lambda function in the template'
);
}
const handlerLogicalId = Object.keys(lambdas)[0];
template.hasResourceProperties('AWS::Cognito::UserPool', {
LambdaConfig: {
CreateAuthChallenge: {
['Fn::GetAtt']: [handlerLogicalId, 'Arn'],
},
},
});
});

void it('stores attribution data in stack', () => {
const app = new App();
const stack = new Stack(app);
new AmplifyAuth(stack, 'testAuth', {
loginWith: { email: true },
});

const template = Template.fromStack(stack);
assert.equal(
JSON.parse(template.toJSON().Description).stackType,
'auth-Cognito'
);
});
});
});
24 changes: 0 additions & 24 deletions packages/auth-construct/src/construct.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Construct } from 'constructs';
import { RemovalPolicy, Stack, aws_cognito as cognito } from 'aws-cdk-lib';
import {
AmplifyFunction,
AuthResources,
BackendOutputStorageStrategy,
ResourceProvider,
Expand All @@ -22,7 +21,6 @@ import {
UserPoolIdentityProviderOidc,
UserPoolIdentityProviderSaml,
UserPoolIdentityProviderSamlMetadataType,
UserPoolOperation,
UserPoolProps,
} from 'aws-cdk-lib/aws-cognito';
import { FederatedPrincipal, Role } from 'aws-cdk-lib/aws-iam';
Expand All @@ -31,10 +29,8 @@ import {
AuthProps,
EmailLoginSettings,
ExternalProviderOptions,
TriggerEvent,
} from './types.js';
import { DEFAULTS } from './defaults.js';
import { IFunction } from 'aws-cdk-lib/aws-lambda';
import {
AttributionMetadataStorage,
StackMetadataBackendOutputStorageStrategy,
Expand Down Expand Up @@ -224,26 +220,6 @@ export class AmplifyAuth
);
}

/**
* Attach a Lambda function trigger handler to the UserPool in this construct
* @param event - The trigger event operation
* @param handler - The function that will handle the event
*/
addTrigger = (
event: TriggerEvent,
handler: IFunction | AmplifyFunction
): void => {
if ('resources' in handler) {
this.userPool.addTrigger(
UserPoolOperation.of(event),
handler.resources.lambda
);
} else {
// handler is an IFunction
this.userPool.addTrigger(UserPoolOperation.of(event), handler);
}
};

/**
* Create Auth/UnAuth Roles
* @returns DefaultRoles
Expand Down
9 changes: 7 additions & 2 deletions packages/backend-auth/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
```ts

import { AmazonProviderProps } from '@aws-amplify/auth-construct-alpha';
import { AmplifyAuth } from '@aws-amplify/auth-construct-alpha';
import { AppleProviderProps } from '@aws-amplify/auth-construct-alpha';
import { AuthProps } from '@aws-amplify/auth-construct-alpha';
import { AuthResources } from '@aws-amplify/plugin-types';
import { AuthRoleName } from '@aws-amplify/plugin-types';
import { BackendSecret } from '@aws-amplify/plugin-types';
import { ConstructFactory } from '@aws-amplify/plugin-types';
import { ExternalProviderOptions } from '@aws-amplify/auth-construct-alpha';
import { FacebookProviderProps } from '@aws-amplify/auth-construct-alpha';
import { FunctionResources } from '@aws-amplify/plugin-types';
import { GoogleProviderProps } from '@aws-amplify/auth-construct-alpha';
import { OidcProviderProps } from '@aws-amplify/auth-construct-alpha';
import { ResourceAccessAcceptorFactory } from '@aws-amplify/plugin-types';
import { ResourceProvider } from '@aws-amplify/plugin-types';
import { TriggerEvent } from '@aws-amplify/auth-construct-alpha';

Expand Down Expand Up @@ -43,8 +45,11 @@ export type AuthLoginWithFactoryProps = Omit<AuthProps['loginWith'], 'externalPr
externalProviders?: ExternalProviderSpecificFactoryProps;
};

// @public (undocumented)
export type BackendAuth = ResourceProvider<AuthResources> & ResourceAccessAcceptorFactory<AuthRoleName>;

// @public
export const defineAuth: (props: AmplifyAuthProps) => ConstructFactory<AmplifyAuth>;
export const defineAuth: (props: AmplifyAuthProps) => ConstructFactory<BackendAuth>;

// @public
export type Expand<T> = T extends infer O ? {
Expand Down
Loading