]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13524 Add clientId and clientSecret
authorJeremy Davis <jeremy.davis@sonarsource.com>
Fri, 12 Jun 2020 15:39:52 +0000 (17:39 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 1 Jul 2020 20:05:53 +0000 (20:05 +0000)
server/sonar-web/src/main/js/apps/settings/components/almIntegration/GithubForm.tsx
server/sonar-web/src/main/js/apps/settings/components/almIntegration/GithubTab.tsx
server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionForm-test.tsx
server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/GithubForm-test.tsx
server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmTabRenderer-test.tsx.snap
server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/GithubForm-test.tsx.snap
server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/GithubTab-test.tsx.snap
server/sonar-web/src/main/js/helpers/mocks/alm-settings.ts
server/sonar-web/src/main/js/types/alm-settings.ts
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index c4fd9afee57975f2b04c892d1c37776519d4383f..d1a3cb3908937851402922e8824387cf40c85460 100644 (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}
index bdeb29f3c896860d1128a45ba087bc75a26f3c50..0a98795b0dc57c7b2e1ebd926241ec8e30b03e27 100644 (file)
  * 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} />}
index e532eb6775940794335d5a08600847077c06402a..b0f8a5ab183cff35feefadf222add24b57279d94 100644 (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}>
index e67edb9e294dcf1fe90c984ab8955b498f48bd8d..5b1a75666ea7380f777de5cdbfc4f5a55a4039f6 100644 (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}
     />
index 5f59a757faa3c86a36b87d5db45ebc564ff24a79..75b36f0c52c73927acb68a642d0dd1d3a9a71263 100644 (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",
index 4015c170435a00e724ebc2d5504279acb3280a60..e64c54eb13688c8d14bf044b9a9aeba7aab89c3a 100644 (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}
index bab4629b9d0f5712e6892a4e3708437738191962..60db1f5eb30bd14883ac9c7a5356dd5892feb144 100644 (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]}
index 2a495addc9d2ab1553d242feba4e5f19b8f7fd36..3ca33106b3315d52e32757f4752d55df013aeb25 100644 (file)
@@ -66,6 +66,8 @@ export function mockGithubBindingDefinition(
     key: 'key',
     url: 'http://github.enterprise.com',
     appId: '123456',
+    clientId: 'client1',
+    clientSecret: '**clientsecret**',
     privateKey: 'asdf1234',
     ...overrides
   };
index 534471f4741cdc9a2ee3fcb37dddbbe0848f5357..10030182e07350dd8f4ef031b29fcbe773f75689 100644 (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;
 }
index 03d6729ba44b81ab76c9edd8f93f349622589e54..99d6119ead352b677a4c07dae60a36a35f7dec46 100644 (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}