forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workplace Search] Add a technical preview of connecting GitHub via G…
…itHub apps (elastic#119764) * Add new routes Render the new github_via_app component on the new routes (added in future commits). Use isGithubEnterpriseServer prop as differentiator between github and github enterprise server * Add readUploadedFileAsText * Add new view and logic for creating a GitHub content source via GitHub apps Also rename github_app to github_via_app to match service_type on backend * Make editPath (path to connector settings) optional as it is not available for GitHub apps which are configured on a source level * Update source_settings and source_logic to include configuration for new source types. Add new "secret" field to ContentSourceFullData and mocks * Rename indexPermissions to index_permissions * Extract handlePrivateKeyUpload into a utility function * Extract `github_via_app` and `github_enterprise_server_via_app` to constants * Add a basic validation: submit button is disabled if fields are empty * Address PR feedback * Do not rely on baseUrl field emptyness to define the service type Rely on explicit parameter instead * Add icons to the new GitHub service types * Fix a bug where indexPermissionsValue was true even on basic license. The solution copied from the add_source component. Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
Showing
21 changed files
with
456 additions
and
87 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
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
21 changes: 21 additions & 0 deletions
21
...enterprise_search/public/applications/workplace_search/utils/handle_private_key_upload.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,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { readUploadedFileAsText } from './read_uploaded_file_as_text'; | ||
|
||
export const handlePrivateKeyUpload = async ( | ||
files: FileList | null, | ||
callback: (text: string) => void | ||
) => { | ||
if (!files || files.length < 1) { | ||
return null; | ||
} | ||
const file = files[0]; | ||
const text = await readUploadedFileAsText(file); | ||
|
||
callback(text); | ||
}; |
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
22 changes: 22 additions & 0 deletions
22
...nterprise_search/public/applications/workplace_search/utils/read_uploaded_file_as_text.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,22 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const readUploadedFileAsText = (fileInput: File): Promise<string> => { | ||
const reader = new FileReader(); | ||
|
||
return new Promise((resolve, reject) => { | ||
reader.onload = () => { | ||
resolve(reader.result as string); | ||
}; | ||
try { | ||
reader.readAsText(fileInput); | ||
} catch { | ||
reader.abort(); | ||
reject(new Error()); | ||
} | ||
}); | ||
}; |
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
64 changes: 0 additions & 64 deletions
64
.../applications/workplace_search/views/content_sources/components/add_source/github_app.tsx
This file was deleted.
Oops, something went wrong.
128 changes: 128 additions & 0 deletions
128
...lications/workplace_search/views/content_sources/components/add_source/github_via_app.tsx
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,128 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
import type { FormEvent } from 'react'; | ||
|
||
import { useValues, useActions } from 'kea'; | ||
|
||
import { | ||
EuiHorizontalRule, | ||
EuiPanel, | ||
EuiSpacer, | ||
EuiFieldText, | ||
EuiFormRow, | ||
EuiFilePicker, | ||
EuiButton, | ||
} from '@elastic/eui'; | ||
|
||
import { LicensingLogic } from '../../../../../shared/licensing'; | ||
import { AppLogic } from '../../../../app_logic'; | ||
|
||
import { | ||
WorkplaceSearchPageTemplate, | ||
PersonalDashboardLayout, | ||
} from '../../../../components/layout'; | ||
import { NAV, SOURCE_NAMES } from '../../../../constants'; | ||
import { handlePrivateKeyUpload } from '../../../../utils'; | ||
|
||
import { staticSourceData } from '../../source_data'; | ||
|
||
import { AddSourceHeader } from './add_source_header'; | ||
import { DocumentPermissionsCallout } from './document_permissions_callout'; | ||
import { DocumentPermissionsField } from './document_permissions_field'; | ||
import { GithubViaAppLogic } from './github_via_app_logic'; | ||
import { SourceFeatures } from './source_features'; | ||
|
||
interface GithubViaAppProps { | ||
isGithubEnterpriseServer: boolean; | ||
} | ||
|
||
export const GitHubViaApp: React.FC<GithubViaAppProps> = ({ isGithubEnterpriseServer }) => { | ||
const { isOrganization } = useValues(AppLogic); | ||
const { githubAppId, githubEnterpriseServerUrl, isSubmitButtonLoading, indexPermissionsValue } = | ||
useValues(GithubViaAppLogic); | ||
const { | ||
setGithubAppId, | ||
setGithubEnterpriseServerUrl, | ||
setStagedPrivateKey, | ||
createContentSource, | ||
setSourceIndexPermissionsValue, | ||
} = useActions(GithubViaAppLogic); | ||
|
||
const { hasPlatinumLicense } = useValues(LicensingLogic); | ||
const name = isGithubEnterpriseServer ? SOURCE_NAMES.GITHUB_ENTERPRISE : SOURCE_NAMES.GITHUB; | ||
const data = staticSourceData.find((source) => source.name === name); | ||
const Layout = isOrganization ? WorkplaceSearchPageTemplate : PersonalDashboardLayout; | ||
|
||
const handleSubmit = (e: FormEvent) => { | ||
e.preventDefault(); | ||
createContentSource(isGithubEnterpriseServer); | ||
}; | ||
|
||
// Default indexPermissions to true, if needed | ||
useEffect(() => { | ||
setSourceIndexPermissionsValue(isOrganization && hasPlatinumLicense); | ||
}, []); | ||
|
||
return ( | ||
<Layout pageChrome={[NAV.SOURCES, NAV.ADD_SOURCE, name || '...']} isLoading={false}> | ||
<form onSubmit={handleSubmit}> | ||
<EuiPanel paddingSize="none" hasShadow={false} color="subdued"> | ||
<EuiPanel hasShadow={false} paddingSize="l" color="subdued"> | ||
<AddSourceHeader | ||
name={name} | ||
serviceType="github" | ||
categories={['Software', 'Version Control', 'Code Repository']} // TODO: get from API | ||
/> | ||
</EuiPanel> | ||
<EuiHorizontalRule margin="xs" /> | ||
<EuiPanel hasShadow={false} paddingSize="l" color="subdued"> | ||
<SourceFeatures features={data!.features} name={name} objTypes={data!.objTypes} /> | ||
</EuiPanel> | ||
</EuiPanel> | ||
|
||
<EuiSpacer /> | ||
|
||
{!hasPlatinumLicense && <DocumentPermissionsCallout />} | ||
{hasPlatinumLicense && isOrganization && ( | ||
<DocumentPermissionsField | ||
needsPermissions | ||
indexPermissionsValue={indexPermissionsValue} | ||
setValue={setSourceIndexPermissionsValue} | ||
/> | ||
)} | ||
|
||
<EuiFormRow label="GitHub App ID"> | ||
<EuiFieldText value={githubAppId} onChange={(e) => setGithubAppId(e.target.value)} /> | ||
</EuiFormRow> | ||
{isGithubEnterpriseServer && ( | ||
<EuiFormRow label="Base URL"> | ||
<EuiFieldText | ||
value={githubEnterpriseServerUrl} | ||
onChange={(e) => setGithubEnterpriseServerUrl(e.target.value)} | ||
/> | ||
</EuiFormRow> | ||
)} | ||
<EuiFormRow label="Private key" helpText="Upload private key (.pem) to authenticate GitHub"> | ||
<EuiFilePicker | ||
onChange={(files) => handlePrivateKeyUpload(files, setStagedPrivateKey)} | ||
accept=".pem" | ||
/> | ||
</EuiFormRow> | ||
<EuiButton | ||
fill | ||
type="submit" | ||
isLoading={isSubmitButtonLoading} | ||
isDisabled={!githubAppId || (isGithubEnterpriseServer && !githubEnterpriseServerUrl)} | ||
> | ||
{isSubmitButtonLoading ? 'Connecting…' : `Connect ${name}`} | ||
</EuiButton> | ||
</form> | ||
</Layout> | ||
); | ||
}; |
Oops, something went wrong.