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

GQL-98: Fixes local MMT tokens and removes unused lambda code #153

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion bin/deploy-bamboo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ docker build -t $dockerTag .
# Convenience function to invoke `docker run` with appropriate env vars instead of baking them into image
dockerRun() {
docker run \
-e "API_GATEWAY_DEPLOYMENT_ID=$bamboo_API_GATEWAY_DEPLOYMENT_ID" \
-e "AWS_ACCESS_KEY_ID=$bamboo_AWS_ACCESS_KEY_ID" \
-e "AWS_ACCOUNT=$bamboo_AWS_ACCOUNT" \
-e "AWS_SECRET_ACCESS_KEY=$bamboo_AWS_SECRET_ACCESS_KEY" \
Expand Down
508 changes: 254 additions & 254 deletions cdk/graphql-infrastructure/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cdk/graphql-infrastructure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"typescript": "~5.6.3"
},
"dependencies": {
"@edsc/cdk-utils": "^0.0.2",
"@edsc/cdk-utils": "^0.0.3",
"aws-cdk-lib": "^2.173.2",
"constructs": "^10.0.0"
}
Expand Down
8 changes: 3 additions & 5 deletions cdk/graphql/lib/graphql-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ export interface GraphqlStackProps extends cdk.StackProps {
}

// `logGroupSuffix` is used during the initial migration from serverless to CDK to avoid name conflicts
// const logGroupSuffix = '_2'
// const logGroupSuffix = '_cdk'
const logGroupSuffix = ''

const {
API_GATEWAY_DEPLOYMENT_ID = `ApiGatewayDeployment${new Date().getTime()}`,
CLOUDFRONT_BUCKET_NAME = 'local-bucket',
LOG_DESTINATION_ARN = 'local-arn',
NODE_ENV = 'development',
Expand Down Expand Up @@ -45,7 +44,7 @@ const environment = {
ummToolVersion: '1.2.0',
ummVariableVersion: '1.9.0',
maximumQueryPathLength: '1500',
stage: STAGE_NAME,
stage: STAGE_NAME
}

// NodeJS bundling options
Expand Down Expand Up @@ -89,7 +88,6 @@ export class GraphqlStack extends cdk.Stack {
});

const apiGateway = new application.ApiGateway(this, 'ApiGateway', {
apiDeploymentId: API_GATEWAY_DEPLOYMENT_ID,
apiName: `${STAGE_NAME}-graphql`,
stageName: STAGE_NAME,
})
Expand Down Expand Up @@ -179,7 +177,7 @@ export class GraphqlStack extends cdk.Stack {
logDestinationArn: LOG_DESTINATION_ARN,
logGroupSuffix,
runtime,
s3Sources: [`graphql_apigw${logGroupSuffix}`],
s3Sources: ['graphql_apigw'],
securityGroups: [lambdaSecurityGroup],
stageName: STAGE_NAME,
vpc
Expand Down
508 changes: 254 additions & 254 deletions cdk/graphql/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cdk/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"typescript": "~5.6.3"
},
"dependencies": {
"@edsc/cdk-utils": "^0.0.2",
"@edsc/cdk-utils": "^0.0.3",
"aws-cdk-lib": "^2.173.2",
"constructs": "^10.0.0"
}
Expand Down
95 changes: 0 additions & 95 deletions src/cloudfrontToCloudwatch/__tests__/handler.test.js

This file was deleted.

69 changes: 0 additions & 69 deletions src/cloudfrontToCloudwatch/handler.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/graphql/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ const apolloPlugins = [
})
]

const { IS_OFFLINE: isOffline } = env
const { AWS_SAM_LOCAL: awsSamLocal } = env

// Only utilize stellate in deployed environments
if (!isOffline) {
if (awsSamLocal !== 'true') {
const {
stellateAppName,
stellateKey
Expand Down
2 changes: 1 addition & 1 deletion src/permissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const permissions = shield(
fallbackRule: allow,

// Only allow the external errors when running in the local DEV environment
allowExternalErrors: process.env.IS_OFFLINE,
allowExternalErrors: process.env.AWS_SAM_LOCAL === 'true',

// `fallbackError` displays a useful message to the user containing a requestId, rather than the default "Not Authorized!" GraphQL Shield error.
fallbackError: async (thrownThing, parent, args, context) => {
Expand Down
6 changes: 3 additions & 3 deletions src/permissions/rules/__tests__/isLocalMMT.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('isLocalMMT', () => {
})

test('returns true if the request is offline and has the admin token', async () => {
process.env.IS_OFFLINE = true
process.env.AWS_SAM_LOCAL = 'true'

const result = await isLocalMMT.resolve(
null,
Expand All @@ -28,7 +28,7 @@ describe('isLocalMMT', () => {
})

test('returns false if the request is offline but a real token is passed', async () => {
process.env.IS_OFFLINE = true
process.env.AWS_SAM_LOCAL = 'true'

const result = await isLocalMMT.resolve(
null,
Expand All @@ -44,7 +44,7 @@ describe('isLocalMMT', () => {
})

test('returns false if the request is not offline', async () => {
process.env.IS_OFFLINE = false
process.env.AWS_SAM_LOCAL = 'false'

const result = await isLocalMMT.resolve(
null,
Expand Down
2 changes: 1 addition & 1 deletion src/permissions/rules/isLocalMMT.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { downcaseKeys } from '../../utils/downcaseKeys'
import { isOfflineMMT } from '../../utils/isOfflineMMT'

/**
* Check to see if the request is made while running in dev mode (IS_OFFLINE),
* Check to see if the request is made while running in dev mode (AWS_SAM_LOCAL === 'true'),
* and is coming from the local MMT (token ABC-1).
*/
export const isLocalMMT = rule()(async (parent, params, context) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/__tests__/fetchLaunchpadEdlUid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('fetchLaunchpadEdlUid', () => {
})

test('returns null for the local MMT', async () => {
process.env.IS_OFFLINE = true
process.env.AWS_SAM_LOCAL = 'true'
const token = await fetchLaunchpadEdlUid('ABC-1', 'mock-client-token')

expect(token).toBeNull()
Expand Down
6 changes: 3 additions & 3 deletions src/utils/__tests__/isOfflineMMT.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('isOfflineMMT', () => {

describe('when running offline with the local MMT token', () => {
test('returns true', async () => {
process.env.IS_OFFLINE = true
process.env.AWS_SAM_LOCAL = 'true'
const token = await isOfflineMMT('ABC-1')

expect(token).toEqual(true)
Expand All @@ -25,7 +25,7 @@ describe('isOfflineMMT', () => {

describe('when running online with the local MMT token', () => {
test('returns false', async () => {
process.env.IS_OFFLINE = false
process.env.AWS_SAM_LOCAL = 'false'
const token = await isOfflineMMT('ABC-1')

expect(token).toEqual(false)
Expand All @@ -34,7 +34,7 @@ describe('isOfflineMMT', () => {

describe('when running online a regular token', () => {
test('returns false', async () => {
process.env.IS_OFFLINE = false
process.env.AWS_SAM_LOCAL = 'false'
const token = await isOfflineMMT('mock-token')

expect(token).toEqual(false)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/aws/__test__/getLambdaConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ describe('Test getLambdaConfig', () => {
})

test('when offline endpoint is configured', () => {
process.env.IS_OFFLINE = true
process.env.AWS_SAM_LOCAL = 'true'

const lambdaConfig = getLambdaConfig()
expect(lambdaConfig.endpoint).toEqual('http://localhost:3014')
process.env = OLD_ENV
})

test('when online endpoint is configured', () => {
process.env.IS_OFFLINE = false
process.env.AWS_SAM_LOCAL = 'false'

const lambdaConfig = getLambdaConfig()
expect(lambdaConfig.endpoint).toEqual(undefined)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/aws/getLambdaConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export const getLambdaConfig = () => {
}

const { env } = process
const { IS_OFFLINE: isOffline } = env
const { AWS_SAM_LOCAL: awsSamLocal } = env

if (isOffline) {
if (awsSamLocal === 'true') {
config.endpoint = 'http://localhost:3014'
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/isOfflineMMT.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* @param {String} token User token to check
* @returns Boolean
*/
export const isOfflineMMT = (token) => process.env.IS_OFFLINE && token === 'ABC-1'
export const isOfflineMMT = (token) => process.env.AWS_SAM_LOCAL === 'true' && token === 'ABC-1'
Loading