Skip to content

fix(cli): generate admin queries auth wiring#14909

Open
hariharan077 wants to merge 1 commit into
aws-amplify:devfrom
hariharan077:fix-14757-admin-queries-rest-api
Open

fix(cli): generate admin queries auth wiring#14909
hariharan077 wants to merge 1 commit into
aws-amplify:devfrom
hariharan077:fix-14757-admin-queries-rest-api

Conversation

@hariharan077

Copy link
Copy Markdown

Description of changes

Fixes #14757.

When Gen1 AdminQueries REST APIs are generated for Gen2 migration, the generated REST API resource needs to preserve the Cognito behavior that AdminQueries depends on. This updates the REST API generator to detect AdminQueries APIs and emit the missing pieces:

  • API-level CORS preflight options so the proxy resource handles OPTIONS
  • a Cognito User Pools authorizer using the Authorization header
  • Cognito authorization method options with the aws.cognito.signin.user.admin scope
  • explicit ANY methods on the root/proxy resources using the Cognito method options
  • Cognito admin/list IAM permissions for the backing AdminQueries Lambda, scoped to the Gen2 user pool and the Gen1 user pool id when available

Regular REST API generation is left unchanged unless the API is AdminQueries or uses an AdminQueries* backing function.

Description of how you validated changes

  • PATH="$PWD/node_modules/.bin:$PATH" corepack yarn workspace @aws-amplify/cli-internal test src/__tests__/commands/gen2-migration/generate/amplify/rest-api/rest-api.generator.test.ts --runInBand --no-coverage
  • PATH="$PWD/node_modules/.bin:$PATH" corepack yarn prettier --check packages/amplify-cli/src/commands/gen2-migration/generate/amplify/rest-api/rest-api.generator.ts packages/amplify-cli/src/commands/gen2-migration/generate/amplify/rest-api/rest-api.renderer.ts packages/amplify-cli/src/__tests__/commands/gen2-migration/generate/amplify/rest-api/rest-api.generator.test.ts
  • PATH="$PWD/node_modules/.bin:$PATH" corepack yarn eslint packages/amplify-cli/src/commands/gen2-migration/generate/amplify/rest-api/rest-api.generator.ts packages/amplify-cli/src/commands/gen2-migration/generate/amplify/rest-api/rest-api.renderer.ts packages/amplify-cli/src/__tests__/commands/gen2-migration/generate/amplify/rest-api/rest-api.generator.test.ts --max-warnings=1500
  • git diff --check
  • PATH="$PWD/node_modules/.bin:$PATH" corepack yarn sanitize-migration-apps
  • PATH="$PWD/node_modules/.bin:$PATH" corepack yarn build-tests-changed

Note: the first build-tests-changed run hit an NX daemon restart message; rerunning the same command succeeded. Local git hooks call a plain yarn binary directly, while this environment exposes Yarn through Corepack, so commit/push hooks were bypassed after running the hook commands above manually.

Checklist

  • PR description included
  • Tests are changed or added

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(gen2-migration): generate incorrectly handles Admin queries in auth definition

1 participant