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

Fix/ignore GitHub unmanaged urls #272

Merged
merged 4 commits into from
Sep 23, 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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG REPO_LOCATION=
FROM ${REPO_LOCATION}node:20-alpine as builder
FROM ${REPO_LOCATION}node:20-alpine AS builder
ARG NG_BUILD_CONFIG=

RUN npm i -g @nestjs/cli
Expand Down Expand Up @@ -56,7 +56,7 @@ EXPOSE 3000

VOLUME /config/envconsul

ENV NODE_ENV production
ENV NODE_ENV=production

# Start up command
ENTRYPOINT ["envconsul", "-config", "/config/envconsul/env.hcl", "node", "dist/main"]
758 changes: 379 additions & 379 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"typeorm": "typeorm-ts-node-commonjs"
},
"dependencies": {
"@aws-sdk/client-kinesis": "^3.651.1",
"@aws-sdk/client-kinesis": "^3.654.0",
"@nestjs/axios": "^3.0.3",
"@nestjs/common": "^10.4.3",
"@nestjs/common": "^10.4.4",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.4.3",
"@nestjs/core": "^10.4.4",
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.4.3",
"@nestjs/platform-express": "^10.4.4",
"@nestjs/schedule": "^4.1.1",
"@nestjs/serve-static": "^4.0.2",
"@nestjs/swagger": "^7.4.2",
Expand Down Expand Up @@ -62,11 +62,11 @@
"uuid": "^10.0.0"
},
"devDependencies": {
"@eslint/js": "^9.10.0",
"@eslint/js": "^9.11.0",
"@golevelup/ts-jest": "^0.5.5",
"@nestjs/cli": "^10.4.5",
"@nestjs/schematics": "^10.1.4",
"@nestjs/testing": "^10.4.3",
"@nestjs/testing": "^10.4.4",
"@types/cron": "^2.4.0",
"@types/deep-equal": "^1.0.4",
"@types/ejs": "^3.1.5",
Expand All @@ -84,7 +84,7 @@
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^8.6.0",
"@typescript-eslint/parser": "^8.6.0",
"eslint": "^9.10.0",
"eslint": "^9.11.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
Expand Down
29 changes: 25 additions & 4 deletions src/collection/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export class AccountService {
1,
);
if (downstreamServices) {
const errors = [];
for (const service of downstreamServices) {
const serviceName = service.collection.name;
const projectDtoArr =
Expand All @@ -353,14 +354,30 @@ export class AccountService {
['component'],
);
const projectName = projectDtoArr[0].collection.name;
try {

// Determine if this is a valid service to sync for
if (
!this.githubService.isBrokerManagedScmUrl(service.collection.scmUrl)
) {
this.auditService.recordToolsSync(
'start',
'info',
'unknown',
`Start sync: ${service.collection.scmUrl}`,
`Skip sync: ${service.collection.scmUrl}`,
projectName,
serviceName,
);
continue;
}

this.auditService.recordToolsSync(
'start',
'unknown',
`Start sync: ${service.collection.scmUrl}`,
projectName,
serviceName,
);

try {
await this.githubService.refresh(
projectName,
serviceName,
Expand Down Expand Up @@ -388,9 +405,13 @@ export class AccountService {
serviceName,
httpErr,
);
throw httpErr;
errors.push(httpErr);
}
}

if (errors.length > 0) {
throw errors[0];
}
} else {
this.auditService.recordToolsSync(
'info',
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ export const REDIS_PUBSUB = {

export const GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID ?? '';
export const GITHUB_PRIVATE_KEY = process.env.GITHUB_PRIVATE_KEY ?? '';
export const GITHUB_MANAGED_URL_REGEX =
process.env.GITHUB_MANAGED_URL_REGEX ??
'^https://github.com/([a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+)$';
11 changes: 10 additions & 1 deletion src/github/github.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import sodium from 'libsodium-wrappers';
import * as jwt from 'jsonwebtoken';
import {
GITHUB_CLIENT_ID,
GITHUB_MANAGED_URL_REGEX,
GITHUB_PRIVATE_KEY,
VAULT_KV_APPS_MOUNT,
} from '../constants';
Expand All @@ -13,6 +14,7 @@ import { VaultService } from '../vault/vault.service';
@Injectable()
export class GithubService {
private readonly axiosInstance: AxiosInstance;
private brokerManagedRegex = new RegExp(GITHUB_MANAGED_URL_REGEX);

constructor(private readonly vaultService: VaultService) {
this.axiosInstance = axios.create({
Expand All @@ -27,11 +29,18 @@ export class GithubService {
return GITHUB_CLIENT_ID !== '' && GITHUB_PRIVATE_KEY !== '';
}

public isBrokerManagedScmUrl(scmUrl: string) {
if (!scmUrl) {
return false;
}
return this.brokerManagedRegex.test(scmUrl);
}

public async refresh(project: string, service: string, scmUrl: string) {
if (!this.isEnabled()) {
throw new Error('Not enabled');
}
if (!scmUrl) {
if (!this.isBrokerManagedScmUrl(scmUrl)) {
throw new Error('Service does not have Github repo URL to update');
}
const path = `tools/${project}/${service}`;
Expand Down
3 changes: 0 additions & 3 deletions src/persistence/dto/collection-config.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ export class CollectionConfigDto {
dir: 1 | -1;
};

@Column()
graphVertexOmit?: boolean;

@Column()
index: number;

Expand Down
Loading
Loading