Add authentication to GitHub preparer

This commit is contained in:
Taras Mankovski
2020-10-08 07:27:49 -04:00
parent 55602200a3
commit 4df660e37f
2 changed files with 20 additions and 4 deletions
@@ -21,11 +21,18 @@ import { parseLocationAnnotation } from '../helpers';
import { InputError } from '@backstage/backend-common';
import { PreparerBase } from './types';
import GitUriParser from 'git-url-parse';
import { Clone } from 'nodegit';
import { Clone, Cred } from 'nodegit';
export class GithubPreparer implements PreparerBase {
token: string;
constructor(params: { token: string }) {
this.token = params.token;
}
async prepare(template: TemplateEntityV1alpha1): Promise<string> {
const { protocol, location } = parseLocationAnnotation(template);
const { token } = this;
if (protocol !== 'github') {
throw new InputError(
@@ -46,7 +53,13 @@ export class GithubPreparer implements PreparerBase {
);
await Clone.clone(repositoryCheckoutUrl, tempDir, {
// TODO(blam): Maybe need some auth here?
fetchOpts: {
callbacks: {
credentials() {
return Cred.userpassPlaintextNew(token, 'x-oauth-basic');
},
},
},
});
return path.resolve(tempDir, templateDirectory);