Browse Source

SONAR-13524 Add clientId and clientSecret

tags/8.4.0.35506
Jeremy Davis 4 years ago
parent
commit
7a8da9668d

+ 16
- 0
server/sonar-web/src/main/js/apps/settings/components/almIntegration/GithubForm.tsx View File

@@ -73,6 +73,22 @@ export default function GithubForm(props: GithubFormProps) {
readOnly={readOnly}
value={formData.appId}
/>
<AlmBindingDefinitionFormField
id="client_id"
maxLength={80}
onFieldChange={onFieldChange}
propKey="clientId"
readOnly={readOnly}
value={formData.clientId}
/>
<AlmBindingDefinitionFormField
id="client_secret"
maxLength={80}
onFieldChange={onFieldChange}
propKey="clientSecret"
readOnly={readOnly}
value={formData.clientSecret}
/>
<AlmBindingDefinitionFormField
id="private_key"
isTextArea={true}

+ 58
- 2
server/sonar-web/src/main/js/apps/settings/components/almIntegration/GithubTab.tsx View File

@@ -18,7 +18,10 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
import { translate } from 'sonar-ui-common/helpers/l10n';
import { FormattedMessage } from 'react-intl';
import WarningIcon from 'sonar-ui-common/components/icons/WarningIcon';
import { Alert } from 'sonar-ui-common/components/ui/Alert';
import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n';
import { createGithubConfiguration, updateGithubConfiguration } from '../../../../api/alm-settings';
import { AlmKeys, GithubBindingDefinition } from '../../../../types/alm-settings';
import { ALM_INTEGRATION } from '../AdditionalCategoryKeys';
@@ -57,9 +60,31 @@ export default function GithubTab(props: GithubTabProps) {
translate('settings.almintegration.table.column.app_id')
]}
additionalColumnsKeys={['url', 'appId']}
additionalTableInfo={
<Alert className="big-spacer-bottom width-50" variant="info">
<FormattedMessage
defaultMessage={translate(
'settings.almintegration.feature.alm_repo_import.disabled_if_multiple_github_instances'
)}
id="settings.almintegration.feature.alm_repo_import.disabled_if_multiple_github_instances"
values={{
feature: (
<em>{translate('settings.almintegration.feature.alm_repo_import.title')}</em>
)
}}
/>
</Alert>
}
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 ? (
<>
<WarningIcon className="little-spacer-right" />
<FormattedMessage
id="settings.almintegration.feature.alm_repo_import.github.requires_fields"
defaultMessage={translate(
'settings.almintegration.feature.alm_repo_import.github.requires_fields'
)}
values={{
clientId: <strong>clientId</strong>,
clientSecret: <strong>clientSecret</strong>
}}
/>
</>
) : (
translateWithParameters(
'settings.almintegration.feature.alm_repo_import.github.too_many_instances_x',
definitions.length
)
)
}
]}
form={childProps => <GithubForm {...childProps} />}

+ 24
- 2
server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionForm-test.tsx View File

@@ -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<AlmBindingDefinitionForm<GithubBindingDefinition>>(
<AlmBindingDefinitionForm
bindingDefinition={{ appId: '', key: '', privateKey: '', url: '' }}
bindingDefinition={{
appId: '',
clientId: '',
clientSecret: '',
key: '',
privateKey: '',
url: ''
}}
onCancel={jest.fn()}
onSubmit={jest.fn()}
{...props}>

+ 1
- 1
server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/GithubForm-test.tsx View File

@@ -30,7 +30,7 @@ it('should render correctly', () => {
function shallowRender(props: Partial<GithubFormProps> = {}) {
return shallow(
<GithubForm
formData={{ key: '', appId: '', privateKey: '', url: '' }}
formData={{ key: '', appId: '', clientId: '', clientSecret: '', privateKey: '', url: '' }}
onFieldChange={jest.fn()}
{...props}
/>

+ 8
- 0
server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmTabRenderer-test.tsx.snap View File

@@ -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",

+ 28
- 0
server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/GithubForm-test.tsx.snap View File

@@ -40,6 +40,20 @@ exports[`should render correctly 1`] = `
propKey="appId"
value=""
/>
<AlmBindingDefinitionFormField
id="client_id"
maxLength={80}
onFieldChange={[MockFunction]}
propKey="clientId"
value=""
/>
<AlmBindingDefinitionFormField
id="client_secret"
maxLength={80}
onFieldChange={[MockFunction]}
propKey="clientSecret"
value=""
/>
<AlmBindingDefinitionFormField
id="private_key"
isTextArea={true}
@@ -90,6 +104,20 @@ exports[`should render correctly 2`] = `
propKey="appId"
value="123456"
/>
<AlmBindingDefinitionFormField
id="client_id"
maxLength={80}
onFieldChange={[MockFunction]}
propKey="clientId"
value="client1"
/>
<AlmBindingDefinitionFormField
id="client_secret"
maxLength={80}
onFieldChange={[MockFunction]}
propKey="clientSecret"
value="**clientsecret**"
/>
<AlmBindingDefinitionFormField
id="private_key"
isTextArea={true}

+ 46
- 0
server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/GithubTab-test.tsx.snap View File

@@ -17,11 +17,31 @@ exports[`should render correctly: with branch support 1`] = `
"appId",
]
}
additionalTableInfo={
<Alert
className="big-spacer-bottom width-50"
variant="info"
>
<FormattedMessage
defaultMessage="settings.almintegration.feature.alm_repo_import.disabled_if_multiple_github_instances"
id="settings.almintegration.feature.alm_repo_import.disabled_if_multiple_github_instances"
values={
Object {
"feature": <em>
settings.almintegration.feature.alm_repo_import.title
</em>,
}
}
/>
</Alert>
}
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": <React.Fragment>
<WarningIcon
className="little-spacer-right"
/>
<FormattedMessage
defaultMessage="settings.almintegration.feature.alm_repo_import.github.requires_fields"
id="settings.almintegration.feature.alm_repo_import.github.requires_fields"
values={
Object {
"clientId": <strong>
clientId
</strong>,
"clientSecret": <strong>
clientSecret
</strong>,
}
}
/>
</React.Fragment>,
"name": "settings.almintegration.feature.alm_repo_import.title",
},
]
}
form={[Function]}

+ 2
- 0
server/sonar-web/src/main/js/helpers/mocks/alm-settings.ts View File

@@ -66,6 +66,8 @@ export function mockGithubBindingDefinition(
key: 'key',
url: 'http://github.enterprise.com',
appId: '123456',
clientId: 'client1',
clientSecret: '**clientsecret**',
privateKey: 'asdf1234',
...overrides
};

+ 2
- 0
server/sonar-web/src/main/js/types/alm-settings.ts View File

@@ -39,6 +39,8 @@ export interface BitbucketBindingDefinition extends AlmBindingDefinition {

export interface GithubBindingDefinition extends AlmBindingDefinition {
appId: string;
clientId: string;
clientSecret: string;
privateKey: string;
url: string;
}

+ 6
- 0
sonar-core/src/main/resources/org/sonar/l10n/core.properties View File

@@ -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}

Loading…
Cancel
Save