Skip to content

Commit

Permalink
Support for secured template sources
Browse files Browse the repository at this point in the history
Some improvements and refactorings to the template sources page

eclipse-archived/codewind#2647

Signed-off-by: Tim Etchells <[email protected]>
  • Loading branch information
Tim Etchells committed Jun 19, 2020
1 parent b61f0ba commit 6974d85
Show file tree
Hide file tree
Showing 15 changed files with 490 additions and 109 deletions.
38 changes: 20 additions & 18 deletions dev/res/css/sources-registries-tables.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

body {
min-width: 700px;
max-width: 1200px;
}

#toolbar {
Expand Down Expand Up @@ -53,8 +54,13 @@ table {
width: 20%;
}

#status-col {
width: 75px;
#enabled-col {
width: 8ch;
}

#enabled-thead {
text-align: center;
padding: 0;
}

#style-col {
Expand All @@ -66,17 +72,18 @@ table {
}

.btn-col {
width: 70px;
width: 50px;
}

#no-registries-msg {
font-weight: normal;
}

td {
padding: 1em;
padding-top: 1.25em;
padding-bottom: 1.25em;
vertical-align: text-top;
padding: 0.5em;
padding-top: 1em;
padding-bottom: 1em;
border-bottom: 1px solid #444;
}

Expand Down Expand Up @@ -104,15 +111,15 @@ thead > tr > td {
text-align: center;
}

.btn-cell > .btn {
height: 1.75em;
.btn-cell .btn, .btn-cell img {
height: 1.2rem;
padding: 0;
vertical-align: top;
}

.btn-cell > .toggle-btn {
min-height: 1.25em;
height: 125%;
margin-left: auto;
margin-right: auto;
.btn-cell .toggle-btn {
min-height: 1.2rem;
height: 120%;
}

.namespace-disabled {
Expand All @@ -122,8 +129,3 @@ thead > tr > td {
#push-registry-header {
text-align: center;
}

.push-registry-radiobtn {
zoom: 175%;
margin: 0;
}
7 changes: 7 additions & 0 deletions dev/res/img/dark/locked.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions dev/res/img/light/locked.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions dev/src/codewind/Requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class Requester {
// tslint:disable-next-line: typedef - The typedef for the options accepted by Got is a total mess :)
private static getGotOptions(verb: HttpMethod, url: string, options: RequesterOptions) {
return {
followRedirect: true,
method: verb,
rejectUnauthorized: false,
json: options.body,
Expand Down
26 changes: 26 additions & 0 deletions dev/src/codewind/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ export interface TemplateSource {
readonly enabled: boolean;
readonly projectStyles: string[];
readonly protected: boolean;
/**
* If auth object is not present, the source is public.
* If it's present and there is a username, then username/pw were used. Else, PAT was used.
* https://github.com/eclipse/codewind/issues/3101
*/
readonly authentication?: {
username?: string;
}
}

export type TemplateSourceAuthType = "credentials" | "pat";

export type TemplateSourceAuth = {
type: "credentials",
username: string,
password?: string
} | {
type: "pat",
personalAccessToken: string
}

export interface NewTemplateSource {
readonly url: string;
readonly name: string;
readonly description?: string;
readonly auth?: TemplateSourceAuth;
}

/**
Expand Down
31 changes: 25 additions & 6 deletions dev/src/codewind/cli/CLICommandRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import MCUtil from "../../MCUtil";
import { CLICommands } from "./CLICommands";
import {
CLIStatus, IInitializationResponse, IDetectedProjectType, CLIConnectionData,
TemplateSource, AccessToken, RegistrySecret, CWTemplateData, DiagnosticsResult } from "../Types";
TemplateSource, AccessToken, RegistrySecret, CWTemplateData, DiagnosticsResult, NewTemplateSource } from "../Types";

export namespace CLICommandRunner {

Expand Down Expand Up @@ -197,15 +197,32 @@ export namespace CLICommandRunner {

///// Template source management commands - These should only be used by the TemplateSourceList

export async function addTemplateSource(connectionID: string, url: string, name: string, descr?: string): Promise<TemplateSource[]> {
export async function addTemplateSource(connectionID: string, newSource: NewTemplateSource): Promise<TemplateSource[]> {

const args = [
"--conid", connectionID,
"--url", url,
"--name", name,
"--url", newSource.url,
"--name", newSource.name,
];

if (descr) {
args.push("--description", descr);
if (newSource.description) {
args.push("--description", newSource.description);
}

if (newSource.auth) {
if (newSource.auth.type === "credentials") {
args.push("--username", newSource.auth.username);
if (newSource.auth.password == null) {
Log.e(`No password provided for template source ${newSource.url}`);
}
args.push(CLICommands.PASSWORD_ARG, newSource.auth.password || "");
}
else if (newSource.auth.personalAccessToken) {
args.push(CLICommands.PAT_ARG, newSource.auth.personalAccessToken);
}
else {
Log.e(`Empty auth object passed for template source "${newSource.url}"`);
}
}

return CLIWrapper.cwctlExec(CLICommands.TEMPLATE_SOURCES.ADD, args);
Expand Down Expand Up @@ -310,6 +327,8 @@ export namespace CLICommandRunner {
return result;
}

///// Project links

export async function addLink(projectID: string, targetProjectID: string, envName: string): Promise<void> {
await CLIWrapper.cwctlExec(CLICommands.PROJECT.LINK, [
"create",
Expand Down
1 change: 1 addition & 0 deletions dev/src/codewind/cli/CLICommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class CLICommand {

export namespace CLICommands {
export const PASSWORD_ARG = "--password";
export const PAT_ARG = "--personalAccessToken";

export const STATUS = new CLICommand([ "status" ]);
export const UPGRADE = new CLICommand([ "upgrade" ]);
Expand Down
4 changes: 2 additions & 2 deletions dev/src/codewind/cli/CLILifecycleWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export namespace CLILifecycleWrapper {
Log.i("Installing Codewind");

const installAffirmBtn = Translator.t(STRING_NS, "installAffirmBtn");
const moreInfoBtn = Translator.t(StringNamespaces.ACTIONS, "moreInfoBtn");
const moreInfoBtn = Translator.t(StringNamespaces.ACTIONS, "moreInfo");

let response;
if (!promptForInstall || MCUtil.isTestEnv()) {
Expand Down Expand Up @@ -307,7 +307,7 @@ export namespace CLILifecycleWrapper {
else {
msg = Translator.t(STRING_NS, "installFailed");
}
const moreInfoBtn = Translator.t(STRING_NS, "moreInfoBtn");
const moreInfoBtn = Translator.t(STRING_NS, "moreInfo");
const tryAgainBtn = Translator.t(StringNamespaces.STARTUP, "tryAgainBtn");

return vscode.window.showWarningMessage(msg, moreInfoBtn, tryAgainBtn, Translator.t(STRING_NS, "okBtn"))
Expand Down
2 changes: 1 addition & 1 deletion dev/src/codewind/cli/CLIWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace CLIWrapper {
// Build the 'cmdStr' which is the full command printed for debugging.
// If the command contains a user password we have to censor it.
const argsCopy = Array.from(args);
const pwIndex = args.findIndex((arg) => arg === CLICommands.PASSWORD_ARG);
const pwIndex = args.findIndex((arg) => arg === CLICommands.PASSWORD_ARG || arg === CLICommands.PAT_ARG);
if (pwIndex >= 0) {
argsCopy[pwIndex + 1] = "********";
}
Expand Down
6 changes: 3 additions & 3 deletions dev/src/codewind/connection/TemplateSourceList.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Connection from "./Connection";
import { CLICommandRunner } from "../cli/CLICommandRunner";
import { TemplateSource, SourceEnablement } from "../Types";
import { TemplateSource, SourceEnablement, NewTemplateSource } from "../Types";

export enum SourceProjectStyles {
CODEWIND = "Codewind",
Expand Down Expand Up @@ -55,8 +55,8 @@ export default class TemplateSourcesList {
}, []);
}

public async add(url: string, name: string, description: string | undefined): Promise<TemplateSource[]> {
this.templateSources = await CLICommandRunner.addTemplateSource(this.connection.id, url, name, description);
public async add(newSource: NewTemplateSource): Promise<TemplateSource[]> {
this.templateSources = await CLICommandRunner.addTemplateSource(this.connection.id, newSource);
return this.templateSources;
}

Expand Down
Loading

0 comments on commit 6974d85

Please sign in to comment.