Skip to content

Commit

Permalink
feat: remove gp mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Apr 19, 2024
1 parent 741374c commit 8a0800f
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 411 deletions.
138 changes: 2 additions & 136 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,153 +30,19 @@ RUN npm ci
COPY ./src/extensions/token-value .
RUN npm run build

# Build gh-webhook-handler
FROM node:18-alpine AS builder-05
WORKDIR /builder/src/extensions/operations/gh-webhook-handler
ADD ./src/extensions/operations/gh-webhook-handler/package.json ./src/extensions/operations/gh-webhook-handler/package-lock.json ./
RUN npm ci
COPY ./src/extensions/operations/gh-webhook-handler .
RUN npm run build

# Build sponsors-cron-handler
FROM node:18-alpine AS builder-06
WORKDIR /builder/src/extensions/operations/sponsors-cron-handler
ADD ./src/extensions/operations/sponsors-cron-handler/package.json ./src/extensions/operations/sponsors-cron-handler/package-lock.json ./
RUN npm ci
COPY ./src/extensions/operations/sponsors-cron-handler .
RUN npm run build

# Build modules/probes-adapter
FROM node:18-alpine AS builder-07
WORKDIR /builder/src/extensions/modules/probes-adapter
ADD ./src/extensions/modules/probes-adapter/package.json ./src/extensions/modules/probes-adapter/package-lock.json ./
RUN npm ci
COPY ./src/extensions/modules/probes-adapter .
RUN npm run build

# Build endpoints/adoption-code
FROM node:18-alpine AS builder-08
WORKDIR /builder/src/extensions/endpoints/adoption-code
ADD ./src/extensions/endpoints/adoption-code/package.json ./src/extensions/endpoints/adoption-code/package-lock.json ./
RUN npm ci
COPY ./src/extensions/endpoints/adoption-code .
RUN npm run build

# Build hooks/adopted-probe
FROM node:18-alpine AS builder-09
WORKDIR /builder/src/extensions/lib
ADD ./src/extensions/lib/package.json ./src/extensions/lib/package-lock.json ./
RUN npm ci
COPY ./src/extensions/lib .
WORKDIR /builder/src/extensions/hooks/adopted-probe
ADD ./src/extensions/hooks/adopted-probe/package.json ./src/extensions/hooks/adopted-probe/package-lock.json ./
RUN npm ci
COPY ./src/extensions/hooks/adopted-probe .
RUN npm run build

# Build hooks/sign-in
FROM node:18-alpine AS builder-10
WORKDIR /builder/src/extensions/hooks/sign-in
ADD ./src/extensions/hooks/sign-in/package.json ./src/extensions/hooks/sign-in/package-lock.json ./
RUN npm ci
COPY ./src/extensions/hooks/sign-in .
RUN npm run build

# Build endpoints/sync-github-data
FROM node:18-alpine AS builder-11
WORKDIR /builder/src/extensions/endpoints/sync-github-data
ADD ./src/extensions/endpoints/sync-github-data/package.json ./src/extensions/endpoints/sync-github-data/package-lock.json ./
RUN npm ci
COPY ./src/extensions/endpoints/sync-github-data .
RUN npm run build

# Build interfaces/github-username
FROM node:18-alpine AS builder-12
WORKDIR /builder/src/extensions/interfaces/github-username
ADD ./src/extensions/interfaces/github-username/package.json ./src/extensions/interfaces/github-username/package-lock.json ./
RUN npm ci
COPY ./src/extensions/interfaces/github-username .
RUN npm run build

# Build adopted-probes-status-cron-handler
FROM node:18-alpine AS builder-13
WORKDIR /builder/src/extensions/operations/adopted-probes-status-cron-handler
ADD ./src/extensions/operations/adopted-probes-status-cron-handler/package.json ./src/extensions/operations/adopted-probes-status-cron-handler/package-lock.json ./
RUN npm ci
COPY ./src/extensions/operations/adopted-probes-status-cron-handler .
RUN npm run build

# Build adopted-probes-credits-cron-handler
FROM node:18-alpine AS builder-14
WORKDIR /builder/src/extensions/operations/adopted-probes-credits-cron-handler
ADD ./src/extensions/operations/adopted-probes-credits-cron-handler/package.json ./src/extensions/operations/adopted-probes-credits-cron-handler/package-lock.json ./
RUN npm ci
COPY ./src/extensions/operations/adopted-probes-credits-cron-handler .
RUN npm run build

# Build interfaces/gp-tags
FROM node:18-alpine AS builder-15
WORKDIR /builder/src/extensions/interfaces/gp-tags
ADD ./src/extensions/interfaces/gp-tags/package.json ./src/extensions/interfaces/gp-tags/package-lock.json ./
RUN npm ci
COPY ./src/extensions/interfaces/gp-tags .
RUN npm run build

# Build operations/remove-banned-users-cron-handler
FROM node:18-alpine AS builder-16
FROM node:18-alpine AS builder-05
WORKDIR /builder/src/extensions/operations/remove-banned-users-cron-handler
ADD ./src/extensions/operations/remove-banned-users-cron-handler/package.json ./src/extensions/operations/remove-banned-users-cron-handler/package-lock.json ./
RUN npm ci
COPY ./src/extensions/operations/remove-banned-users-cron-handler .
RUN npm run build

# Build hooks/gp-tokens
FROM node:18-alpine AS builder-17
WORKDIR /builder/src/extensions/hooks/gp-tokens
ADD ./src/extensions/hooks/gp-tokens/package.json ./src/extensions/hooks/gp-tokens/package-lock.json ./
RUN npm ci
COPY ./src/extensions/hooks/gp-tokens .
RUN npm run build

# Build hooks/directus-users
FROM node:18-alpine AS builder-18
WORKDIR /builder/src/extensions/hooks/directus-users
ADD ./src/extensions/hooks/directus-users/package.json ./src/extensions/hooks/directus-users/package-lock.json ./
RUN npm ci
COPY ./src/extensions/hooks/directus-users .
RUN npm run build

# Build hooks/location-verrides
FROM node:18-alpine AS builder-19
WORKDIR /builder/src/extensions/lib
ADD ./src/extensions/lib/package.json ./src/extensions/lib/package-lock.json ./
RUN npm ci
COPY ./src/extensions/lib .
WORKDIR /builder/src/extensions/hooks/location-overrides
ADD ./src/extensions/hooks/location-overrides/package.json ./src/extensions/hooks/location-overrides/package-lock.json ./
RUN npm ci
COPY ./src/extensions/hooks/location-overrides .
RUN npm run build

FROM directus/directus:10.9.3

COPY --from=builder-01 /builder/src/extensions/hooks/jsd-purge-tokens/dist/* /directus/extensions/hooks/jsd-purge-tokens/
COPY --from=builder-02 /builder/src/extensions/hooks/sign-up/dist/* /directus/extensions/hooks/sign-up/
COPY --from=builder-03 /builder/src/extensions/interfaces/token/dist/* /directus/extensions/interfaces/token/
COPY --from=builder-04 /builder/src/extensions/token-value/dist/* /directus/extensions/directus-extension-token-value/dist/
COPY --from=builder-04 /builder/src/extensions/token-value/package.json /directus/extensions/directus-extension-token-value/
COPY --from=builder-05 /builder/src/extensions/operations/gh-webhook-handler/dist/* /directus/extensions/operations/gh-webhook-handler/
COPY --from=builder-06 /builder/src/extensions/operations/sponsors-cron-handler/dist/* /directus/extensions/operations/sponsors-cron-handler/
COPY --from=builder-07 /builder/src/extensions/modules/probes-adapter/dist/* /directus/extensions/modules/probes-adapter/
COPY --from=builder-08 /builder/src/extensions/endpoints/adoption-code/dist/* /directus/extensions/endpoints/adoption-code/
COPY --from=builder-09 /builder/src/extensions/hooks/adopted-probe/dist/* /directus/extensions/hooks/adopted-probe/
COPY --from=builder-10 /builder/src/extensions/hooks/sign-in/dist/* /directus/extensions/hooks/sign-in/
COPY --from=builder-11 /builder/src/extensions/endpoints/sync-github-data/dist/* /directus/extensions/endpoints/sync-github-data/
COPY --from=builder-12 /builder/src/extensions/interfaces/github-username/dist/* /directus/extensions/interfaces/github-username/
COPY --from=builder-13 /builder/src/extensions/operations/adopted-probes-status-cron-handler/dist/* /directus/extensions/operations/adopted-probes-status-cron-handler/
COPY --from=builder-14 /builder/src/extensions/operations/adopted-probes-credits-cron-handler/dist/* /directus/extensions/operations/adopted-probes-credits-cron-handler/
COPY --from=builder-15 /builder/src/extensions/interfaces/gp-tags/dist/* /directus/extensions/interfaces/gp-tags/
COPY --from=builder-16 /builder/src/extensions/operations/remove-banned-users-cron-handler/dist/* /directus/extensions/operations/remove-banned-users-cron-handler/
COPY --from=builder-17 /builder/src/extensions/hooks/gp-tokens/dist/* /directus/extensions/hooks/gp-tokens/
COPY --from=builder-18 /builder/src/extensions/hooks/directus-users/dist/* /directus/extensions/hooks/directus-users/
COPY --from=builder-19 /builder/src/extensions/hooks/location-overrides/dist/* /directus/extensions/hooks/location-overrides/
COPY --from=builder-05 /builder/src/extensions/operations/remove-banned-users-cron-handler/dist/* /directus/extensions/operations/remove-banned-users-cron-handler/
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# dashboard
# jsDelivr dashboard directus

## Prod first deploy

Expand Down Expand Up @@ -54,11 +54,11 @@ sudo apt -y install haproxy
# Configure and start haproxy
sudo chmod a+w /etc/haproxy/haproxy.cfg
cat <<EOF | sudo tee -a /etc/haproxy/haproxy.cfg > /dev/null
frontend gp_fe
frontend jsd_fe
bind *:80
default_backend gp_be
default_backend jsd_be
backend gp_be
backend jsd_be
server server1 127.0.0.1:8056
EOF
sudo systemctl stop haproxy
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "dashboard",
"name": "dash-directus",
"version": "1.0.0",
"license": "OSL-3.0",
"description": "jsDelivr dashboard",
"description": "jsDelivr dashboard directus",
"private": true,
"type": "module",
"dependencies": {
Expand Down Expand Up @@ -41,10 +41,10 @@
},
"repository": {
"type": "git",
"url": "[email protected]:jsdelivr/dashboard.git"
"url": "[email protected]:jsdelivr/dash-directus.git"
},
"bugs": {
"url": "https://github.com/jsdelivr/dashboard/issues"
"url": "https://github.com/jsdelivr/dash-directus/issues"
},
"engines": {
"node": "^18.15.0"
Expand Down
130 changes: 0 additions & 130 deletions src/extensions/hooks/sign-up/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,85 +1,18 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { expect } from 'chai';
import * as sinon from 'sinon';
import nock from 'nock';
import hook from '../src/index.js';

describe('Sign-up hook', () => {
const callbacks = {
filter: {},
action: {},
};
const hooks = {
filter: (name, cb) => {
callbacks.filter[name] = cb;
},
action: (name, cb) => {
callbacks.action[name] = cb;
},
} as any;
const creditsService = {
readByQuery: sinon.stub().resolves([]),
createOne: sinon.stub(),
};
const creditsAdditionsService = {
readByQuery: sinon.stub().resolves([]),
updateByQuery: sinon.stub(),
};
const sponsorsService = {
readByQuery: sinon.stub().resolves([]),
};
const usersService = {
updateOne: sinon.stub(),
};
const context = {
services: {
ItemsService: sinon.stub().callsFake((collection) => {
switch (collection) {
case 'gp_credits':
return creditsService;
case 'gp_credits_additions':
return creditsAdditionsService;
case 'sponsors':
return sponsorsService;
default:
throw new Error('Collection name wasn\'t provided');
}
}),
UsersService: sinon.stub().callsFake(() => {
return usersService;
}),
},
env: {
GITHUB_ACCESS_TOKEN: 'fakeToken',
},
database: {
transaction: async (f) => {
return f({});
},
},
getSchema: () => Promise.resolve({}),
logger: {
error: () => {},
},
} as any;

before(() => {
nock.disableNetConnect();
});

beforeEach(() => {
sinon.resetHistory();
});

after(() => {
nock.cleanAll();
});

it('filter should fulfill first_name, last_name, github_username', async () => {
nock('https://api.github.com')
.get(`/user/1834071/orgs`)
.reply(200, [{ login: 'jsdelivr' }]);

hook(hooks, context);

const payload = {
Expand All @@ -104,10 +37,6 @@ describe('Sign-up hook', () => {
});

it('filter should use gh login as first_name if name is not provided', async () => {
nock('https://api.github.com')
.get(`/user/1834071/orgs`)
.reply(200, [{ login: 'jsdelivr' }]);

hook(hooks, context);

const payload = {
Expand All @@ -130,63 +59,4 @@ describe('Sign-up hook', () => {
github_organizations: null,
});
});

it('filter should fulfill organizations, credits', async () => {
nock('https://api.github.com')
.get(`/user/1834071/orgs`)
.reply(200, [{ login: 'jsdelivr' }]);

creditsAdditionsService.readByQuery.resolves([{
amount: 10,
github_id: 1834071,
}, {
amount: 20,
github_id: 1834071,
}]);

hook(hooks, context);

await callbacks.action['users.create']({ key: '1-1-1-1', payload: {
provider: 'github',
external_identifier: 1834071,
first_name: 'Dmitriy Akulov',
last_name: 'jimaek',
github_username: null,
github_organizations: null,
} });

expect(usersService.updateOne.args[0]).to.deep.equal([ '1-1-1-1', { github_organizations: [ 'jsdelivr' ] }]);

expect(creditsAdditionsService.updateByQuery.callCount).to.equal(1);

expect(creditsAdditionsService.updateByQuery.args[0]).to.deep.equal([
{ filter: { github_id: 1834071, consumed: false } },
{ consumed: true },
]);

expect(creditsService.createOne.args[0]).to.deep.equal([{ amount: 30, user_id: '1-1-1-1' }]);
});

it('filter should fulfill user type', async () => {
nock('https://api.github.com')
.get(`/user/1834071/orgs`)
.reply(200, [{ login: 'jsdelivr' }]);

sponsorsService.readByQuery.resolves([{
github_id: 1834071,
}]);

hook(hooks, context);

await callbacks.action['users.create']({ key: '1-1-1-1', payload: {
provider: 'github',
external_identifier: 1834071,
first_name: 'Dmitriy Akulov',
last_name: 'jimaek',
github_username: null,
github_organizations: null,
} });

expect(usersService.updateOne.args[0]).to.deep.equal([ '1-1-1-1', { user_type: 'sponsor' }]);
});
});
17 changes: 0 additions & 17 deletions src/extensions/token-value/src/token-validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,4 @@ export default defineHook(({ filter }) => {
const hashedToken = hashToken(token.value);
token.value = hashedToken;
});

filter('gp_tokens.items.create', (payload) => {
const token = payload as Token;
const hashedToken = hashToken(token.value);
token.value = hashedToken;
});

filter('gp_tokens.items.update', (payload) => {
const token = payload as Partial<Token>;

if (token.value === undefined) {
return;
}

const hashedToken = hashToken(token.value);
token.value = hashedToken;
});
});
Loading

0 comments on commit 8a0800f

Please sign in to comment.