-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Code] enable ssh protocol, only read ssh key pairs from data folder.
- Loading branch information
spacedragon
committed
Apr 3, 2019
1 parent
8132915
commit 80e07a5
Showing
13 changed files
with
249 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ export class RepositoryUtils { | |
url: repo.href as string, | ||
name, | ||
org, | ||
protocol: repo.protocol, | ||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/code/server/__tests__/repository_service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import assert from 'assert'; | ||
// import { generateKeyPairSync } from 'crypto'; | ||
import fs from 'fs'; | ||
import * as os from 'os'; | ||
import path from 'path'; | ||
import rimraf from 'rimraf'; | ||
import { RepositoryUtils } from '../../common/repository_utils'; | ||
import { RepositoryService } from '../repository_service'; | ||
import { ConsoleLogger } from '../utils/console_logger'; | ||
|
||
describe('repository service test', () => { | ||
const log = new ConsoleLogger(); | ||
const baseDir = fs.mkdtempSync(path.join(os.tmpdir(), 'code_test')); | ||
log.debug(baseDir); | ||
const repoDir = path.join(baseDir, 'repo'); | ||
const credsDir = path.join(baseDir, 'credentials'); | ||
// @ts-ignore | ||
before(() => { | ||
fs.mkdirSync(credsDir); | ||
fs.mkdirSync(repoDir); | ||
}); | ||
// @ts-ignore | ||
after(() => { | ||
return rimraf.sync(baseDir); | ||
}); | ||
const service = new RepositoryService(repoDir, credsDir, log); | ||
|
||
it('can not clone a repo by ssh without a key', async () => { | ||
const repo = RepositoryUtils.buildRepository( | ||
'git@github.com:elastic/TypeScript-Node-Starter.git' | ||
); | ||
await assert.rejects(service.clone(repo)); | ||
// @ts-ignore | ||
}).timeout(60000); | ||
|
||
/*it('can clone a repo by ssh with a key', async () => { | ||
const repo = RepositoryUtils.buildRepository('git@github.com:elastic/code.git'); | ||
const { publicKey, privateKey } = generateKeyPairSync('rsa', { | ||
modulusLength: 4096, | ||
publicKeyEncoding: { | ||
type: 'pkcs1', | ||
format: 'pem', | ||
}, | ||
privateKeyEncoding: { | ||
type: 'pkcs1', | ||
format: 'pem', | ||
}, | ||
}); | ||
fs.writeFileSync(path.join(credsDir, 'id_rsa.pub'), publicKey); | ||
fs.writeFileSync(path.join(credsDir, 'id_rsa'), privateKey); | ||
const result = await service.clone(repo); | ||
assert.ok(fs.existsSync(path.join(repoDir, result.repo.uri))); | ||
}).timeout(60000); */ | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.