Skip to content

Commit 308c5c8

Browse files
author
naman-contentstack
committed
handle token setup for audit
1 parent 8ba13c2 commit 308c5c8

File tree

7 files changed

+21
-10
lines changed

7 files changed

+21
-10
lines changed

src/commands/content-type/audit.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Command from "../../core/command";
22
import {
33
flags,
4-
FlagInput,
54
managementSDKClient,
65
cliux,
76
printFlagDeprecation,
7+
authenticationHandler,
88
} from "@contentstack/cli-utilities";
99
import buildOutput from "../../core/content-type/audit";
1010
import { getStack, getUsers, getContentType } from "../../utils";
@@ -53,7 +53,20 @@ export default class AuditCommand extends Command {
5353
async run() {
5454
try {
5555
const { flags } = await this.parse(AuditCommand);
56-
await this.setup(flags);
56+
await authenticationHandler.getAuthDetails();
57+
const authToken = authenticationHandler.accessToken;
58+
if (!authToken) {
59+
this.error(
60+
"You're not logged in. Run auth:login to sign in. Use auth:login --help for more details.",
61+
{
62+
exit: 2,
63+
suggestions: [
64+
"https://www.contentstack.com/docs/developers/cli/authentication/",
65+
],
66+
}
67+
);
68+
}
69+
this.setup(flags, authToken);
5770

5871
this.contentTypeManagementClient = await managementSDKClient({
5972
host: this.cmaHost,

src/commands/content-type/compare-remote.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default class CompareRemoteCommand extends Command {
4444
async run() {
4545
try {
4646
const { flags } = await this.parse(CompareRemoteCommand);
47-
await this.setup({ alias: undefined, stack: flags["origin-stack"] });
47+
this.setup({ alias: undefined, stack: flags["origin-stack"] });
4848
this.contentTypeManagementClient = await managementSDKClient({
4949
host: this.cmaHost,
5050
"X-CS-CLI": this.context?.analyticsInfo,

src/commands/content-type/compare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default class CompareCommand extends Command {
6868
async run() {
6969
try {
7070
const { flags } = await this.parse(CompareCommand);
71-
await this.setup(flags);
71+
this.setup(flags);
7272
this.contentTypeManagementClient = await managementSDKClient({
7373
host: this.cmaHost,
7474
"X-CS-CLI": this.context?.analyticsInfo,

src/commands/content-type/details.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default class DetailsCommand extends Command {
6262
async run() {
6363
try {
6464
const { flags } = await this.parse(DetailsCommand);
65-
await this.setup(flags);
65+
this.setup(flags);
6666
this.contentTypeManagementClient = await managementSDKClient({
6767
host: this.cmaHost,
6868
"X-CS-CLI": this.context?.analyticsInfo,

src/commands/content-type/diagram.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default class DiagramCommand extends Command {
8484
host: this.cmaHost,
8585
"X-CS-CLI": this.context?.analyticsInfo,
8686
});
87-
await this.setup(flags);
87+
this.setup(flags);
8888

8989
const outputPath = flags.output;
9090

src/commands/content-type/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default class ListCommand extends Command {
5555
async run() {
5656
try {
5757
const { flags } = await this.parse(ListCommand);
58-
await this.setup(flags);
58+
this.setup(flags);
5959
this.contentTypeManagementClient = await managementSDKClient({
6060
host: this.cmaHost,
6161
"X-CS-CLI": this.context?.analyticsInfo,

src/core/command.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ export default class ContentTypeCommand extends Command {
1212

1313
protected contentTypeManagementClient: any;
1414

15-
async setup(flags: any) {
16-
await authenticationHandler.getAuthDetails();
17-
const authToken = authenticationHandler.accessToken;
15+
setup(flags: any, authToken?: string) {
1816
if (!authToken) {
1917
this.error(
2018
"You're not logged in. Run auth:login to sign in. Use auth:login --help for more details.",

0 commit comments

Comments
 (0)