diff --git a/ui/src/app/settings/components/repos-list/repos-list.scss b/ui/src/app/settings/components/repos-list/repos-list.scss index e53efea671..583e9956d6 100644 --- a/ui/src/app/settings/components/repos-list/repos-list.scss +++ b/ui/src/app/settings/components/repos-list/repos-list.scss @@ -32,4 +32,12 @@ float: right; } } + + textarea.argo-field { + height: 20em; + width: 1024em; + white-space: pre; + overflow-wrap: normal; + overflow-x: scroll; + } } diff --git a/ui/src/app/settings/components/repos-list/repos-list.tsx b/ui/src/app/settings/components/repos-list/repos-list.tsx index 0f146dddf3..780cb40ef8 100644 --- a/ui/src/app/settings/components/repos-list/repos-list.tsx +++ b/ui/src/app/settings/components/repos-list/repos-list.tsx @@ -1,7 +1,7 @@ import {DropDownMenu, FormField, NotificationType, SlidingPanel} from 'argo-ui'; import * as PropTypes from 'prop-types'; import * as React from 'react'; -import {Form, FormApi, Text} from 'react-form'; +import {Form, FormApi, Text, TextArea} from 'react-form'; import {RouteComponentProps} from 'react-router'; import {CheckboxField, ConnectionStateIcon, DataLoader, EmptyState, ErrorNotification, Page} from '../../../shared/components'; @@ -12,10 +12,19 @@ import {services} from '../../../shared/services'; require('./repos-list.scss'); -interface NewRepoParams { +interface NewSSHRepoParams { + url: string; + sshPrivateKey: string; + insecure: boolean; + enableLfs: boolean; +} + +interface NewHTTPSRepoParams { url: string; username: string; password: string; + tlsClientCertData: string; + tlsClientCertKey: string; insecure: boolean; enableLfs: boolean; } @@ -27,7 +36,8 @@ export class ReposList extends React.Component> { history: PropTypes.object, }; - private formApi: FormApi; + private formApiSSH: FormApi; + private formApiHTTPS: FormApi; private loader: DataLoader; public render() { @@ -37,8 +47,11 @@ export class ReposList extends React.Component> { actionMenu: { className: 'fa fa-plus', items: [{ - title: 'Connect Repo', - action: () => this.showConnectRepo = true, + title: 'Connect Repo using SSH', + action: () => this.showConnectSSHRepo = true, + }, { + title: 'Connect Repo using HTTPS', + action: () => this.showConnectHTTPSRepo = true, }], }, }}> @@ -84,7 +97,9 @@ export class ReposList extends React.Component> {

No repositories connected

Connect your repo to deploy apps.
) @@ -92,35 +107,77 @@ export class ReposList extends React.Component> { - this.showConnectRepo = false} header={( + this.showConnectHTTPSRepo = false} header={(
- -
)}> -

Connect Git repo

-
this.connectRepo(params as NewRepoParams)} - getApi={(api) => this.formApi = api} - validateError={(params: NewRepoParams) => ({ +

Connect Git repo using HTTPS

+ this.connectHTTPSRepo(params as NewHTTPSRepoParams)} + getApi={(api) => this.formApiHTTPS = api} + validateError={(params: NewHTTPSRepoParams) => ({ url: !params.url && 'Repo URL is required', + password: !params.password && params.username && 'Password is required if username is given.', + tlsClientCertKey: !params.tlsClientCertKey && params.tlsClientCertData && 'TLS client cert key is required if TLS client cert is given.', })}> {(formApi) => ( - +
- +
-
+
+ +
+
+ +
+
+ +
+
+ +
+
+ )} + +
+ this.showConnectSSHRepo = false} header={( +
+ +
+ )}> +

Connect Git repo using SSH

+
this.connectSSHRepo(params as NewSSHRepoParams)} + getApi={(api) => this.formApiSSH = api} + validateError={(params: NewSSHRepoParams) => ({ + url: !params.url && 'Repo URL is required', + sshPrivateKey: !params.sshPrivateKey && 'SSH private key data is required for connecting SSH repositories', + })}> + {(formApi) => ( + +
+ +
+
+ +
@@ -135,10 +192,41 @@ export class ReposList extends React.Component> { ); } - private async connectRepo(params: NewRepoParams) { + /* + private isHTTPSUrl(url: string) { + if (url.match(/^https:\/\/.*$/gi)) { + return true; + } else { + return false; + } + } + */ + + private clearConnectSSHForm() { + this.formApiSSH.resetAll(); + } + + private clearConnectHTTPSForm() { + this.formApiHTTPS.resetAll(); + } + + private async connectSSHRepo(params: NewSSHRepoParams) { try { - await services.repos.create(params); - this.showConnectRepo = false; + await services.repos.createSSH(params); + this.showConnectSSHRepo = false; + this.loader.reload(); + } catch (e) { + this.appContext.apis.notifications.show({ + content: , + type: NotificationType.Error, + }); + } + } + + private async connectHTTPSRepo(params: NewHTTPSRepoParams) { + try { + await services.repos.createHTTPS(params); + this.showConnectSSHRepo = false; this.loader.reload(); } catch (e) { this.appContext.apis.notifications.show({ @@ -157,12 +245,22 @@ export class ReposList extends React.Component> { } } - private get showConnectRepo() { - return new URLSearchParams(this.props.location.search).get('addRepo') === 'true'; + private get showConnectHTTPSRepo() { + return new URLSearchParams(this.props.location.search).get('addHTTPSRepo') === 'true'; } - private set showConnectRepo(val: boolean) { - this.appContext.router.history.push(`${this.props.match.url}?addRepo=${val}`); + private set showConnectHTTPSRepo(val: boolean) { + this.clearConnectHTTPSForm(); + this.appContext.router.history.push(`${this.props.match.url}?addHTTPSRepo=${val}`); + } + + private get showConnectSSHRepo() { + return new URLSearchParams(this.props.location.search).get('addSSHRepo') === 'true'; + } + + private set showConnectSSHRepo(val: boolean) { + this.clearConnectSSHForm(); + this.appContext.router.history.push(`${this.props.match.url}?addSSHRepo=${val}`); } private get appContext(): AppContext { diff --git a/ui/src/app/shared/services/repo-service.ts b/ui/src/app/shared/services/repo-service.ts index 14a36553e5..7a24c92949 100644 --- a/ui/src/app/shared/services/repo-service.ts +++ b/ui/src/app/shared/services/repo-service.ts @@ -6,9 +6,16 @@ export class RepositoriesService { return requests.get('/repositories').then((res) => res.body as models.RepositoryList).then((list) => list.items || []); } - public create({url, username, password, insecure, enableLfs}: - {url: string, username: string, password: string, insecure: boolean, enableLfs: boolean}): Promise { - return requests.post('/repositories').send({ repo: url, username, password, insecure, enableLfs }).then((res) => res.body as models.Repository); + public createHTTPS({url, username, password, tlsClientCertData, tlsClientCertKey, insecure, enableLfs}: + {url: string, username: string, password: string, tlsClientCertData: string, tlsClientCertKey: string, + insecure: boolean, enableLfs: boolean}): Promise { + return requests.post('/repositories').send({ repo: url, username, password, tlsClientCertData, tlsClientCertKey, insecure, enableLfs }) + .then((res) => res.body as models.Repository); + } + + public createSSH({url, sshPrivateKey, insecure, enableLfs}: + {url: string, sshPrivateKey: string, insecure: boolean, enableLfs: boolean}): Promise { + return requests.post('/repositories').send({ repo: url, sshPrivateKey, insecure, enableLfs }).then((res) => res.body as models.Repository); } public delete(url: string): Promise {