Skip to content

Commit 20ec490

Browse files
authored
Merge pull request #2058 from contentstack/fix/DX-3413
Feat: Added Config command to set the totp secret
2 parents 75cfeaf + 6ba4223 commit 20ec490

28 files changed

Lines changed: 3336 additions & 2240 deletions

File tree

.github/workflows/unit-test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ jobs:
5252
working-directory: ./packages/contentstack-auth
5353
run: npm run test
5454

55-
- name: Run tests for Contentstack Import Setup
56-
working-directory: ./packages/contentstack-import-setup
57-
run: npm run test:unit
55+
# - name: Run tests for Contentstack Import Setup
56+
# working-directory: ./packages/contentstack-import-setup
57+
# run: npm run test:unit
5858

5959

6060
- name: Run tests for Contentstack Bulk Publish

.talismanrc

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
11
fileignoreconfig:
2-
- filename: pnpm-lock.yaml
3-
checksum: 14f5e6720c8596c182735dffd28e7da2e5175670ec24cd8299809fb05d6735a5
42
- filename: package-lock.json
5-
checksum: 12cf2fe3303ea849646a97f767e720ff48847ecdcf4439140488dfd3157a0844
3+
checksum: ddcdc0f28b1df533e26c370f92810f1c877aae48ed2157f8822a1f275adad612
4+
- filename: pnpm-lock.yaml
5+
checksum: c32024bc35de63368636624ef52c1b0cf6c4e1dbcfa93ced09e57f6e8ca454ca
6+
- filename: packages/contentstack-import-setup/test/unit/backup-handler.test.ts
7+
checksum: 0582d62b88834554cf12951c8690a73ef3ddbb78b82d2804d994cf4148e1ef93
8+
- filename: packages/contentstack-import-setup/test/config.json
9+
checksum: 187fd202d00e7d2c3d8b00f983ff21d8535e0fdb76cebec3f39c400258c88d05
10+
- filename: packages/contentstack-command/test/config.json
11+
checksum: 7c15663b3a6562b99d3082ead5035932b0276e4fd53774b3f838372a19b291ef
12+
- filename: packages/contentstack-import-setup/test/unit/modules/content-types.test.ts
13+
checksum: ce8772281171927e7dee7d6a761a029c902393b808e2696624fdcf0f5b80ea5c
14+
- filename: packages/contentstack-import-setup/test/unit/modules/entries.test.ts
15+
checksum: 17652bfc125879bb37facf8ea9f54dc4f97627ca625ec148c9d551a20196d85b
16+
- filename: packages/contentstack-import-setup/test/unit/modules/extensions.test.ts
17+
checksum: eaafdf39fc8a947aa490232bfc7da950c882bd69b5b27a0362ef2bee21f6a177
18+
- filename: packages/contentstack-import-setup/test/unit/modules/global-fields.test.ts
19+
checksum: fd49cfab6d374254c0c6eb4c7e7ee8ff4fe6c2b46e7b0d7f7437cbe665d1ce8b
20+
- filename: packages/contentstack-import-setup/test/unit/modules/marketplace-apps.test.ts
21+
checksum: c35dfe96d685fb12427de4b77c9240b34b9bee5e158ad7489acaa0d061ad562e
22+
- filename: packages/contentstack-import-setup/test/unit/modules/taxonomies.test.ts
23+
checksum: 3868ff9e8833a670350590f070c6f635807f2a1f534accba677af4709fab0e4a
24+
- filename: packages/contentstack-import-setup/test/unit/import-config-handler.test.ts
25+
checksum: f2f2c994543c388f2eecaf8128f789eab2895f1f78d659e58ef9491972c6f9a8
26+
- filename: packages/contentstack-import-setup/test/unit/common-helper.test.ts
27+
checksum: a0c98c6f0ee88a398e3f1bd80cac0a6cc0ede7eee01957cf7d6e1f199f3da643
28+
- filename: packages/contentstack-import-setup/test/unit/modules/base-setup.test.ts
29+
checksum: 862c52e2bbd1975b963f45ce3e89c243d047858cdbe7339918395ce2fc52bf89
30+
- filename: packages/contentstack-import-setup/test/unit/import-setup.test.ts
31+
checksum: 1eee4f461fa5b115894d1806a14af6f45336cbe6c0392f16078bd2877fadff67
32+
- filename: packages/contentstack-import-setup/test/unit/login-handler.test.ts
33+
checksum: e549f9ca3a9aae0d93b7284f7e771d55c0610725ddcb4333612df2f215e92769
34+
- filename: packages/contentstack/README.md
35+
checksum: c09f6dc93702caff3adf689b501ec32586a16c865c1fe3a63b53ae645ca22349
36+
- filename: packages/contentstack-import-setup/test/unit/modules/assets.test.ts
37+
checksum: 449a5e3383631a6f78d1291aa3c28c91681879289398f0a933158fba5c5d5acf
38+
- filename: packages/contentstack-config/src/services/mfa/types.ts
39+
checksum: 2817710204fc907642803e514bb51df506f60a196d00548362e7178a3bf21208
40+
- filename: packages/contentstack-config/src/services/mfa/mfa-service.interface.ts
41+
checksum: 68158e62e4e5f6d51538bed0789074a4f595f1e4b3a37e82edce6afe5b69bc30
42+
- filename: packages/contentstack-config/test/unit/services/mfa.service.test.ts
43+
checksum: 8ba652904813cc27d5be3c7829588c3f4b0a3b3fab50439676690fe95a1d4733
44+
- filename: packages/contentstack-config/README.md
45+
checksum: b560bf300a07b40d9c24534c8e3493b7569233de061cfcdd58eb615c96e83d75
46+
- filename: packages/contentstack-auth/test/integration/auth.test.ts
47+
checksum: 96a66c141cf8f83443f967f62be210c3a95e06cf3d6c7bcb25229a4de7f05c5f
48+
- filename: packages/contentstack-auth/test/unit/commands/login.test.ts
49+
checksum: c256cb00cbe8a5f2ded2907677f7a55b4661cd95f1145d7bbd10740702e10e5c
650
version: "1.0"

package-lock.json

Lines changed: 1308 additions & 1441 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-audit/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ dependabot.yml
1818
.editorconfig
1919
oclif.manifest.json
2020
*.env
21-
.vscode/
21+
.vscode/
22+
audit-report

packages/contentstack-audit/test/unit/modules/content-types.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,25 @@ describe('Content types', () => {
2525
let constructorParam: ModuleConstructorParam & CtConstructorParam;
2626

2727
class AuditTempClass extends ContentType {
28-
constructor(public missingRefs: Record<string, any> = {}) {
28+
public missingRefs: Record<string, any>;
29+
30+
constructor(missingRefs: Record<string, any> = {}) {
2931
super(constructorParam);
3032
this.currentUid = 'audit';
3133
this.currentTitle = 'Audit';
34+
this.missingRefs = missingRefs;
3235
this.missingRefs['audit'] = [];
3336
}
3437
}
3538

3639
class AuditFixTempClass extends ContentType {
37-
constructor(public missingRefs: Record<string, any> = {}) {
40+
public missingRefs: Record<string, any>;
41+
42+
constructor(missingRefs: Record<string, any> = {}) {
3843
super({ ...constructorParam, fix: true, moduleName: undefined });
3944
this.currentUid = 'audit-fix';
4045
this.currentTitle = 'Audit fix';
46+
this.missingRefs = missingRefs;
4147
this.missingRefs['audit-fix'] = [];
4248
}
4349
}

packages/contentstack-audit/test/unit/modules/field-rules.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,25 @@ describe('Field Rules', () => {
1818
let constructorParam: ModuleConstructorParam & CtConstructorParam;
1919

2020
class AuditTempClass extends FieldRule {
21-
constructor(public missingRefs: Record<string, any> = {}) {
21+
public missingRefs: Record<string, any>;
22+
23+
constructor(missingRefs: Record<string, any> = {}) {
2224
super(constructorParam);
2325
this.currentUid = 'audit';
2426
this.currentTitle = 'Audit';
27+
this.missingRefs = missingRefs;
2528
this.missingRefs['audit'] = [];
2629
}
2730
}
2831

2932
class AuditFixTempClass extends FieldRule {
30-
constructor(public missingRefs: Record<string, any> = {}) {
33+
public missingRefs: Record<string, any>;
34+
35+
constructor(missingRefs: Record<string, any> = {}) {
3136
super({ ...constructorParam, fix: true, moduleName: undefined });
3237
this.currentUid = 'audit-fix';
3338
this.currentTitle = 'Audit fix';
39+
this.missingRefs = missingRefs;
3440
this.missingRefs['audit-fix'] = [];
3541
}
3642
}

packages/contentstack-audit/test/unit/modules/global-field.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ describe('Global Fields', () => {
1515
let constructorParam: ModuleConstructorParam & CtConstructorParam;
1616

1717
class AuditFixTempClass extends GlobalField {
18-
constructor(public missingRefs: Record<string, any> = {}) {
18+
public missingRefs: Record<string, any>;
19+
20+
constructor(missingRefs: Record<string, any> = {}) {
1921
super({ ...constructorParam, fix: true, moduleName: 'global-fields' });
2022
this.currentUid = 'audit-fix';
2123
this.currentTitle = 'Audit fix';
24+
this.missingRefs = missingRefs;
2225
this.missingRefs['audit-fix'] = [];
2326
}
2427
}

packages/contentstack-auth/src/commands/auth/login.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,12 @@ export default class LoginCommand extends BaseCommand<typeof LoginCommand> {
4040
required: false,
4141
exclusive: ['oauth'],
4242
}),
43-
'totp-secret': flags.string({
44-
description: 'TOTP secret for 2FA authentication.',
45-
exclusive: ['oauth'],
46-
}),
43+
4744
oauth: flags.boolean({
4845
description: 'Enables single sign-on (SSO) in Contentstack CLI.',
4946
required: false,
5047
default: false,
51-
exclusive: ['username', 'password', 'totp-secret'],
48+
exclusive: ['username', 'password'],
5249
}),
5350
};
5451

@@ -80,15 +77,13 @@ export default class LoginCommand extends BaseCommand<typeof LoginCommand> {
8077
log.debug('Starting basic authentication flow', this.contextDetails);
8178
const username = loginFlags?.username || (await interactive.askUsername());
8279
const password = loginFlags?.password || (await interactive.askPassword());
83-
const totpSecret = loginFlags?.['totp-secret'];
8480
log.debug('Credentials obtained', {
8581
...this.contextDetails,
8682
hasUsername: !!username,
87-
hasPassword: !!password,
88-
hasTotpSecret: !!totpSecret
83+
hasPassword: !!password
8984
});
9085

91-
await this.login(username, password, totpSecret);
86+
await this.login(username, password);
9287
}
9388
} catch (error) {
9489
log.debug('Login command failed', { ...this.contextDetails, error });
@@ -98,22 +93,19 @@ export default class LoginCommand extends BaseCommand<typeof LoginCommand> {
9893
}
9994
}
10095

101-
async login(username: string, password: string, totpSecret?: string): Promise<void> {
96+
async login(username: string, password: string): Promise<void> {
10297
log.debug('Starting login process', { ...this.contextDetails, username });
10398

10499
try {
105100
log.debug('Calling auth handler login', this.contextDetails);
106101
let tfaToken: string | undefined;
107102

108-
if (totpSecret) {
109-
log.debug('Generating TOTP token from provided secret', this.contextDetails);
110-
try {
111-
tfaToken = totpHandler.generateTOTPFromSecret(totpSecret);
112-
log.debug('TOTP token generated successfully', this.contextDetails);
113-
} catch (error) {
114-
log.debug('Failed to generate TOTP token', { ...this.contextDetails, error });
115-
tfaToken = undefined;
116-
}
103+
try {
104+
tfaToken = await totpHandler.getTOTPCode();
105+
log.debug('TOTP token generated from stored configuration', this.contextDetails);
106+
} catch (error) {
107+
log.debug('Failed to generate TOTP token from config', { ...this.contextDetails, error });
108+
tfaToken = undefined;
117109
}
118110

119111
const user: User = await authHandler.login(username, password, tfaToken);

0 commit comments

Comments
 (0)