Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Bump redis to latest (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjackgardner authored May 19, 2021
1 parent d5a9657 commit eeb9de5
Show file tree
Hide file tree
Showing 10 changed files with 3,396 additions and 3,710 deletions.
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@
"test:unit": "jest",
"pretest:integration": "node tools/test-local.js",
"test:integration": "yarn test:integration:staging",
"posttest:integration": "node tools/revert-test-local.js",
"posttest:integration": "node tools/test-local.js --revert",
"test:integration:staging": "cypress run --reporter junit",
"format": "prettier --write src/**/*.ts src/**/*.tsx",
"build": "yarn clean && yarn build:server && yarn build:ui",
"build:server": "tsc",
"build:ui": "cross-env OUTPUT_PATH=dist/static webpack --mode=production",
"start": "cross-env NODE_ENV=production node ./dist",
"dev": "yarn build:server && concurrently \"webpack-dev-server\" \"tsc -w\" \"nodemon ./dist --watch dist --watch config.js --watch rules --delay 1\"",
"precommit": "node tools/revert-test-local.js && lint-staged",
"postinstall": "node tools/hax.js",
"migrate": "ts-node src/db/MigrationService.ts"
"precommit": "node tools/test-local.js --revert && lint-staged",
"migrate": "ts-node src/db/MigrationService.ts",
"tunnel": "./tools/tunnel.sh"
},
"devDependencies": {
"@types/body-parser": "^1.17.0",
"@types/connect-redis": "^0.0.7",
"@types/connect-redis": "0.0.16",
"@types/express": "^4.16.0",
"@types/express-session": "^1.15.11",
"@types/express-session": "^1.17.3",
"@types/express-winston": "^3.0.0",
"@types/faker": "^4.1.12",
"@types/jest": "^26.0.5",
"@types/joi": "^14.3.4",
"@types/node": "^10.12.7",
"@types/p-retry": "^2.0.0",
"@types/passport": "^0.4.7",
"@types/passport-oauth2": "^1.4.7",
"@types/passport": "^1.0.6",
"@types/passport-oauth2": "^1.4.10",
"@types/react": "^16.7.5",
"@types/react-dom": "^16.0.9",
"@types/redis": "^2.8.7",
"@types/redis": "^2.8.28",
"@types/redlock": "^3.0.2",
"@types/umzug": "^2.2.2",
"cache-loader": "^1.2.5",
Expand Down Expand Up @@ -78,21 +78,21 @@
"atlassian-jwt": "^1.0.1",
"axios": "^0.21.1",
"body-parser": "^1.18.2",
"connect-redis": "^3.4.0",
"connect-redis": "^5.2.0",
"cross-env": "^5.2.0",
"date-fns": "^1.29.0",
"delay": "^4.3.0",
"emotion": "^10.0.27",
"express": "^4.16.2",
"express-session": "^1.15.6",
"express-session": "^1.17.1",
"express-winston": "^3.0.1",
"micromatch": "^4.0.2",
"passport": "^0.4.0",
"passport-oauth2": "^1.4.0",
"passport": "^0.4.1",
"passport-oauth2": "^1.5.0",
"pg": "^8.2.1",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"redis": "^2.8.0",
"redis": "^3.1.2",
"redlock": "^3.1.2",
"reflect-metadata": "^0.1.12",
"sequelize": "^4.44.0",
Expand All @@ -105,7 +105,8 @@
},
"resolutions": {
"lodash": "^4.17.21",
"color-string": "^1.5.5"
"color-string": "^1.5.5",
"@types/sequelize": "^4.28.9"
},
"lint-staged": {
"*.js": [
Expand Down
16 changes: 5 additions & 11 deletions src/auth/bitbucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { config } from '../lib/Config';
import { OAuthConfig } from '../types';

export function initializePassport(oAuthConfig: OAuthConfig) {
passport.deserializeUser<ISessionUser, string>((serialized, done) => {
done(null, JSON.parse(serialized));
passport.serializeUser<string>((user, done) => {
done(null, JSON.stringify(user));
});

passport.serializeUser<ISessionUser, string>((user, done) => {
done(null, JSON.stringify(user));
passport.deserializeUser<string>((serialized, done) => {
done(null, JSON.parse(serialized));
});

passport.use(
Expand All @@ -24,13 +24,7 @@ export function initializePassport(oAuthConfig: OAuthConfig) {
clientID: oAuthConfig.key,
clientSecret: oAuthConfig.secret,
},
async (
accessToken: string,
refreshToken: string,
results: any,
profile: any,
verified: VerifyCallback,
) => {
async (accessToken: string, refreshToken: string, profile: any, verified: VerifyCallback) => {
let userInfo: ISessionUser;
try {
const userResponse = await axios.get('https://api.bitbucket.org/2.0/user', {
Expand Down
12 changes: 8 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env node

import * as redis from 'redis';
import * as connectRedis from 'connect-redis';
import * as express from 'express';
import * as expressSession from 'express-session';
import * as expressWinston from 'express-winston';
import * as passport from 'passport';
import * as session from 'express-session';
import * as bodyParser from 'body-parser';

import { initializeSequelize, MigrationService } from './db';
Expand All @@ -19,7 +19,7 @@ import { LandRequestHistory } from './lib/History';
import { Logger } from './lib/Logger';
import { initializeEventListeners, eventEmitter } from './lib/Events';

const RedisStore = connectRedis(session);
const RedisStore = connectRedis(expressSession);

async function main() {
if (!hasConfig) {
Expand All @@ -34,6 +34,11 @@ async function main() {

const server = express();

const redisClient = redis.createClient({
host: config.deployment.redis.endpoint,
port: config.deployment.redis.port,
});

server.use(
expressWinston.logger({
meta: false,
Expand All @@ -49,8 +54,7 @@ async function main() {
secret: config.deployment.secret,
saveUninitialized: true,
store: new RedisStore({
host: config.deployment.redis.endpoint,
port: config.deployment.redis.port,
client: redisClient,
}),
}),
);
Expand Down
36 changes: 0 additions & 36 deletions tools/hax.js

This file was deleted.

17 changes: 0 additions & 17 deletions tools/revert-test-local.js

This file was deleted.

10 changes: 6 additions & 4 deletions tools/test-local.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const fs = require('fs');
const path = require('path');

const revert = process.argv.includes('--revert');

const devURL = "'https://atlassian-frontend-landkid.dev.services.atlassian.com/current-state/'";
const envURL = "Cypress.env('LANDKID_DEV_URL')";

const cypressSupportPath = path.resolve(__dirname, '..', 'cypress', 'support', 'index.js');

if (fs.existsSync(cypressSupportPath)) {
Expand All @@ -9,9 +14,6 @@ if (fs.existsSync(cypressSupportPath)) {
fs
.readFileSync(cypressSupportPath, 'utf8')
.replace('LANDKID_SESSION_ID', 'LANDKID_DEV_SESSION_ID')
.replace(
"'https://atlassian-frontend-landkid.dev.services.atlassian.com/current-state/'",
"Cypress.env('LANDKID_DEV_URL')",
),
.replace(revert ? envURL : devURL, revert ? devURL : envURL),
);
}
58 changes: 58 additions & 0 deletions tools/tunnel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

function deleteTunnel {
echo -e "${GREEN}Deleting tunnel and attached hostnames${ENDCOLOUR}"
rm -f ${CREDFILE}
atlas slauth curl -a atlastunnel-issuer -e prod -- \
"https://atlastunnel-issuer.ap-southeast-2.prod.atl-paas.net/delete?tunnel=${TUNNEL_NAME}"
}

# This will clean everything up after the script exits
trap deleteTunnel INT TERM

GREEN="\033[1;32m"
RED="\033[1;31m"
ENDCOLOUR="\033[0m"
BOLD="\033[0;1m"

# Check for required command line args
if [ $# != 2 ]; then
echo -e "${BOLD}Usage: yarn tunnel <TUNNELNAME> <HOSTNAME>${ENDCOLOUR}"
exit 1
fi

TUNNEL_NAME="$1"
HOST_NAME="$2"

TMPFILE=$(mktemp -t tmp)
CLOUDFLARED_DIR=$(cd ~/.cloudflared && pwd)

# Generate cloudflared tunnel
echo -e "${GREEN}Creating tunnel: ${BOLD}${TUNNEL_NAME}${ENDCOLOUR}"
atlas slauth curl -a atlastunnel-issuer -e prod -- \
"https://atlastunnel-issuer.ap-southeast-2.prod.atl-paas.net/generate?tunnel=${TUNNEL_NAME}" \
> ${TMPFILE}

# Move credentials (provided by generate step) into credentials file
TUNNEL_ID=$(jq -r .TunnelID ${TMPFILE})
CREDFILE="${CLOUDFLARED_DIR}/${TUNNEL_ID}.json"
cp "${TMPFILE}" "${CREDFILE}"
rm -f ${TMPFILE}

echo -e "${GREEN}Created file with tunnel credentials: ${BOLD}${CREDFILE}${ENDCOLOUR}"

# Attach hostname to tunnel
echo -e "${GREEN}Attaching hostname: ${BOLD}${HOST_NAME}${ENDCOLOUR}"
atlas slauth curl -a atlastunnel-issuer -e prod -- \
"https://atlastunnel-issuer.ap-southeast-2.prod.atl-paas.net/attach?tunnel=${TUNNEL_NAME}&hostname=${HOST_NAME}"

# Generate tunnel config
cp tunnel-config.template.yml ~/.cloudflared/config.yml
sed -i ".backup" "s:<TUNNELID>:${TUNNEL_ID}:gi" ~/.cloudflared/config.yml
sed -i ".backup" "s:<CREDFILE>:${CREDFILE}:gi" ~/.cloudflared/config.yml
sed -i ".backup" "s:<HOSTNAME>:${HOST_NAME}:gi" ~/.cloudflared/config.yml

echo -e "${GREEN}Created tunnel config${ENDCOLOUR}"

cloudflared tunnel --config ~/.cloudflared/config.yml ingress validate
cloudflared tunnel --config ~/.cloudflared/config.yml run ${TUNNEL_ID}
7 changes: 7 additions & 0 deletions tunnel-config.template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file is used by tools/tunnel.sh to generate a private tunnel-config.yml file
tunnel: <TUNNELID>
credentials-file: <CREDFILE>
ingress:
- hostname: <HOSTNAME>.public.atlastunnel.com
service: http://localhost:3000
- service: http_status:404
10 changes: 4 additions & 6 deletions typings/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ declare namespace JSX {
}
}

declare namespace Express {
interface User extends ISessionUser {}
}

declare interface Window {
landClicked: () => void;
landWhenAbleClicked: () => void;
Expand Down Expand Up @@ -88,12 +92,6 @@ declare interface UserState extends IPermission {
note?: string;
}

declare namespace Express {
interface Request {
user?: ISessionUser;
}
}

declare type HistoryResponse = {
history: IStatusUpdate[];
count: number;
Expand Down
Loading

0 comments on commit eeb9de5

Please sign in to comment.