-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ test('Repository url parsing', () => { | |
url: 'https://github.com/apache/sqoop', | ||
name: 'sqoop', | ||
org: 'apache', | ||
protocol: 'https', | ||
}); | ||
|
||
// Valid git url with .git suffix. | ||
|
@@ -23,6 +24,7 @@ test('Repository url parsing', () => { | |
uri: 'github.com/apache/sqoop', | ||
url: 'https://github.com/apache/sqoop.git', | ||
name: 'sqoop', | ||
protocol: 'https', | ||
org: 'apache', | ||
}); | ||
|
||
|
@@ -39,6 +41,7 @@ test('Repository url parsing', () => { | |
url: 'git://a/b', | ||
name: 'b', | ||
org: '_', | ||
protocol: 'git', | ||
}); | ||
|
||
const repo5 = RepositoryUtils.buildRepository('git://a/b/c'); | ||
|
@@ -47,13 +50,15 @@ test('Repository url parsing', () => { | |
url: 'git://a/b/c', | ||
name: 'c', | ||
org: 'b', | ||
protocol: 'git', | ||
}); | ||
|
||
const repo6 = RepositoryUtils.buildRepository('[email protected]:foo/bar.git'); | ||
expect(repo6).toEqual({ | ||
uri: 'github.com/foo/bar', | ||
url: '[email protected]:foo/bar.git', | ||
name: 'bar', | ||
protocol: 'ssh', | ||
org: 'foo', | ||
}); | ||
|
||
|
@@ -63,6 +68,7 @@ test('Repository url parsing', () => { | |
url: 'ssh://[email protected]:foo/bar.git', | ||
name: 'bar', | ||
org: 'foo', | ||
protocol: 'ssh', | ||
}); | ||
}); | ||
|
||
|
@@ -73,6 +79,7 @@ test('Repository url parsing with non standard segments', () => { | |
url: 'git://a/b/c/d', | ||
name: 'd', | ||
org: 'b_c', | ||
protocol: 'git', | ||
}); | ||
|
||
const repo2 = RepositoryUtils.buildRepository('git://a/b/c/d/e'); | ||
|
@@ -81,13 +88,15 @@ test('Repository url parsing with non standard segments', () => { | |
url: 'git://a/b/c/d/e', | ||
name: 'e', | ||
org: 'b_c_d', | ||
protocol: 'git', | ||
}); | ||
|
||
const repo3 = RepositoryUtils.buildRepository('git://a'); | ||
expect(repo3).toEqual({ | ||
uri: 'a/_/_', | ||
url: 'git://a', | ||
name: '_', | ||
protocol: 'git', | ||
org: '_', | ||
}); | ||
}); | ||
|
@@ -99,6 +108,7 @@ test('Repository url parsing with port', () => { | |
url: 'ssh://[email protected]:27017/gitolite-admin', | ||
name: 'gitolite-admin', | ||
org: 'mine', | ||
protocol: 'ssh', | ||
}); | ||
|
||
const repo2 = RepositoryUtils.buildRepository( | ||
|
@@ -108,6 +118,7 @@ test('Repository url parsing with port', () => { | |
uri: 'mydomain.com:27017/elastic/gitolite-admin', | ||
url: 'ssh://[email protected]:27017/elastic/gitolite-admin', | ||
name: 'gitolite-admin', | ||
protocol: 'ssh', | ||
org: 'elastic', | ||
}); | ||
}); | ||
|
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( | ||
'[email protected]: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('[email protected]: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.