Skip to content

Commit 94e18b7

Browse files
committed
setup
1 parent fa0fbd2 commit 94e18b7

File tree

3 files changed

+37
-55
lines changed

3 files changed

+37
-55
lines changed

astra-shell/src/main/java/com/datastax/astra/shell/ShellContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ public void init(BaseCliCommand cli) {
151151

152152
if (token != null) {
153153
connect(cli, token);
154+
} else {
155+
INVALID_PARAMETER.exit();
154156
}
155157
}
156158

astra-shell/src/main/java/com/datastax/astra/shell/cmd/config/Setup.java

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package com.datastax.astra.shell.cmd.config;
22

3+
import static org.fusesource.jansi.Ansi.ansi;
4+
35
import java.util.Scanner;
46

57
import org.fusesource.jansi.Ansi;
8+
import org.fusesource.jansi.Ansi.Color;
69

7-
import com.datastax.astra.sdk.AstraClient;
8-
import com.datastax.astra.sdk.config.AstraClientConfig;
10+
import com.datastax.astra.sdk.organizations.OrganizationsClient;
911
import com.datastax.astra.shell.cmd.show.ShowConfigsCommand;
1012
import com.datastax.astra.shell.utils.LoggerShell;
1113
import com.datastax.astra.shell.utils.ShellPrinter;
12-
import com.github.rvesse.airline.annotations.Arguments;
1314
import com.github.rvesse.airline.annotations.Command;
1415

1516
/**
@@ -22,80 +23,59 @@
2223
description = "Intialize configuration")
2324
public class Setup extends BaseConfigCommand implements Runnable {
2425

25-
/**
26-
* Section in configuration file to as as default.
27-
*/
28-
@Arguments(
29-
title = "section",
30-
description = "Section in configuration file to as as defulat.")
31-
protected String sectionName;
32-
3326
/** {@inheritDoc} */
3427
@Override
3528
public void run() {
29+
System.out.print(ansi().eraseScreen().reset());
3630
ShellPrinter.banner();
37-
System.out.println("+-------------------------------+");
38-
System.out.println("+- Setup. -+");
39-
System.out.println("+-------------------------------+");
40-
41-
System.out.println("\nWelcome to Astra Shell/CLI. We will guide you to start.");
42-
43-
LoggerShell.println("\nHow it works ?\n", Ansi.Color.CYAN);
44-
System.out.println("Astra Cli and shell (interactive) leverage a configuration file (~/.astrarc) avoiding users to have to enter credentials each time. "
45-
+ "The file is divided in sections identified by a name. If user does not specify section name the [default] is used."
46-
+ " For each section, key 'ASTRA_DB_APPLICATION_TOKEN' is mandatory: it is the authentication token "
47-
+ " used to invoke Astra Apis. More keys can be added to change scope or settings. Here is a sample file:");
48-
49-
System.out.println("\n[default]");
50-
System.out.println(AstraClientConfig.ASTRA_DB_APPLICATION_TOKEN + "=AstraCS:aaaaa......");
51-
System.out.println("\n[my_dev_env]");
52-
System.out.println(AstraClientConfig.ASTRA_DB_APPLICATION_TOKEN + "=AstraCS:abcde......");
53-
System.out.println(AstraClientConfig.ASTRA_DB_ID + "=924e6ab3-eeb5-45e1-9861-5abcdc62f343");
54-
System.out.println(AstraClientConfig.ASTRA_DB_REGION + "=europe-west-1");
55-
System.out.println("\n[my_prod_env]");
56-
System.out.println(AstraClientConfig.ASTRA_DB_APPLICATION_TOKEN + "=AstraCS:12345......");
57-
System.out.println(AstraClientConfig.ASTRA_DB_ID + "=924e6ab3-eeb5-45e1-9861-5abcdc62f34444");
58-
System.out.println(AstraClientConfig.ASTRA_DB_REGION + "=europe-west-1");
59-
60-
LoggerShell.println("\nGetting Started\n", Ansi.Color.CYAN);
61-
System.out.println("You need an Astra token, here is the procedure to create one :\nhttps://awesome-astra.github.io/docs/pages/astra/create-token/");
31+
System.out.println();
32+
LoggerShell.print("+-------------------------------+\n", Color.CYAN);
33+
LoggerShell.print("+- Setup. -+\n", Color.CYAN);
34+
LoggerShell.print("+-------------------------------+\n", Color.CYAN);
35+
System.out.println("\nWelcome to Astra Shell. We will guide you to start.");
6236

63-
System.out.println("\nWe will now create a section. "
64-
+ "(if first, will be set as default).");
37+
LoggerShell.println("\n[Astra Setup]\n", Ansi.Color.CYAN);
38+
System.out.println("To use the cli you have to:");
39+
System.out.println(" • Create an Astra account on : https://astra.datastax.com");
40+
System.out.println(" • Create an authentication token following: https://dtsx.io/create-astra-token");
6541

42+
LoggerShell.println("\n[Cli Setup]\n", Ansi.Color.CYAN);
43+
System.out.println("You will be asked to enter your token, it will be saved locally.");
6644
String token = null;
6745
try(Scanner scanner = new Scanner(System.in)) {
6846
boolean valid_token = false;
6947
while (!valid_token) {
70-
LoggerShell.print("\n - Enter a token (eg: AstraCS...) : ", Ansi.Color.CYAN);
48+
LoggerShell.print("\nEnter your token (AstraCS...) : ", Ansi.Color.MAGENTA);
7149
token = scanner.nextLine();
7250
if (!token.startsWith("AstraCS:")) {
7351
LoggerShell.error("Your token should start with 'AstraCS:'");
7452
} else {
7553
try {
76-
AstraClient.builder()
77-
.withToken(token)
78-
.build()
79-
.apiDevopsOrganizations()
80-
.organization();
81-
valid_token = true;
54+
;
8255
ConfigCreate ccc = new ConfigCreate();
8356
ccc.token = token;
57+
ccc.sectionName = new OrganizationsClient(token).organization().getName();
8458
ccc.run();
59+
valid_token = true;
60+
61+
ShowConfigsCommand configs = new ShowConfigsCommand();
62+
configs.astraRc = this.astraRc;
63+
configs.configFilename = this.configFilename;
64+
configs.run();
8565

86-
} catch(IllegalArgumentException iexo) {
87-
LoggerShell.error("Your token seems invalid, it was not possible to connect to Astra.");
66+
} catch(Exception e) {
67+
LoggerShell.error("Token provided is invalid. Please enter a valid token or quit with CTRL+C");
8868
}
8969
}
9070
}
91-
92-
ShowConfigsCommand configs = new ShowConfigsCommand();
93-
configs.astraRc = this.astraRc;
94-
configs.configFilename = this.configFilename;
95-
configs.run();
96-
System.out.println("");
9771

98-
System.out.println("\nTo change default organization: astra config default <section>");
72+
LoggerShell.println("\n[What's NEXT ?]\n", Ansi.Color.CYAN);
73+
System.out.println("You are all set you can now:");
74+
System.out.println(" • Use any command, 'astra help' will get you the list");
75+
System.out.println(" • Try with 'astra db list'");
76+
System.out.println(" • Enter interactive mode using 'astra'");
77+
System.out.println("\nHappy Coding !");
78+
System.out.println("");
9979
}
10080
}
10181

astra-shell/src/main/java/com/datastax/astra/shell/cmd/shell/ShellCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public ExitCode execute() {
2929

3030
if (version) {
3131
outputData("version", ShellPrinter.version());
32-
return ExitCode.SUCCESS;
32+
ExitCode.SUCCESS.exit();
3333
}
3434

3535
// Show Banner

0 commit comments

Comments
 (0)