Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook up webflow auth during credential checks #94

Merged
merged 19 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,5 @@ ASALocalRun/

out
node_modules
media
media
.DS_Store
32 changes: 29 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 10 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,13 @@
"type": "object",
"title": "GitHub configuration",
"properties": {
"github.username": {
"type": [
"string",
"null"
],
"default": null,
"description": "The username to use when accessing GitHub. The default is to consult the Git credential manager."
},
"github.host": {
"type": "string",
"default": "github.com",
"description": "The host name to access GitHub. Change this to your GitHub Enterprise host."
},
"github.accessToken": {
"type": [
"string",
"null"
],
"default": null,
"description": "GitHub access token."
"github.hosts": {
"type": "array",
"default": [],
"description": "Host tokens",
"items": {
"type": "object"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can also add a "properties" property within items, which helps intellisense in the settings editor

something like

"properties": {
	"host": {
		"type": "string",
		"description": "The host name to access GitHub."
	},
	"username": {
		"type": "string",
		"description": "The host name to access GitHub."
	},
	"token": {
		"type": "string",
		"description": "GitHub access token."
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool, didn't know that, thanks!

}
}
}
},
Expand Down Expand Up @@ -221,9 +208,11 @@
"iconv-lite": "0.4.23",
"vscode": "^1.1.18",
"@octokit/rest": "^15.9.5",
"@types/ws": "^5.1.2",
"markdown-it": "^8.4.0",
"git-credential-node": "^1.1.0",
"tmp": "^0.0.31",
"moment": "^2.22.1"
"moment": "^2.22.1",
"ws": "^6.0.0"
}
}
53 changes: 53 additions & 0 deletions src/authentication/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as vscode from 'vscode';

export interface IHostConfiguration {
host: string;
username: string | undefined;
token: string | undefined;
}

export const HostHelper = class {
public static getApiHost(host: IHostConfiguration | vscode.Uri): vscode.Uri {
const hostUri: vscode.Uri = host instanceof vscode.Uri ? host : vscode.Uri.parse(host.host);
if (hostUri.authority === 'github.com') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible for there to be a case mismatch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmmm, good question. possibly, yes, I can test that quick

return vscode.Uri.parse('https://api.github.com');
} else {
return vscode.Uri.parse(`${hostUri.scheme}://${hostUri.authority}`);
}
}

public static getApiPath(host: IHostConfiguration | vscode.Uri, path: string): string {
const hostUri: vscode.Uri = host instanceof vscode.Uri ? host : vscode.Uri.parse(host.host);
if (hostUri.authority === 'github.com') {
return path;
} else {
return `/api/v3${path}`;
}
}
};

export interface IConfiguration extends IHostConfiguration {
onDidChange: vscode.Event<IConfiguration>;
}

export class Configuration implements IConfiguration {
public username: string | undefined;
public token: string | undefined;
public onDidChange: vscode.Event<IConfiguration>;
private _emitter: vscode.EventEmitter<IConfiguration>;

constructor(public host: string) {
this._emitter = new vscode.EventEmitter<IConfiguration>();
this.onDidChange = this._emitter.event;
}

public update(username: string | undefined, token: string | undefined, raiseEvent: boolean = true): void {
if (username !== this.username || token !== this.token) {
this.username = username;
this.token = token;
if (raiseEvent) {
this._emitter.fire(this);
}
}
}
}
Loading