From 567b34b6bad7d604a63830bbda0cfc56f4c93b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <git@minelli.swiss> Date: Mon, 7 Oct 2024 17:52:47 +0200 Subject: [PATCH] SharedGitlabManager => Adapt to new config usage --- managers/SharedGitlabManager.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/managers/SharedGitlabManager.ts b/managers/SharedGitlabManager.ts index abddde1..0faa08d 100644 --- a/managers/SharedGitlabManager.ts +++ b/managers/SharedGitlabManager.ts @@ -1,5 +1,4 @@ import axios from 'axios'; -import SharedConfig from '../config/SharedConfig.js'; import * as GitlabCore from '@gitbeaker/core'; import { GitbeakerRequestError } from '@gitbeaker/requester-utils'; import { Gitlab, PipelineSchema, ProjectSchema, UserSchema } from '@gitbeaker/rest'; @@ -12,11 +11,11 @@ class SharedGitlabManager { setToken(token: string) { this.api = new Gitlab(Object.assign({ - host: SharedConfig.gitlab.URL + host: this.gitlabUrl ?? '' }, this.refreshTokenFunction ? { oauthToken: token } : { token: token })); } - constructor(token: string, refreshTokenFunction?: () => Promise<string>) { + constructor(public gitlabUrl: string, token: string, public clientId?: string, public urlRedirect?: string, public urlToken?: string, refreshTokenFunction?: () => Promise<string>) { this.refreshTokenFunction = refreshTokenFunction; this.setToken(token); } @@ -36,13 +35,17 @@ class SharedGitlabManager { } async getTokens(codeOrRefresh: string, isRefresh: boolean = false, clientSecret: string = ''): Promise<GitlabToken> { - const response = await axios.post<GitlabToken>(SharedConfig.login.gitlab.url.token, { - client_id : SharedConfig.login.gitlab.client.id, + if ( !this.urlToken ) { + throw new Error('Error when initializing GitlabManager'); + } + + const response = await axios.post<GitlabToken>(this.urlToken, { + client_id : this.clientId, client_secret: clientSecret, grant_type : isRefresh ? 'refresh_token' : 'authorization_code', refresh_token: codeOrRefresh, code : codeOrRefresh, - redirect_uri : SharedConfig.login.gitlab.url.redirect + redirect_uri : this.urlRedirect }); return response.data; -- GitLab