From 54bbc0d79ca075e6259ca637d916bdf0b7fe46af Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Sun, 9 Oct 2022 15:04:52 +0200 Subject: [PATCH] chore: remove unused gitlab app --- .../src/apps/gitlab/assets/favicon.svg | 12 - .../backend/src/apps/gitlab/authentication.ts | 101 -------- packages/backend/src/apps/gitlab/index.d.ts | 0 packages/backend/src/apps/gitlab/index.ts | 15 -- packages/backend/src/apps/gitlab/info.json | 239 ------------------ 5 files changed, 367 deletions(-) delete mode 100644 packages/backend/src/apps/gitlab/assets/favicon.svg delete mode 100644 packages/backend/src/apps/gitlab/authentication.ts delete mode 100644 packages/backend/src/apps/gitlab/index.d.ts delete mode 100644 packages/backend/src/apps/gitlab/index.ts delete mode 100644 packages/backend/src/apps/gitlab/info.json diff --git a/packages/backend/src/apps/gitlab/assets/favicon.svg b/packages/backend/src/apps/gitlab/assets/favicon.svg deleted file mode 100644 index 65b9e02c..00000000 --- a/packages/backend/src/apps/gitlab/assets/favicon.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/backend/src/apps/gitlab/authentication.ts b/packages/backend/src/apps/gitlab/authentication.ts deleted file mode 100644 index caa7c776..00000000 --- a/packages/backend/src/apps/gitlab/authentication.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { URLSearchParams } from 'url'; -import axios from 'axios'; -import crypto from 'crypto'; -import { Gitlab } from '@gitbeaker/node'; -import type { - IAuthentication, - IApp, - IField, - IJSONObject, -} from '@automatisch/types'; - -export default class Authentication implements IAuthentication { - appData: IApp; - connectionData: IJSONObject; - client: any; - scopes = [ - 'api', - 'profile', - 'email', - ]; - - constructor(appData: IApp, connectionData: IJSONObject) { - this.connectionData = connectionData; - this.appData = appData; - - if (connectionData?.accessToken) { - this.client = new Gitlab({ - host: this.host, - oauthToken: connectionData?.accessToken as string, - }); - } - } - - get host() { - return `https://${this.connectionData.host}`; - } - - get oauthRedirectUrl() { - return this.appData.fields.find( - (field: IField) => field.key == 'oAuthRedirectUrl' - ).value; - } - - async createAuthData() { - const state = crypto.randomUUID(); - - const searchParams = new URLSearchParams({ - client_id: this.connectionData.applicationId as string, - redirect_uri: this.oauthRedirectUrl, - response_type: 'code', - scope: this.scopes.join(' '), - state, - }); - - const url = `${this.host}/oauth/authorize?${searchParams.toString()}`; - - return { url }; - } - - async verifyCredentials() { - const params = new URLSearchParams({ - client_id: this.connectionData.applicationId as string, - grant_type: 'authorization_code', - redirect_uri: this.oauthRedirectUrl, - code: this.connectionData.oauthVerifier as string, - client_secret: this.connectionData.secret as string, - }); - const { data } = await axios.post(`${this.host}/oauth/token`, params.toString()); - const accessToken = data.access_token; - - const client = new Gitlab({ - host: this.host, - oauthToken: accessToken, - }); - - const user = await client.Users.current(); - - return { - host: this.connectionData.host as string, - applicationId: this.connectionData.applicationId as string, - secret: this.connectionData.secret, - accessToken: data.access_token, - refreshToken: data.refresh_token, - expiresIn: data.expires_in, - tokenType: data.token_type, - userId: user.id, - screenName: user.name, - username: user.username, - }; - } - - async isStillVerified() { - try { - await this.client.Users.current(); - - return true; - } catch (err) { - return false; - } - } -} diff --git a/packages/backend/src/apps/gitlab/index.d.ts b/packages/backend/src/apps/gitlab/index.d.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/backend/src/apps/gitlab/index.ts b/packages/backend/src/apps/gitlab/index.ts deleted file mode 100644 index 592ea6e9..00000000 --- a/packages/backend/src/apps/gitlab/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -import Authentication from './authentication'; -import { - IService, - IAuthentication, - IApp, - IJSONObject, -} from '@automatisch/types'; - -export default class Gitlab implements IService { - authenticationClient: IAuthentication; - - constructor(appData: IApp, connectionData: IJSONObject) { - this.authenticationClient = new Authentication(appData, connectionData); - } -} diff --git a/packages/backend/src/apps/gitlab/info.json b/packages/backend/src/apps/gitlab/info.json deleted file mode 100644 index c9703cb5..00000000 --- a/packages/backend/src/apps/gitlab/info.json +++ /dev/null @@ -1,239 +0,0 @@ -{ - "name": "GitLab", - "key": "gitlab", - "iconUrl": "{BASE_URL}/apps/gitlab/assets/favicon.svg", - "docUrl": "https://automatisch.io/docs/gitlab", - "primaryColor": "2DAAE1", - "supportsConnections": true, - "fields": [ - { - "key": "oAuthRedirectUrl", - "label": "OAuth Redirect URL", - "type": "string", - "required": true, - "readOnly": true, - "value": "{WEB_APP_URL}/app/gitlab/connections/add", - "placeholder": null, - "description": "When asked to input an OAuth callback or redirect URL in GitLab OAuth, enter the URL above.", - "docUrl": "https://automatisch.io/docs/gitlab#oauth-redirect-url", - "clickToCopy": true - }, - { - "key": "host", - "label": "GitLab Host", - "type": "string", - "required": true, - "readOnly": false, - "value": "gitlab.com", - "placeholder": null, - "description": "Only required if you host your own instance of GitLab. If you access GitLab by going to https://www.example.com, enter www.example.com here.", - "docUrl": "https://automatisch.io/docs/gitlab#host", - "clickToCopy": false - }, - { - "key": "applicationId", - "label": "Application ID", - "type": "string", - "required": true, - "readOnly": false, - "value": null, - "placeholder": null, - "description": null, - "docUrl": "https://automatisch.io/docs/gitlab#application-id", - "clickToCopy": false - }, - { - "key": "secret", - "label": "Secret", - "type": "string", - "required": true, - "readOnly": false, - "value": null, - "placeholder": null, - "description": null, - "docUrl": "https://automatisch.io/docs/gitlab#secret", - "clickToCopy": false - } - ], - "authenticationSteps": [ - { - "step": 1, - "type": "mutation", - "name": "createConnection", - "arguments": [ - { - "name": "key", - "value": "{key}" - }, - { - "name": "formattedData", - "value": null, - "properties": [ - { - "name": "host", - "value": "{fields.host}" - }, - { - "name": "applicationId", - "value": "{fields.applicationId}" - }, - { - "name": "secret", - "value": "{fields.secret}" - } - ] - } - ] - }, - { - "step": 2, - "type": "mutation", - "name": "createAuthData", - "arguments": [ - { - "name": "id", - "value": "{createConnection.id}" - } - ] - }, - { - "step": 3, - "type": "openWithPopup", - "name": "openAuthPopup", - "arguments": [ - { - "name": "url", - "value": "{createAuthData.url}" - } - ] - }, - { - "step": 4, - "type": "mutation", - "name": "updateConnection", - "arguments": [ - { - "name": "id", - "value": "{createConnection.id}" - }, - { - "name": "formattedData", - "value": null, - "properties": [ - { - "name": "oauthVerifier", - "value": "{openAuthPopup.code}" - } - ] - } - ] - }, - { - "step": 5, - "type": "mutation", - "name": "verifyConnection", - "arguments": [ - { - "name": "id", - "value": "{createConnection.id}" - } - ] - } - ], - "reconnectionSteps": [ - { - "step": 1, - "type": "mutation", - "name": "resetConnection", - "arguments": [ - { - "name": "id", - "value": "{connection.id}" - } - ] - }, - { - "step": 2, - "type": "mutation", - "name": "updateConnection", - "arguments": [ - { - "name": "id", - "value": "{connection.id}" - }, - { - "name": "formattedData", - "value": null, - "properties": [ - { - "name": "host", - "value": "{fields.host}" - }, - { - "name": "applicationId", - "value": "{fields.applicationId}" - }, - { - "name": "secret", - "value": "{fields.secret}" - } - ] - } - ] - }, - { - "step": 3, - "type": "mutation", - "name": "createAuthData", - "arguments": [ - { - "name": "id", - "value": "{connection.id}" - } - ] - }, - { - "step": 4, - "type": "openWithPopup", - "name": "openAuthPopup", - "arguments": [ - { - "name": "url", - "value": "{createAuthData.url}" - } - ] - }, - { - "step": 5, - "type": "mutation", - "name": "updateConnection", - "arguments": [ - { - "name": "id", - "value": "{connection.id}" - }, - { - "name": "formattedData", - "value": null, - "properties": [ - { - "name": "oauthVerifier", - "value": "{openAuthPopup.code}" - } - ] - } - ] - }, - { - "step": 6, - "type": "mutation", - "name": "verifyConnection", - "arguments": [ - { - "name": "id", - "value": "{connection.id}" - } - ] - } - ] -}