Skip to content

Commit 92f8bf1

Browse files
authored
Merge pull request #1351 from GnsP/support-bitbucket-http-auth
[CDAP-21200] Add authType HTTP_ACCESS_TOKEN for BITBUCKET_SERVER
2 parents ad14c38 + feeb4c4 commit 92f8bf1

File tree

6 files changed

+118
-61
lines changed

6 files changed

+118
-61
lines changed

app/cdap/components/NamespaceAdmin/SourceControlManagement/SourceControlManagementForm.tsx

Lines changed: 70 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ import { ISourceControlManagementConfig } from './types';
2121
import PrimaryContainedButton from 'components/shared/Buttons/PrimaryContainedButton';
2222
import PrimaryOutlinedButton from 'components/shared/Buttons/PrimaryOutlinedButton';
2323
import ButtonLoadingHoc from 'components/shared/Buttons/ButtonLoadingHoc';
24-
import { authKeys, githubOnlyProviders, patConfigKeys, providers, scmAuthType } from './constants';
24+
import {
25+
SCM_AUTH_TYPE_PAT,
26+
authKeys,
27+
githubOnlyProviders,
28+
patConfigKeys,
29+
providers,
30+
scmAuthType,
31+
} from './constants';
2532
import { defaultSourceControlManagement, sourceControlManagementFormReducer } from './reducer';
2633
import { addOrValidateSourceControlManagementForm } from '../store/ActionCreator';
2734
import { getCurrentNamespace } from 'services/NamespaceStore';
@@ -95,6 +102,9 @@ const SourceControlManagementForm = ({
95102
defaultSourceControlManagement
96103
);
97104

105+
const supportedAuthTypes =
106+
formState?.config?.provider === 'BITBUCKET_SERVER' ? scmAuthType : [SCM_AUTH_TYPE_PAT];
107+
98108
const getMissingFieldsCount = () => {
99109
let count = 0;
100110
if (!formState.config?.link) {
@@ -293,74 +303,77 @@ const SourceControlManagementForm = ({
293303
<BoldHeader>{T.translate(`${PREFIX}.authHeader`)}</BoldHeader>
294304
<StyledHr />
295305
<PropertyRow
296-
value={formState.config?.auth?.type ? formState.config.auth.type : scmAuthType[0].id}
306+
value={
307+
formState.config?.auth?.type ? formState.config.auth.type : supportedAuthTypes[0].id
308+
}
297309
property={{
298310
name: 'auth',
299-
description: T.translate(`${PREFIX}.auth.helperText`).toString(),
311+
description:
312+
supportedAuthTypes.length === 1
313+
? T.translate(`${PREFIX}.auth.helperTextPatOnly`, {
314+
provider: formState?.config?.provider,
315+
}).toString()
316+
: T.translate(`${PREFIX}.auth.helperText`).toString(),
300317
label: T.translate(`${PREFIX}.auth.label`).toString(),
301318
'widget-type': 'radio-group',
302319
'widget-attributes': {
303-
default: scmAuthType[0].id,
320+
default: supportedAuthTypes[0].id,
304321
layout: 'inline',
305-
options: scmAuthType,
322+
options: supportedAuthTypes,
306323
},
307324
}}
308325
onChange={(val) => {
309326
handleValueChange(val, 'type');
310327
}}
311328
/>
312-
{formState.config?.auth?.type === scmAuthType[0].id && (
313-
<>
314-
<PropertyRow
315-
value={formState.config?.auth?.patConfig?.passwordName}
316-
property={{
317-
name: 'tokenName',
318-
description: T.translate(`${PREFIX}.auth.pat.tokenNameHelperText`).toString(),
319-
label: T.translate(`${PREFIX}.auth.pat.tokenName`).toString(),
320-
required: true,
321-
}}
322-
onChange={(val) => {
323-
handleValueChange(val, 'passwordName');
324-
}}
325-
errors={
326-
!formState.config?.auth?.patConfig?.passwordName && formState.error
327-
? [{ msg: T.translate('commons.requiredFieldMissingMsg').toString() }]
328-
: []
329-
}
330-
/>
331-
<PropertyRow
332-
value={formState.config?.auth?.token}
333-
property={{
334-
name: 'token',
335-
description: T.translate(`${PREFIX}.auth.pat.tokenHelperText`, {
336-
provider: formState.config?.provider || providers.github,
337-
}).toString(),
338-
label: T.translate(`${PREFIX}.auth.pat.token`).toString(),
339-
required: !isEdit,
340-
'widget-type': 'password',
341-
}}
342-
onChange={(val) => {
343-
handleValueChange(val, 'token');
344-
}}
345-
errors={
346-
!formState.config?.auth?.token && formState.error
347-
? [{ msg: T.translate('commons.requiredFieldMissingMsg').toString() }]
348-
: []
349-
}
350-
/>
351-
<PropertyRow
352-
value={formState.config?.auth?.patConfig?.username}
353-
property={{
354-
name: 'username',
355-
description: T.translate(`${PREFIX}.auth.pat.usernameHelperText`).toString(),
356-
label: T.translate(`${PREFIX}.auth.pat.username`).toString(),
357-
}}
358-
onChange={(val) => {
359-
handleValueChange(val, 'username');
360-
}}
361-
/>
362-
</>
363-
)}
329+
<PropertyRow
330+
value={formState.config?.auth?.patConfig?.passwordName}
331+
property={{
332+
name: 'tokenName',
333+
description: T.translate(`${PREFIX}.auth.pat.tokenNameHelperText`).toString(),
334+
label: T.translate(`${PREFIX}.auth.pat.tokenName`).toString(),
335+
required: true,
336+
}}
337+
onChange={(val) => {
338+
handleValueChange(val, 'passwordName');
339+
}}
340+
errors={
341+
!formState.config?.auth?.patConfig?.passwordName && formState.error
342+
? [{ msg: T.translate('commons.requiredFieldMissingMsg').toString() }]
343+
: []
344+
}
345+
/>
346+
<PropertyRow
347+
value={formState.config?.auth?.token}
348+
property={{
349+
name: 'token',
350+
description: T.translate(`${PREFIX}.auth.pat.tokenHelperText`, {
351+
provider: formState.config?.provider || providers.github,
352+
}).toString(),
353+
label: T.translate(`${PREFIX}.auth.pat.token`).toString(),
354+
required: !isEdit,
355+
'widget-type': 'password',
356+
}}
357+
onChange={(val) => {
358+
handleValueChange(val, 'token');
359+
}}
360+
errors={
361+
!formState.config?.auth?.token && formState.error
362+
? [{ msg: T.translate('commons.requiredFieldMissingMsg').toString() }]
363+
: []
364+
}
365+
/>
366+
<PropertyRow
367+
value={formState.config?.auth?.patConfig?.username}
368+
property={{
369+
name: 'username',
370+
description: T.translate(`${PREFIX}.auth.pat.usernameHelperText`).toString(),
371+
label: T.translate(`${PREFIX}.auth.pat.username`).toString(),
372+
}}
373+
onChange={(val) => {
374+
handleValueChange(val, 'username');
375+
}}
376+
/>
364377
</StyledGroup>
365378
</StyledForm>
366379
<StyledButtonGroup>

app/cdap/components/NamespaceAdmin/SourceControlManagement/constants.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@ import T from 'i18n-react';
1818

1919
const PREFIX = 'features.SourceControlManagement';
2020

21-
export const scmAuthType = [
22-
{ id: 'PAT', label: T.translate(`${PREFIX}.configModal.auth.pat.label`) },
23-
];
21+
export const SCM_AUTH_TYPE_PAT = {
22+
id: 'PAT',
23+
label: T.translate(`${PREFIX}.configModal.auth.pat.label`),
24+
};
25+
export const SCM_AUTH_TYPE_HTTP_ACCESS_TOKEN = {
26+
id: 'HTTP_ACCESS_TOKEN',
27+
label: T.translate(`${PREFIX}.configModal.auth.httpAccessToken.label`),
28+
};
29+
30+
export const scmAuthType = [SCM_AUTH_TYPE_PAT, SCM_AUTH_TYPE_HTTP_ACCESS_TOKEN];
2431

2532
export const githubOnlyProviders = {
2633
github: 'GITHUB',

app/cdap/text/text-en.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3224,7 +3224,8 @@ features:
32243224
configModal:
32253225
auth:
32263226
label: Authentication type
3227-
helperText: Choose method for authentication. Currently only PAT is available
3227+
helperTextPatOnly: Choose method for authentication. Currently only PAT is available for {provider}.
3228+
helperText: Choose method for authentication.
32283229
pat:
32293230
label: Personal access token (PAT)
32303231
token: Token
@@ -3233,6 +3234,8 @@ features:
32333234
tokenNameHelperText: Give personal access token a name for secure store. The name can contain lower case alphabets, numbers, _, and -
32343235
username: User name
32353236
usernameHelperText: Add a username to your token
3237+
httpAccessToken:
3238+
label: Http access token
32363239
authHeader: Authentication
32373240
basicHeader: Basic
32383241
branch:

server/config/development/cdap.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"feature.lifecycle.management.edit.enabled": "true",
1919
"feature.source.control.management.git.enabled": "true",
2020
"feature.source.control.management.multi.app.enabled": "true",
21+
"feature.source.control.management.gitlab.bitbucket.enabled": "true",
2122
"ui.analyticsTag": "",
2223
"ui.GTM": "",
2324
"hsts.enabled": "false",

src/e2e-test/features/source.control.management.repository.feature

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,16 @@ Feature: Source Control Management - Repository Configuration CRUD operations
5252
Then Verify saved fake repo config
5353
Then Delete the repo config
5454
Then Verify UI directed to initial page
55+
56+
Scenario: Should support HTTP_ACCESS_TOKEN for BITBUCKET_SERVER
57+
When Open Source Control Management Page
58+
Then Click on "Link Repository" button
59+
Then Select "GITHUB" scm provider
60+
Then Verify scm auth type "PAT" exists
61+
Then Verify scm auth type "HTTP_ACCESS_TOKEN" does not exist
62+
Then Select "BITBUCKET_SERVER" scm provider
63+
Then Verify scm auth type "PAT" exists
64+
Then Verify scm auth type "HTTP_ACCESS_TOKEN" exists
65+
Then Select "GITLAB" scm provider
66+
Then Verify scm auth type "PAT" exists
67+
Then Verify scm auth type "HTTP_ACCESS_TOKEN" does not exist

src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/SourceControlManagement.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,26 @@ public void addFakeRepositoryConfiguration() {
120120
addToken(Constants.FAKE_TOKEN);
121121
}
122122

123+
@Then("Select {string} scm provider")
124+
public void selectScmProvider(String scmProvider) {
125+
WebElement providerSelector = Helper.locateElementByTestId("select-provider");
126+
providerSelector.click();
127+
WebElement providerOption = Helper.locateElementByTestId("option-" + scmProvider);
128+
providerOption.click();
129+
}
130+
131+
@Then("Verify scm auth type {string} exists")
132+
public void verifyScmAuthTypeExists(String authType) {
133+
String selector = "input[name=\"auth\"][type=\"radio\"][value=\"" + authType + "\"]";
134+
Assert.assertNotNull(Helper.locateElementByCssSelector(selector));
135+
}
136+
137+
@Then("Verify scm auth type {string} does not exist")
138+
public void verifyScmAuthTypeDoesNotExist(String authType) {
139+
String selector = "input[name=\"auth\"][type=\"radio\"][value=\"" + authType + "\"]";
140+
Assert.assertFalse(Helper.isElementExists(selector));
141+
}
142+
123143
@Then("Add test repository configuration")
124144
public void addTestRepositoryConfiguration() {
125145
addRepoUrl(PluginPropertyUtils.pluginProp(Constants.GIT_REPO_URL_PROP_NAME));

0 commit comments

Comments
 (0)