diff --git a/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.html b/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.html index f04f14af..f71eab53 100644 --- a/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.html +++ b/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.html @@ -20,12 +20,12 @@

Import a script file from GitHub

type="text" /> - GitHub Password + GitHub Token + placeholder="Personal Access Token" + type="text" /> diff --git a/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.ts b/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.ts index 8767ead0..2437765c 100644 --- a/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.ts +++ b/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.ts @@ -124,26 +124,13 @@ export class DfScriptsGithubDialogComponent implements OnInit { const githubApiEndpoint = `${this.repoOwner}/${this.repoName}/contents/${this.fileName}`; - const authData = window.btoa( - this.formGroup.value.username + ':' + this.formGroup.value.password - ); - - const headers: KeyValuePair[] = this.isGitRepoPrivate - ? [ - { - key: 'Authorization', - value: `Basic ${authData}`, - }, - ] - : []; - this.githubService - .get(githubApiEndpoint, { - additionalParams: [{ key: 'ref', value: 'main' }], - additionalHeaders: [...headers], - }) - - .subscribe(data => { + .getFileContent( + githubApiEndpoint, + this.formGroup.value.username, + this.formGroup.value.password + ) + .subscribe((data: any) => { this.dialogRef.close({ data: data }); }); } diff --git a/src/app/shared/services/df-base-crud.service.ts b/src/app/shared/services/df-base-crud.service.ts index d19698f0..919669ed 100644 --- a/src/app/shared/services/df-base-crud.service.ts +++ b/src/app/shared/services/df-base-crud.service.ts @@ -1,4 +1,4 @@ -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; import { RequestOptions } from 'src/app/shared/types/generic-http'; import { readAsText } from 'src/app/shared/utilities/file'; import { map, switchMap } from 'rxjs'; @@ -31,6 +31,17 @@ export class DfBaseCrudService { ); } + getFileContent(id: string, username?: string, token?: string) { + let headers = new HttpHeaders(); + if (username && token) { + headers = headers.set( + 'Authorization', + 'Basic ' + btoa(`${username}:${token}`) + ); + } + return this.http.get(`${this.url}/${id}`, { headers }); + } + getEventScripts() { return this.http.get( '/api/v2/system/event_script',