Skip to content

Commit c1044b7

Browse files
committed
setup
1 parent 63f7026 commit c1044b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1402
-498
lines changed

astra-sdk/src/main/java/com/datastax/astra/sdk/config/AstraClientConfig.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.datastax.astra.sdk.config;
22

3-
import static com.datastax.astra.sdk.utils.AstraRcParser.readRcVariable;
3+
import static com.datastax.astra.sdk.utils.AstraRc.readRcVariable;
44
import static com.datastax.stargate.sdk.utils.Assert.hasLength;
55
import static com.datastax.stargate.sdk.utils.Assert.notNull;
66
import static com.datastax.stargate.sdk.utils.Utils.readEnvVariable;
@@ -16,7 +16,7 @@
1616
import org.slf4j.LoggerFactory;
1717

1818
import com.datastax.astra.sdk.AstraClient;
19-
import com.datastax.astra.sdk.utils.AstraRcParser;
19+
import com.datastax.astra.sdk.utils.AstraRc;
2020
import com.datastax.oss.driver.api.core.ConsistencyLevel;
2121
import com.datastax.oss.driver.api.core.config.ProgrammaticDriverConfigLoaderBuilder;
2222
import com.datastax.oss.driver.api.core.config.TypedDriverOption;
@@ -924,8 +924,8 @@ public AstraClientConfig() {
924924
stargateConfig = new StargateClientConfig();
925925

926926
// Loading ~/.astrarc section default if present
927-
if (AstraRcParser.exists()) {
928-
loadFromAstraRc(AstraRcParser.load(), AstraRcParser.ASTRARC_DEFAULT);
927+
if (AstraRc.exists()) {
928+
loadFromAstraRc(AstraRc.load(), AstraRc.ASTRARC_DEFAULT);
929929
}
930930

931931
// Authentication
@@ -951,7 +951,7 @@ public AstraClientConfig() {
951951
* @param sectionName String
952952
* @return AstraClientBuilder
953953
*/
954-
public AstraClientConfig loadFromAstraRc(AstraRcParser arc, String sectionName) {
954+
public AstraClientConfig loadFromAstraRc(AstraRc arc, String sectionName) {
955955
notNull(arc, "AstraRc");
956956
hasLength(sectionName, "sectionName");
957957
readRcVariable(arc, ASTRA_DB_ID, sectionName).ifPresent(this::withDatabaseId);

astra-sdk/src/main/java/com/datastax/astra/sdk/organizations/OrganizationsClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ public Stream<Key> keys() {
413413
/**
414414
* Create a new key.
415415
*
416-
* @param cr
417-
* new role request
416+
* @param keyDef
417+
* key definition request
418418
* @return
419419
* new role created
420420
*/

astra-sdk/src/main/java/com/datastax/astra/sdk/utils/AstraRcParser.java renamed to astra-sdk/src/main/java/com/datastax/astra/sdk/utils/AstraRc.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
*
4646
* @author Cedrick LUNVEN (@clunven)
4747
*/
48-
public class AstraRcParser {
48+
public class AstraRc {
4949

5050
/** Logger for our Client. */
51-
private static final Logger LOGGER = LoggerFactory.getLogger(AstraRcParser.class);
51+
private static final Logger LOGGER = LoggerFactory.getLogger(AstraRc.class);
5252

5353
/** Default filename we are looking for. */
5454
public static final String ASTRARC_FILENAME = ".astrarc";
@@ -71,8 +71,8 @@ public class AstraRcParser {
7171
/**
7272
* Load from ~/.astrarc
7373
*/
74-
public AstraRcParser() {
75-
this.sections = AstraRcParser.load().getSections();
74+
public AstraRc() {
75+
this.sections = AstraRc.load().getSections();
7676
}
7777

7878
/**
@@ -81,8 +81,8 @@ public AstraRcParser() {
8181
* @param fileName
8282
* String
8383
*/
84-
public AstraRcParser(String fileName) {
85-
this.sections = AstraRcParser.load(fileName).getSections();
84+
public AstraRc(String fileName) {
85+
this.sections = AstraRc.load(fileName).getSections();
8686
}
8787

8888
/**
@@ -91,7 +91,7 @@ public AstraRcParser(String fileName) {
9191
* @param s
9292
* Map
9393
*/
94-
public AstraRcParser(Map<String, Map<String, String>> s) {
94+
public AstraRc(Map<String, Map<String, String>> s) {
9595
this.sections = s;
9696
}
9797

@@ -264,8 +264,7 @@ public static void save(Map<String, Map<String, String>> astraRc) {
264264
*
265265
* @return AstraRc
266266
*/
267-
public static AstraRcParser load() {
268-
createIfNotExists();
267+
public static AstraRc load() {
269268
return load(getDefaultConfigFile().getAbsolutePath());
270269
}
271270

@@ -277,7 +276,7 @@ public static AstraRcParser load() {
277276
* @return
278277
* parser.
279278
*/
280-
public static AstraRcParser load(File file) {
279+
public static AstraRc load(File file) {
281280
Map<String, Map<String, String>> sections = new HashMap<>();
282281
try (Scanner scanner = new Scanner(file)) {
283282
if (file.exists()) {
@@ -304,7 +303,7 @@ public static AstraRcParser load(File file) {
304303
} catch (FileNotFoundException e) {
305304
throw new IllegalArgumentException("Cannot read configuration file", e);
306305
}
307-
return new AstraRcParser(sections);
306+
return new AstraRc(sections);
308307
}
309308

310309
/**
@@ -314,7 +313,7 @@ public static AstraRcParser load(File file) {
314313
* String
315314
* @return AstraRc
316315
*/
317-
public static AstraRcParser load(String fileName) {
316+
public static AstraRc load(String fileName) {
318317
return load(new File(fileName));
319318

320319
}
@@ -391,7 +390,7 @@ private static Map<String, String> dbKeys(Database db, String token) {
391390
* section Name
392391
* @return if the value is there
393392
*/
394-
public static Optional<String> readRcVariable(AstraRcParser arc, String key, String sectionName) {
393+
public static Optional<String> readRcVariable(AstraRc arc, String key, String sectionName) {
395394
Map<String, String> section = arc.getSections().get(sectionName);
396395
if (section != null && section.containsKey(key) && Utils.hasLength(section.get(key))) {
397396
return Optional.ofNullable(section.get(key));

astra-shell/README.MD

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Astra Shell
2+
3+
[![License Apache2](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0)
4+
5+
## Overview
6+
7+
Astra Shell is a standalone command line interface.
8+
9+
(1) It can be use as a stateless cli providing all options in the command line for automation purporse
10+
11+
```
12+
astra create db
13+
--token AstraCS:...... \
14+
--name workshop \
15+
--region eu-central-1 \
16+
--keyspace nosql1
17+
```
18+
19+
(2) It provides a configuration management system to avoid you to enter credentials (tokens) for each command.
20+
21+
```
22+
astra create db
23+
--config my_env_dev \
24+
--name workshop \
25+
--region eu-central-1 \
26+
--keyspace nosql1
27+
```
28+
29+
(3) It provides a shell, an interactive repl for users interactions.
30+
31+
```
32+
astra --config my_env_dev
33+
34+
$myAstraOrganization>create db --name workshop --region eu-central-1 --keyspace nosql1
35+
```
36+
37+
## Prequisites
38+
39+
The program is written in Java. You need to have a JRE/JDK 8+ install
40+
41+
## Installations
42+
43+
### Manual installation
44+
45+
### Homebrew install (Mac Users)
46+
47+
*Not available yet*
48+
49+
```
50+
brew install astra
51+
```
52+
53+
### Apt-Get install (Linux Users)
54+
55+
*Not available yet*
56+
57+
```
58+
apt-get install astra
59+
```
60+
61+
### Yum Install (Linux Users)
62+
63+
*Not available yet*
64+
65+
```
66+
yum install astra
67+
```
68+
69+
### Install with sdkman
70+
71+
*Not available yet*
72+
73+
```
74+
sdk install astra
75+
```
76+
77+
### Install with Chocolatey (Windows Users)
78+
79+
*Not available yet*
80+
81+
```
82+
sdk install astra
83+
```
84+
85+
## Setup
86+
87+
## Getting Started
88+
89+
```
90+
astra setup
91+
```
92+
93+
```
94+
astra show configs
95+
astra show config default
96+
astra show dbs
97+
astra show roles
98+
astra show users
99+
astra show user <U>
100+
astra show role <R>
101+
```
102+
103+
```
104+
astra
105+
>show configs
106+
>show config <CONF>
107+
>config load --name <CONF>
108+
>config save --name <CONF>
109+
```
110+

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package com.datastax.astra.shell;
22

3-
import com.datastax.astra.shell.cmd.ConfigCommand;
4-
import com.datastax.astra.shell.cmd.HelpCustomCommand;
3+
import com.datastax.astra.shell.cmd.HelpCommand;
54
import com.datastax.astra.shell.cmd.SetDefaultOrgCommand;
6-
import com.datastax.astra.shell.cmd.ShowConfigCommand;
5+
import com.datastax.astra.shell.cmd.SetupCommand;
6+
import com.datastax.astra.shell.cmd.ShowConfigsCommand;
77
import com.datastax.astra.shell.cmd.ShowRoleCommand;
88
import com.datastax.astra.shell.cmd.ShowRolesCommand;
99
import com.datastax.astra.shell.cmd.ShowUserCommand;
1010
import com.datastax.astra.shell.cmd.ShowUsersCommands;
1111
import com.datastax.astra.shell.cmd.db.CreateDatabaseCommand;
12+
import com.datastax.astra.shell.cmd.db.CreateDatabaseCommand.CreateDatabaseCommandAlias1;
1213
import com.datastax.astra.shell.cmd.db.DeleteDatabaseCommand;
14+
import com.datastax.astra.shell.cmd.db.DeleteDatabaseCommand.DeleteDatabaseCommandAlias1;
1315
import com.datastax.astra.shell.cmd.db.ShowDatabasesCommand;
1416
import com.datastax.astra.shell.cmd.db.ShowDatabasesCommand.ShowDatabasesCommandBis;
1517
import com.datastax.astra.shell.cmd.shell.ShellCommand;
@@ -29,33 +31,45 @@
2931
description = "CLI for DataStax Astra™ including an interactive mode",
3032
defaultCommand = ShellCommand.class, // no command => interactive
3133
commands = {
34+
SetupCommand.class,
35+
HelpCommand.class,
3236
ShellCommand.class,
33-
HelpCustomCommand.class,
34-
ConfigCommand.class,
3537
SetDefaultOrgCommand.class
3638
},
3739
groups = {
3840
@Group(
3941
name = "show", description = "Display an entity or a group of entities",
40-
commands = {
41-
ShowDatabasesCommand.class, ShowDatabasesCommandBis.class,
42-
ShowRoleCommand.class, ShowRolesCommand.class,
43-
ShowUserCommand.class, ShowUsersCommands.class,
44-
ShowConfigCommand.class
42+
commands = {
43+
// List Db in the organization (dbs | databases)
44+
ShowDatabasesCommand.class,
45+
ShowDatabasesCommandBis.class,
46+
// List Roles in the current organization/tenant
47+
ShowRolesCommand.class,
48+
// Display details of a role (permissions)
49+
ShowRoleCommand.class,
50+
// Display details of a user (roles, permissions, metadata)
51+
ShowUserCommand.class,
52+
// List Users in the current organization/tenant
53+
ShowUsersCommands.class,
54+
// Show current configuration
55+
ShowConfigsCommand.class
4556
}
4657
),
4758
@Group(
4859
name = "create",
4960
description = "Create an entity",
5061
commands = {
51-
CreateDatabaseCommand.class
62+
CreateDatabaseCommand.class,
63+
CreateDatabaseCommandAlias1.class,
64+
SetupCommand.class
5265
}
5366
),
5467
@Group(
5568
name = "delete",
56-
description = "Delete an entity",
69+
description = "Delete existing entities",
5770
commands = {
58-
DeleteDatabaseCommand.class
71+
DeleteDatabaseCommand.class,
72+
DeleteDatabaseCommandAlias1.class,
5973
}
6074
)
6175
})
@@ -66,8 +80,6 @@ public class AstraCli {
6680
*
6781
* @param args
6882
* start options for the shell
69-
* @throws Exception
70-
* error during parsing or interpreting command
7183
*/
7284
public static void main(String[] args) {
7385

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.datastax.astra.shell;
22

33
import com.datastax.astra.shell.cmd.ExitCommand;
4-
import com.datastax.astra.shell.cmd.HelpCustomCommand;
5-
import com.datastax.astra.shell.cmd.ShowConfigCommand;
4+
import com.datastax.astra.shell.cmd.HelpCommand;
5+
import com.datastax.astra.shell.cmd.QuitCommand;
6+
import com.datastax.astra.shell.cmd.ShowConfigsCommand;
67
import com.datastax.astra.shell.cmd.ShowRoleCommand;
78
import com.datastax.astra.shell.cmd.ShowRolesCommand;
89
import com.datastax.astra.shell.cmd.ShowUserCommand;
910
import com.datastax.astra.shell.cmd.ShowUsersCommands;
1011
import com.datastax.astra.shell.cmd.db.ShowDatabasesCommand;
12+
import com.datastax.astra.shell.cmd.db.UseDatabaseCommand;
1113
import com.datastax.astra.shell.cmd.db.ShowDatabasesCommand.ShowDatabasesCommandBis;
1214
import com.datastax.astra.shell.cmd.shell.ConnectCommand;
1315
import com.datastax.astra.shell.cmd.shell.EmptyCommand;
@@ -30,8 +32,9 @@
3032
commands = {
3133
ConnectCommand.class,
3234
EmptyCommand.class,
33-
HelpCustomCommand.class,
34-
ExitCommand.class
35+
HelpCommand.class,
36+
ExitCommand.class,
37+
QuitCommand.class
3538
},
3639
groups = {
3740
@Group(
@@ -41,7 +44,14 @@
4144
ShowDatabasesCommand.class, ShowDatabasesCommandBis.class,
4245
ShowRoleCommand.class, ShowRolesCommand.class,
4346
ShowUserCommand.class, ShowUsersCommands.class,
44-
ShowConfigCommand.class }
47+
ShowConfigsCommand.class }
48+
),
49+
@Group(
50+
name = "use",
51+
description = "Focus on an entity (context & prompt changed)",
52+
commands = {
53+
UseDatabaseCommand.class
54+
}
4555
)
4656
})
4757
public class AstraShell {

0 commit comments

Comments
 (0)