From: Jeremy Davis Date: Fri, 12 Jun 2020 15:39:52 +0000 (+0200) Subject: SONAR-13524 Add clientId and clientSecret X-Git-Tag: 8.4.0.35506~12 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7a8da9668dc5101503bcf6ba3393c0b1c162172d;p=sonarqube.git SONAR-13524 Add clientId and clientSecret --- diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/GithubForm.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/GithubForm.tsx index c4fd9afee57..d1a3cb39089 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/GithubForm.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/GithubForm.tsx @@ -73,6 +73,22 @@ export default function GithubForm(props: GithubFormProps) { readOnly={readOnly} value={formData.appId} /> + + + {translate('settings.almintegration.feature.alm_repo_import.title')} + ) + }} + /> + + } alm={AlmKeys.GitHub} createConfiguration={createGithubConfiguration} - defaultBinding={{ key: '', appId: '', url: '', privateKey: '' }} + defaultBinding={{ + key: '', + appId: '', + clientId: '', + clientSecret: '', + url: '', + privateKey: '' + }} definitions={definitions} features={[ { @@ -67,6 +92,37 @@ export default function GithubTab(props: GithubTabProps) { active: definitions.length > 0, description: translate('settings.almintegration.feature.pr_decoration.description'), inactiveReason: translate('settings.almintegration.feature.need_at_least_1_binding') + }, + { + name: translate('settings.almintegration.feature.alm_repo_import.title'), + active: + definitions.length === 1 && + !!definitions[0].clientId && + !!definitions[0].clientSecret, + description: translate( + 'settings.almintegration.feature.alm_repo_import.description' + ), + inactiveReason: + definitions.length === 1 ? ( + <> + + clientId, + clientSecret: clientSecret + }} + /> + + ) : ( + translateWithParameters( + 'settings.almintegration.feature.alm_repo_import.github.too_many_instances_x', + definitions.length + ) + ) } ]} form={childProps => } diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionForm-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionForm-test.tsx index e532eb67759..b0f8a5ab183 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionForm-test.tsx @@ -47,12 +47,16 @@ it('should handle field changes', () => { key: 'github - example', url: 'http://github.com', appId: '34812568251', + clientId: 'cid', + clientSecret: 'csecret', privateKey: 'gs7df9g7d9fsg7x9df7g9xdg' }; wrapper.instance().handleFieldChange('key', formData.key); wrapper.instance().handleFieldChange('url', formData.url); wrapper.instance().handleFieldChange('appId', formData.appId); + wrapper.instance().handleFieldChange('clientId', formData.clientId); + wrapper.instance().handleFieldChange('clientSecret', formData.clientSecret); wrapper.instance().handleFieldChange('privateKey', formData.privateKey); expect(wrapper.state().formData).toEqual(formData); }); @@ -61,12 +65,21 @@ it('should handle form submit', async () => { const onSubmit = jest.fn(); const wrapper = shallowRender({ onSubmit, - bindingDefinition: { key: 'originalKey', appId: '', privateKey: '', url: '' } + bindingDefinition: { + key: 'originalKey', + appId: '', + clientId: '', + clientSecret: '', + privateKey: '', + url: '' + } }); const formData = { key: 'github instance', url: 'http://github.enterprise.com', appId: '34812568251', + clientId: 'client1234', + clientSecret: 'secret', privateKey: 'gs7df9g7d9fsg7x9df7g9xdg' }; wrapper.setState({ formData }); @@ -81,6 +94,8 @@ it('should handle cancelling', () => { const onCancel = jest.fn(); const bindingDefinition = { appId: 'foo', + clientId: 'cid', + clientSecret: 'cs', key: 'bar', privateKey: 'baz', url: 'http://github.enterprise.com' @@ -130,7 +145,14 @@ function shallowRender( ) { return shallow>( diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/GithubForm-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/GithubForm-test.tsx index e67edb9e294..5b1a75666ea 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/GithubForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/GithubForm-test.tsx @@ -30,7 +30,7 @@ it('should render correctly', () => { function shallowRender(props: Partial = {}) { return shallow( diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmTabRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmTabRenderer-test.tsx.snap index 5f59a757faa..75b36f0c52c 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmTabRenderer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmTabRenderer-test.tsx.snap @@ -36,6 +36,8 @@ exports[`should render correctly for multi-ALM binding: editing a definition 1`] bindingDefinition={ Object { "appId": "123456", + "clientId": "client1", + "clientSecret": "**clientsecret**", "key": "key", "privateKey": "asdf1234", "url": "http://github.enterprise.com", @@ -282,6 +284,8 @@ exports[`should render correctly for single-ALM binding 1`] = ` bindingDefinition={ Object { "appId": "123456", + "clientId": "client1", + "clientSecret": "**clientsecret**", "key": "key", "privateKey": "asdf1234", "url": "http://github.enterprise.com", @@ -327,6 +331,8 @@ exports[`should render correctly for single-ALM binding 2`] = ` bindingDefinition={ Object { "appId": "123456", + "clientId": "client1", + "clientSecret": "**clientsecret**", "key": "key", "privateKey": "asdf1234", "url": "http://github.enterprise.com", @@ -372,6 +378,8 @@ exports[`should render correctly for single-ALM binding 3`] = ` bindingDefinition={ Object { "appId": "123456", + "clientId": "client1", + "clientSecret": "**clientsecret**", "key": "key", "privateKey": "asdf1234", "url": "http://github.enterprise.com", diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/GithubForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/GithubForm-test.tsx.snap index 4015c170435..e64c54eb136 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/GithubForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/GithubForm-test.tsx.snap @@ -40,6 +40,20 @@ exports[`should render correctly 1`] = ` propKey="appId" value="" /> + + + + + + settings.almintegration.feature.alm_repo_import.title + , + } + } + /> + + } alm="github" createConfiguration={[Function]} defaultBinding={ Object { "appId": "", + "clientId": "", + "clientSecret": "", "key": "", "privateKey": "", "url": "", @@ -31,6 +51,8 @@ exports[`should render correctly: with branch support 1`] = ` Array [ Object { "appId": "123456", + "clientId": "client1", + "clientSecret": "**clientsecret**", "key": "key", "privateKey": "asdf1234", "url": "http://github.enterprise.com", @@ -45,6 +67,30 @@ exports[`should render correctly: with branch support 1`] = ` "inactiveReason": "settings.almintegration.feature.need_at_least_1_binding", "name": "settings.almintegration.feature.pr_decoration.title", }, + Object { + "active": true, + "description": "settings.almintegration.feature.alm_repo_import.description", + "inactiveReason": + + + clientId + , + "clientSecret": + clientSecret + , + } + } + /> + , + "name": "settings.almintegration.feature.alm_repo_import.title", + }, ] } form={[Function]} diff --git a/server/sonar-web/src/main/js/helpers/mocks/alm-settings.ts b/server/sonar-web/src/main/js/helpers/mocks/alm-settings.ts index 2a495addc9d..3ca33106b33 100644 --- a/server/sonar-web/src/main/js/helpers/mocks/alm-settings.ts +++ b/server/sonar-web/src/main/js/helpers/mocks/alm-settings.ts @@ -66,6 +66,8 @@ export function mockGithubBindingDefinition( key: 'key', url: 'http://github.enterprise.com', appId: '123456', + clientId: 'client1', + clientSecret: '**clientsecret**', privateKey: 'asdf1234', ...overrides }; diff --git a/server/sonar-web/src/main/js/types/alm-settings.ts b/server/sonar-web/src/main/js/types/alm-settings.ts index 534471f4741..10030182e07 100644 --- a/server/sonar-web/src/main/js/types/alm-settings.ts +++ b/server/sonar-web/src/main/js/types/alm-settings.ts @@ -39,6 +39,8 @@ export interface BitbucketBindingDefinition extends AlmBindingDefinition { export interface GithubBindingDefinition extends AlmBindingDefinition { appId: string; + clientId: string; + clientSecret: string; privateKey: string; url: string; } diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 03d6729ba44..99d6119ead3 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1061,6 +1061,8 @@ settings.almintegration.form.url.gitlab=GitLab URL settings.almintegration.form.url.gitlab.help1=You do not have to provide this value if you're using GitLab CI. settings.almintegration.form.url.gitlab.help2=If you're using another CI, provide the GitLab API URL. For example: settings.almintegration.form.app_id=GitHub App ID +settings.almintegration.form.client_id=GitHub Client ID +settings.almintegration.form.client_secret=GitHub Client Secret settings.almintegration.form.private_key=Private Key settings.almintegration.form.personal_access_token=Personal Access token settings.almintegration.form.personal_access_token.azure.help=Token of the user that will be used to decorate the Pull Requests. Needs authorized scope: "Code (read and write)". @@ -1078,6 +1080,10 @@ settings.almintegration.feature.mr_decoration.description=Add analysis and a Qua settings.almintegration.feature.alm_repo_import.title=Import repositories from your ALM settings.almintegration.feature.alm_repo_import.description=Select repositories from your ALM, and import them into SonarQube. settings.almintegration.feature.alm_repo_import.disabled_if_multiple_bbs_instances=Connecting to multiple Bitbucket Server instances will deactivate the {feature} feature. Projects will have to be set up manually. +settings.almintegration.feature.alm_repo_import.disabled_if_multiple_github_instances=Connecting to multiple GitHub Enterprise instances will deactivate the {feature} feature. Projects will have to be set up manually. +settings.almintegration.feature.alm_repo_import.github.too_many_instances_x=You must have exactly 1 GitHub Enterprise instance configured in order to use this method. You currently have {0}. +settings.almintegration.feature.alm_repo_import.github.requires_fields=Your configured instance must be provided with the App's {clientId} and {clientSecret}. + settings.pr_decoration.binding.category=Pull Request Decoration settings.pr_decoration.binding.no_bindings=This feature must first be enabled in the global settings. {link}