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

feat: storage category codegen #13928

Merged
merged 28 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5f1dd79
fix: resolve incorrect mfaconifg option
Sep 3, 2024
3e9d197
Merge remote-tracking branch 'upstream/migrations' into migrations
Sep 4, 2024
4f4d9fd
fix: add attribute mapping for external providers
Sep 5, 2024
e0a33e3
fix: yarn extract-api changes
Sep 5, 2024
ca3de21
fix: remove unused vars
Sep 5, 2024
9e45af9
feat: storage codegen
Sep 13, 2024
dade8f2
feat: storage codegen
Sep 13, 2024
a61100e
feat: storage codegen
Sep 13, 2024
83da5fe
feat: storage codegen
Sep 13, 2024
6ccb0ef
feat: storage codegen
Sep 13, 2024
43c5e3f
feat: storage codegen
Sep 13, 2024
da810f0
feat: storage codegen
Sep 13, 2024
96f12ca
refactor: modified addPropertyOverride
Sep 16, 2024
88a0b89
refactor: modified addPropertyOverride
Sep 16, 2024
3d7e73e
refactor: modified addPropertyOverride
Sep 16, 2024
c14156d
feat: bucket versioning override codegen
Sep 17, 2024
c28e4f9
fix: resolve failing test error
Sep 17, 2024
1d5be0a
fix: resolve workflow errors
Sep 17, 2024
75dc70f
fix: resolve workflow errors
Sep 17, 2024
aad8b48
fix: resolve workflow errors
Sep 17, 2024
b2e96ea
fix: resolve workflow errors
Sep 17, 2024
2e950dd
fix: prettier changes
Sep 17, 2024
e68d2ad
fix: resolve workflow errors
Sep 17, 2024
c3cb8b4
fix: resolve extract-api error
Sep 18, 2024
4559ff3
refactor: assign value to var for reusing/resolve creating storage fi…
Sep 18, 2024
12c923a
fix: resolve policies generated in backend.ts
Sep 19, 2024
a2b43f2
Merge remote-tracking branch 'origin/migrations' into storage
Sep 19, 2024
c3943b0
fix: remove unnecessary log statement
Sanayshah2 Sep 19, 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
2 changes: 2 additions & 0 deletions .eslint-dictionary.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"amplifymeta",
"amplifyrc",
"amplifytools",
"ampx",
"ansi",
"apigateway",
"apigw",
Expand Down Expand Up @@ -434,6 +435,7 @@
"venv",
"verificationbucket",
"versioned",
"versioning",
"vert",
"virtualenv",
"vpc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,144 @@ void describe('auth codegen', () => {
});
});
});
void it('contains oidc login if OIDC identityProvider type is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{ ProviderType: IdentityProviderTypeType.OIDC, ProviderName: 'OIDC_1', ProviderDetails: { oidc_issuer: 'https://example.com' } },
{ ProviderType: IdentityProviderTypeType.OIDC, ProviderName: 'OIDC_2', ProviderDetails: { oidc_issuer: 'https://example.com' } },
],
});
assert(result.loginOptions?.oidcLogin);
});
void it('contains SAML login if SAML identityProvider type is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{
ProviderType: IdentityProviderTypeType.SAML,
ProviderName: 'SAML_1',
ProviderDetails: { metadataContent: 'https://example.com' },
},
],
});
assert(result.loginOptions?.samlLogin);
});
});
void describe('OIDC and SAML providers', () => {
void describe('OIDC', () => {
void it('contains name and issuerUrl if OIDC identityProviderDetails is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{
ProviderType: IdentityProviderTypeType.OIDC,
ProviderName: 'OIDC_1',
ProviderDetails: {
oidc_issuer: 'https://example.com',
authorize_url: 'https://example.com',
token_url: 'https://example.com',
attributes_url: 'https://example.com',
jwks_uri: 'https://example.com',
},
},
{
ProviderType: IdentityProviderTypeType.OIDC,
ProviderName: 'OIDC_2',
ProviderDetails: { oidc_issuer: 'https://example.com' },
},
],
});
assert.deepEqual(result.loginOptions?.oidcLogin, [
{
endpoints: {
authorization: 'https://example.com',
token: 'https://example.com',
userInfo: 'https://example.com',
jwksUri: 'https://example.com',
},
issuerUrl: 'https://example.com',
name: 'OIDC_1',
},
{ issuerUrl: 'https://example.com', name: 'OIDC_2' },
]);
});
void it('contains attributeMapping if AttributeMapping is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{
ProviderType: IdentityProviderTypeType.OIDC,
ProviderName: 'OIDC_1',
ProviderDetails: { oidc_issuer: 'https://example.com' },
AttributeMapping: { name: 'name', phone_number: 'phone_number' },
},
{
ProviderType: IdentityProviderTypeType.OIDC,
ProviderName: 'OIDC_2',
ProviderDetails: { oidc_issuer: 'https://example.com' },
AttributeMapping: { name: 'name', phone_number: 'phone_number' },
},
],
});
assert.deepEqual(result.loginOptions?.oidcLogin, [
{ issuerUrl: 'https://example.com', name: 'OIDC_1', attributeMapping: { fullname: 'name', phoneNumber: 'phone_number' } },
{ issuerUrl: 'https://example.com', name: 'OIDC_2', attributeMapping: { fullname: 'name', phoneNumber: 'phone_number' } },
]);
});
});
void describe('SAML', () => {
void it('contains metadataType URL if SAML identityProviderDetails and metadataURL is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{
ProviderType: IdentityProviderTypeType.SAML,
ProviderName: 'SAML_1',
ProviderDetails: { metadataURL: 'https://example.com' },
},
],
});
assert.deepEqual(result.loginOptions?.samlLogin, {
metadata: { metadataContent: 'https://example.com', metadataType: 'URL' },
name: 'SAML_1',
});
});
void it('contains metadataType FILE if SAML identityProviderDetails and metadataContent is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{
ProviderType: IdentityProviderTypeType.SAML,
ProviderName: 'SAML_1',
ProviderDetails: { metadataContent: 'https://example.com' },
},
],
});
assert.deepEqual(result.loginOptions?.samlLogin, {
metadata: { metadataContent: 'https://example.com', metadataType: 'FILE' },
name: 'SAML_1',
});
});
void it('contains attributeMapping if AttributeMapping is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{
ProviderType: IdentityProviderTypeType.SAML,
ProviderName: 'SAML_1',
ProviderDetails: { metadataContent: 'https://example.com' },
AttributeMapping: { name: 'name', phone_number: 'phone_number' },
},
],
});
assert.deepEqual(result.loginOptions?.samlLogin, {
attributeMapping: { fullname: 'name', phoneNumber: 'phone_number' },
metadata: { metadataContent: 'https://example.com', metadataType: 'FILE' },
name: 'SAML_1',
});
});
});
});
void describe('callback URLs and logout URLs', () => {
void it('contains callback urls if callbackURLs array is passed', () => {
Expand Down Expand Up @@ -204,7 +342,7 @@ void describe('auth codegen', () => {
for (const key in defaultPasswordPolicy) {
const typedKey = key as keyof PasswordPolicyType;
const testValue = defaultPasswordPolicy[typedKey];
void it(`does not explicitly override the value for ${typedKey} when set to the default value of ${testValue}`, () => {
void it(`does explicitly override the value for ${typedKey} when set to the default value of ${testValue}`, () => {
const result = getAuthDefinition({
userPool: {
Policies: {
Expand All @@ -214,7 +352,7 @@ void describe('auth codegen', () => {
},
},
});
assert(!(`Policies.PasswordPolicy.${typedKey}` in result.userPoolOverrides!));
assert(`Policies.PasswordPolicy.${typedKey}` in result.userPoolOverrides!);
});
}
});
Expand Down Expand Up @@ -462,7 +600,7 @@ void describe('auth codegen', () => {
const result = getAuthDefinition({
userPool: { Name: 'test' },
});
assert.deepEqual(result.userPoolOverrides, { UserPoolName: 'test', UsernameAttributes: [] });
assert.deepEqual(result.userPoolOverrides, { userPoolName: 'test', usernameAttributes: [] });
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ const getPasswordPolicyOverrides = (passwordPolicy: Partial<PasswordPolicyType>)
for (const key of Object.keys(passwordPolicy)) {
const typedKey: keyof PasswordPolicyType = key as keyof PasswordPolicyType;
if (passwordPolicy[typedKey] !== undefined) {
if (passwordPolicy[typedKey] === DEFAULT_PASSWORD_SETTINGS[typedKey]) {
continue;
}
policyOverrides[passwordOverridePath(typedKey)] = passwordPolicy[typedKey];
}
}
Expand All @@ -78,12 +75,12 @@ const getUserPoolOverrides = (userPool: UserPoolType): Partial<PolicyOverrides>
Object.assign(userPoolOverrides, getPasswordPolicyOverrides(userPool.Policies?.PasswordPolicy ?? {}));
if (userPool.Name) {
const userNamePolicy: Partial<PolicyOverrides> = {
UserPoolName: userPool.Name,
userPoolName: userPool.Name,
};
Object.assign(userPoolOverrides, userNamePolicy);
}
if (userPool.UsernameAttributes === undefined || userPool.UsernameAttributes.length === 0) {
userPoolOverrides.UsernameAttributes = [];
userPoolOverrides.usernameAttributes = [];
}
return userPoolOverrides;
};
Expand Down
5 changes: 4 additions & 1 deletion packages/amplify-gen1-codegen-storage-adapter/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

```ts

import { Lambda } from '@aws-amplify/amplify-gen2-codegen';
import { StorageRenderParameters } from '@aws-amplify/amplify-gen2-codegen';
import { StorageTriggerEvent } from '@aws-amplify/amplify-gen2-codegen';

// @public (undocumented)
export type CLIV1Permission = 'READ' | 'CREATE_AND_UPDATE' | 'DELETE';

// @public (undocumented)
export const getStorageDefinition: ({ bucketName, cliInputs }: StorageInputs) => StorageRenderParameters;
export const getStorageDefinition: ({ bucketName, cliInputs, triggers }: StorageInputs) => StorageRenderParameters;

// @public (undocumented)
export type StorageCLIInputsJSON = {
Expand All @@ -28,6 +30,7 @@ export type StorageCLIInputsJSON = {
export type StorageInputs = {
bucketName: string;
cliInputs: StorageCLIInputsJSON;
triggers?: Partial<Record<StorageTriggerEvent, Lambda>>;
};

// (No @packageDocumentation comment for this package)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { StorageRenderParameters } from '@aws-amplify/amplify-gen2-codegen';
import { StorageTriggerEvent, Lambda, StorageRenderParameters } from '@aws-amplify/amplify-gen2-codegen';
import { StorageCLIInputsJSON, getStorageAccess } from './storage_access';

export type StorageInputs = {
bucketName: string;
cliInputs: StorageCLIInputsJSON;
triggers?: Partial<Record<StorageTriggerEvent, Lambda>>;
};
export const getStorageDefinition = ({ bucketName, cliInputs }: StorageInputs): StorageRenderParameters => {
export const getStorageDefinition = ({ bucketName, cliInputs, triggers }: StorageInputs): StorageRenderParameters => {
return {
accessPatterns: getStorageAccess(cliInputs),
storageIdentifier: bucketName,
triggers: triggers ?? {},
};
};
8 changes: 8 additions & 0 deletions packages/amplify-gen2-codegen/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

```ts

import { BucketAccelerateStatus } from '@aws-sdk/client-s3';
import { BucketVersioningStatus } from '@aws-sdk/client-s3';
import { EnvironmentResponse } from '@aws-sdk/client-lambda';
import { PasswordPolicyType } from '@aws-sdk/client-cognito-identity-provider';
import { Runtime } from '@aws-sdk/client-lambda';
Expand Down Expand Up @@ -218,16 +220,22 @@ export type StandardAttributes = Partial<Record<Attribute, StandardAttribute>>;

// @public (undocumented)
export interface StorageRenderParameters {
// (undocumented)
accelerateConfiguration?: BucketAccelerateStatus;
// (undocumented)
accessPatterns?: AccessPatterns;
// (undocumented)
bucketEncryptionAlgorithm?: string;
// (undocumented)
dynamoDB?: string;
// (undocumented)
lambdas?: S3TriggerDefinition[];
// (undocumented)
storageIdentifier?: string;
// (undocumented)
triggers?: Partial<Record<StorageTriggerEvent, Lambda>>;
// (undocumented)
versioningConfiguration?: BucketVersioningStatus;
}

// @public (undocumented)
Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-gen2-codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"dependencies": {
"@aws-amplify/auth-construct": "^1.1.5",
"@aws-sdk/client-cognito-identity-provider": "^3.592.0",
"@aws-sdk/client-lambda": "^3.637.0",
"@aws-sdk/client-lambda": "^3.651.1",
"@aws-sdk/client-s3": "^3.651.1",
"aws-cdk-lib": "^2.127.0",
"typescript": "^5.4.5"
},
Expand Down
Loading
Loading