Skip to content

Commit

Permalink
fix principal rewriting in IAM permissions(#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzon authored Nov 5, 2024
1 parent 2b7dda9 commit 809a83e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 42 deletions.
33 changes: 19 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,58 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '18'
- name: Build and Lint
run: |
npm install
npm run lint
- name: Install AWS CLI
uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install awscli
- name: Configure AWS credentials
run: |
aws configure set aws_access_key_id "AKIAI44QH8DHBEXAMPLE" --profile default
aws configure set aws_secret_access_key "je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY" --profile default
aws configure set region "us-east-1" --profile default
aws configure set output "json" --profile default
- name: Install Amplify CLI
run: npm install -g @aws-amplify/cli
- name: Set up Amplify Plugin
run: |
npm -g install .
amplify plugin scan
- name: Configure Amplify CLI
run: |
aws configure set aws_access_key_id "AKIAI44QH8DHBEXAMPLE" --profile default
aws configure set aws_secret_access_key "je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY" --profile default
aws configure set region "us-east-1" --profile default
aws configure set output "json" --profile default
- name: Install Localstack
run: pip install localstack
- name: Start and wait for localstack
timeout-minutes: 5
run: |
docker pull localstack/localstack:latest
LOCALSTACK_API_KEY=${{ secrets.LOCALSTACK_API_KEY }} localstack start -d
docker pull localstack/localstack-pro:latest
LOCALSTACK_API_KEY=${{ secrets.LOCALSTACK_API_KEY }} DEBUG=1 localstack start -d
localstack wait -t 30
- name: Init Amplify Project
run: |
mkdir test_project
cd test_project
amplify init --envName test --yes --use-localstack true
- name: Add Auth Resource
working-directory: test_project
run: |
cat ../headlessRequests/addAuth.json | jq -c | amplify add auth --headless
- name: Add Storage Resource
working-directory: test_project
run: |
cat ../headlessRequests/addStorage.json | jq -c | amplify add storage --headless
- name: Add Api Resource
working-directory: test_project
run: |
cat ../headlessRequests/addApi.json | jq -c | amplify add api --headless
- name: Push Resources
working-directory: test_project
run: amplify push --use-localstack true --yes
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release NPM Package

on:
push:
branches:
- main # Change this to your default branch

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Check out the code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
cache: 'npm'

- name: Install dependencies
run: npm install

- name: Publish to npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The following environment variables can be configured:
* `LOCALSTACK_ENDPOINT`: Sets a custom endpoint (default `https://localhost.localstack.cloud:4566`).

## Change Log
* 0.2.7: remove patching of CFn files
* 0.2.6: more and up to date settings
* 0.2.5: patch AWS-SDK Config
* 0.2.4: add missing handlers
Expand Down
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 2 additions & 28 deletions patches.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs')
// const fs = require('fs')

const DEFAULT_EDGE_PORT = 4566
const DEFAULT_HOSTNAME = 'localhost.localstack.cloud'
Expand Down Expand Up @@ -34,33 +34,8 @@ const patchConfigManagerLoader = (context) => {
}
}

// Patchs the utility that copy files from .ejs to replace the hardcoded AWS domains with LocalStack domains
const patchCopyBatch = (context) => {
const newDomain = getLocalEndpoint().replace('https://', '').replace('http://', '')
const port = newDomain.split(':').pop()
const copyBatchPath = `${snapshotPath}@aws-amplify/cli-internal/lib/extensions/amplify-helpers/copy-batch`

try {
const copyBatchLib = require(copyBatchPath)
const oldMethod = copyBatchLib.copyBatch
copyBatchLib.copyBatch = async (context, jobs, props, force, writeParams) => {
await oldMethod(context, jobs, props, force, writeParams)

//
jobs.forEach(job => {
// console.log(`LS Plugin is patching file: ${job.template}`)
const file = job.target
const content = fs.readFileSync(file).toString()
const newContent = content.replace(new RegExp(`amazonaws.com(:${port})?`, 'gm'), newDomain)
fs.writeFileSync(file, newContent)
})
}
} catch (error) {
context.print.error('Error:\t\tLocalStack Plugin unable to patch CopyBatch Utility', error)
}
}

// Patchs the utility that generates json files replacing the hardcoded AWS domains with LocalStack domains
// These EJS tend to be AWS Cloudformation JSON templates
const patchWriteJsonFileUtility = (context) => {
const jsonUtilitiesPath = `${snapshotPath}@aws-amplify/amplify-cli-core/lib/jsonUtilities`
const newDomain = getLocalEndpoint().replace('https://', '').replace('http://', '')
Expand Down Expand Up @@ -97,7 +72,6 @@ const patchEverything = (context) => {
context.print.info('Info:\t Patching AWS Amplify libs')
patchAwsSdkConfig(context)
patchConfigManagerLoader(context)
patchCopyBatch(context)
patchWriteJsonFileUtility(context)
}

Expand Down
Empty file added tests/test_conversion.js
Empty file.

0 comments on commit 809a83e

Please sign in to comment.