-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-3397: Implemented the HTTP-based authentication for Git in Electron.
Closes: #3397 Signed-off-by: Akos Kitta <kittaakos@typefox.io>
- Loading branch information
Akos Kitta
committed
Nov 7, 2018
1 parent
e275359
commit ea5b78a
Showing
19 changed files
with
994 additions
and
55 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { ContainerModule, interfaces } from 'inversify'; | ||
import { WebSocketConnectionProvider } from '@theia/core/lib/browser/messaging/ws-connection-provider'; | ||
import { GitPrompt, GitPromptServer, GitPromptServerProxy, ReconnectingGitPromptServer } from '../../common/git-prompt'; | ||
|
||
export default new ContainerModule(bind => { | ||
bind(GitPrompt).toSelf(); | ||
bindPromptServer(bind); | ||
}); | ||
|
||
export function bindPromptServer(bind: interfaces.Bind): void { | ||
bind(GitPromptServer).to(ReconnectingGitPromptServer).inSingletonScope(); | ||
bind(GitPromptServerProxy).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, GitPrompt.WS_PATH)).inSingletonScope(); | ||
} |
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,180 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { inject, injectable, postConstruct } from 'inversify'; | ||
import { JsonRpcProxy } from '@theia/core/lib/common/messaging/proxy-factory'; | ||
import { JsonRpcServer } from '@theia/core/lib/common/messaging/proxy-factory'; | ||
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable'; | ||
|
||
export const GitPromptServer = Symbol('GitPromptServer'); | ||
export interface GitPromptServer extends JsonRpcServer<GitPromptClient> { | ||
} | ||
|
||
export const GitPromptServerProxy = Symbol('GitPromptServerProxy'); | ||
export interface GitPromptServerProxy extends JsonRpcProxy<GitPromptServer> { | ||
} | ||
|
||
@injectable() | ||
export class GitPrompt implements GitPromptClient, Disposable { | ||
|
||
@inject(GitPromptServer) | ||
protected readonly server: GitPromptServer; | ||
|
||
protected readonly toDispose = new DisposableCollection(); | ||
|
||
@postConstruct() | ||
protected init(): void { | ||
this.server.setClient(this); | ||
} | ||
|
||
dispose(): void { | ||
this.toDispose.dispose(); | ||
} | ||
|
||
async ask(question: GitPrompt.Question): Promise<GitPrompt.Answer> { | ||
return GitPrompt.Failure.create('Interactive Git prompt is not supported in the browser.'); | ||
} | ||
|
||
async confirm(question: GitPrompt.Question): Promise<GitPrompt.Answer> { | ||
return GitPrompt.Failure.create('Interactive Git prompt is not supported in the browser.'); | ||
} | ||
|
||
} | ||
|
||
export namespace GitPrompt { | ||
|
||
/** | ||
* Unique WS endpoint path for the Git prompt service. | ||
*/ | ||
export const WS_PATH = 'services/git-prompt'; | ||
|
||
export interface Question { | ||
readonly text: string; | ||
readonly details?: string; | ||
readonly password?: boolean; | ||
} | ||
|
||
export interface Answer { | ||
readonly type: Answer.Type; | ||
} | ||
|
||
export interface Success { | ||
readonly type: Answer.Type.SUCCESS; | ||
readonly result: string | boolean; | ||
} | ||
|
||
export namespace Success { | ||
|
||
export function is(answer: Answer): answer is Success { | ||
return answer.type === Answer.Type.SUCCESS | ||
&& 'result' in answer | ||
&& ((typeof (answer as Success).result) === 'string' || (typeof (answer as Success).result) === 'boolean'); | ||
} | ||
|
||
export function create(result: string | boolean): Success { | ||
return { | ||
type: Answer.Type.SUCCESS, | ||
result | ||
}; | ||
} | ||
|
||
} | ||
|
||
export interface Cancel extends Answer { | ||
readonly type: Answer.Type.CANCEL; | ||
} | ||
|
||
export namespace Cancel { | ||
|
||
export function is(answer: Answer): answer is Cancel { | ||
return answer.type === Answer.Type.CANCEL; | ||
} | ||
|
||
export function create(): Cancel { | ||
return { | ||
type: Answer.Type.CANCEL | ||
}; | ||
} | ||
|
||
} | ||
|
||
export interface Failure extends Answer { | ||
readonly type: Answer.Type.FAILURE; | ||
readonly error: string | Error; | ||
} | ||
|
||
export namespace Failure { | ||
|
||
export function is(answer: Answer): answer is Failure { | ||
return answer.type === Answer.Type.FAILURE | ||
&& 'error' in answer | ||
&& ((typeof (answer as Failure).error) === 'string' || (answer as Failure).error instanceof Error); | ||
} | ||
|
||
export function create(error: string | Error): Failure { | ||
return { | ||
type: Answer.Type.FAILURE, | ||
error | ||
}; | ||
} | ||
|
||
} | ||
|
||
export namespace Answer { | ||
|
||
export enum Type { | ||
|
||
SUCCESS, | ||
CANCEL, | ||
FAILURE | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
export const GitPromptClient = Symbol('GitPromptClient'); | ||
export interface GitPromptClient { | ||
|
||
ask(question: GitPrompt.Question): Promise<GitPrompt.Answer>; | ||
|
||
confirm(question: GitPrompt.Question): Promise<GitPrompt.Answer>; | ||
|
||
// XXX support for `select`? | ||
|
||
} | ||
|
||
@injectable() | ||
export class ReconnectingGitPromptServer implements GitPromptServer { | ||
|
||
@inject(GitPromptServerProxy) | ||
protected readonly proxy: GitPromptServerProxy; | ||
|
||
@postConstruct() | ||
protected init(): void { | ||
// this.proxy.onDidCloseConnection(() => this.rec) | ||
} | ||
|
||
setClient(client: GitPromptClient): void { | ||
this.proxy.setClient(client); | ||
} | ||
|
||
dispose(): void { | ||
this.proxy.dispose(); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
packages/git/src/electron-browser/prompt/electron-git-prompt-module.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,26 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { ContainerModule } from 'inversify'; | ||
import { GitPrompt } from '../../common/git-prompt'; | ||
import { bindPromptServer } from '../../browser/prompt/git-prompt-module'; | ||
import { GitQuickOpenPrompt } from './git-quick-open-prompt'; | ||
|
||
export default new ContainerModule(bind => { | ||
bind(GitQuickOpenPrompt).toSelf(); | ||
bind(GitPrompt).toService(GitQuickOpenPrompt); | ||
bindPromptServer(bind); | ||
}); |
60 changes: 60 additions & 0 deletions
60
packages/git/src/electron-browser/prompt/git-quick-open-prompt.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,60 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { inject, injectable } from 'inversify'; | ||
import { QuickOpenItem, QuickOpenMode } from '@theia/core/lib/browser/quick-open/quick-open-model'; | ||
import { QuickOpenService } from '@theia/core/lib/browser/quick-open/quick-open-service'; | ||
import { GitPrompt } from '../../common/git-prompt'; | ||
|
||
@injectable() | ||
export class GitQuickOpenPrompt extends GitPrompt { | ||
|
||
@inject(QuickOpenService) | ||
protected readonly quickOpenService: QuickOpenService; | ||
|
||
async ask(question: GitPrompt.Question): Promise<GitPrompt.Answer> { | ||
const { details, text, password } = question; | ||
return new Promise<GitPrompt.Answer>(resolve => { | ||
const model = { | ||
onType(lookFor: string, acceptor: (items: QuickOpenItem[]) => void): void { | ||
acceptor([ | ||
new QuickOpenItem({ | ||
label: details, | ||
run: (mode: QuickOpenMode): boolean => { | ||
if (mode !== QuickOpenMode.OPEN) { | ||
return false; | ||
} | ||
resolve(GitPrompt.Success.create(lookFor)); | ||
return true; | ||
} | ||
}) | ||
]); | ||
} | ||
}; | ||
const options = { | ||
onClose: (canceled: boolean): void => { | ||
if (canceled) { | ||
resolve(GitPrompt.Cancel.create()); | ||
} | ||
}, | ||
placeholder: text, | ||
password | ||
}; | ||
this.quickOpenService.open(model, options); | ||
}); | ||
} | ||
|
||
} |
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,2 @@ | ||
#!/bin/sh | ||
echo '' |
Oops, something went wrong.