Skip to content

Commit 8ab22c2

Browse files
committed
Push embedding functions
1 parent c88b01d commit 8ab22c2

23 files changed

+3796
-107
lines changed

pom.xml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@
1111
<url>https://github.com/datastax/astra-cli</url>
1212
<properties>
1313

14+
<!-- Core Properties -->
1415
<imageName>astra</imageName>
16+
<required-maven.version>3.6.3</required-maven.version>
1517
<app.main.class>com.dtsx.astra.cli.AstraCli</app.main.class>
1618
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1719
<sonar.organization>clun-datastax</sonar.organization>
1820
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
1921

20-
<astra-sdk.version>1.2.8-SNAPSHOT</astra-sdk.version>
21-
<astra-db-java.version>1.2.0</astra-db-java.version>
22+
<astra-sdk.version>1.2.8</astra-sdk.version>
23+
<astra-db-java.version>1.4.3</astra-db-java.version>
2224
<jansi.version>2.4.1</jansi.version>
2325
<airline.version>3.0.0</airline.version>
2426
<slf4j.version>2.0.13</slf4j.version>
2527
<httpclient.version>5.1.2</httpclient.version>
26-
<jackson-datatype.version>2.17.1</jackson-datatype.version>
28+
<jackson-datatype.version>2.17.2</jackson-datatype.version>
2729
<commons-compress.version>1.26.2</commons-compress.version>
28-
<!-- Junit -->
30+
<!-- TEST -->
2931
<junit-jupiter.version>5.10.2</junit-jupiter.version>
3032
<awaitibility.version>4.2.1</awaitibility.version>
3133
<!-- Java -->
@@ -37,6 +39,7 @@
3739
<version.maven.plugin.compiler>3.12.1</version.maven.plugin.compiler>
3840
<version.maven.plugin.coveralls>4.3.0</version.maven.plugin.coveralls>
3941
<version.maven.plugin.dependency>3.6.1</version.maven.plugin.dependency>
42+
<version.maven.plugin.enforcer>3.5.0</version.maven.plugin.enforcer>
4043
<version.maven.plugin.exec>3.3.0</version.maven.plugin.exec>
4144
<version.maven.plugin.jacoco>0.8.12</version.maven.plugin.jacoco>
4245
<version.maven.plugin.javadoc>3.6.0</version.maven.plugin.javadoc>
@@ -144,6 +147,26 @@
144147
</includes>
145148
</configuration>
146149
</plugin>
150+
<plugin>
151+
<groupId>org.apache.maven.plugins</groupId>
152+
<artifactId>maven-enforcer-plugin</artifactId>
153+
<version>${version.maven.plugin.enforcer}</version>
154+
<executions>
155+
<execution>
156+
<id>enforce-maven</id>
157+
<goals>
158+
<goal>enforce</goal>
159+
</goals>
160+
<configuration>
161+
<rules>
162+
<requireMavenVersion>
163+
<version>${required-maven.version}</version>
164+
</requireMavenVersion>
165+
</rules>
166+
</configuration>
167+
</execution>
168+
</executions>
169+
</plugin>
147170
<plugin>
148171
<groupId>org.apache.maven.plugins</groupId>
149172
<artifactId>maven-dependency-plugin</artifactId>

src/main/dist/astra-init.sh

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ function _complete_astra_group_db() {
495495
CURR_CMD=${COMP_WORDS[2]}
496496
fi
497497

498-
COMMANDS="list-regions delete-keyspace list-clouds download-scb delete-region list-regions-vector create-region delete create-keyspace list-cdc create-collection list-regions-classic load delete-collection get unload create delete-cdc create-cdc resume list-keyspaces list-collections list-regions-serverless count create-dotenv list get-endpoint-playground describe cqlsh get-endpoint-api get-endpoint-swagger status"
498+
COMMANDS="list-regions delete-keyspace list-clouds download-scb delete-region list-regions-vector describe-collection create-region delete create-keyspace list-cdc create-collection list-regions-classic load delete-collection get unload create delete-cdc create-cdc resume list-keyspaces list-collections list-regions-serverless count create-dotenv list get-endpoint-playground describe cqlsh get-endpoint-api get-endpoint-swagger status"
499499
if [[ ${COMP_CWORD} -eq 2 ]]; then
500500
COMPREPLY=( $(_complete_astra_group_db_command_list "${COMMANDS}" ) )
501501
DEFAULT_GROUP_COMMAND_COMPLETIONS=(${COMPREPLY[@]})
@@ -580,6 +580,11 @@ function _complete_astra_group_db() {
580580
echo ${COMPREPLY[@]}
581581
return $?
582582
;;
583+
describe-collection)
584+
COMPREPLY=( $(_complete_astra_group_db_command_describecollection "${COMMANDS}" ) )
585+
echo ${COMPREPLY[@]}
586+
return $?
587+
;;
583588
create-region)
584589
COMPREPLY=( $(_complete_astra_group_db_command_createregion "${COMMANDS}" ) )
585590
echo ${COMPREPLY[@]}
@@ -1491,7 +1496,7 @@ function _complete_astra_group_db_command_createcollection() {
14911496
COMMANDS=$1
14921497

14931498
FLAG_OPTS="--no-color --async -v --verbose"
1494-
ARG_OPTS="--token -m --keyspace --config-file --indexing-allow -o --metric --embedding-model --default-id --timeout --config --indexing-deny -cf --dimension -c -d -conf --collection --embedding-provider --env -k --output"
1499+
ARG_OPTS="--token -m --keyspace --config-file --indexing-allow -o --metric --embedding-model --default-id --timeout --config --indexing-deny -cf --dimension -c -d --embedding-key -conf --collection --embedding-provider --env -k --output"
14951500

14961501
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
14971502
SAW_ARG=$?
@@ -1559,6 +1564,11 @@ function _complete_astra_group_db_command_createcollection() {
15591564
echo ${COMPREPLY[@]}
15601565
return 0
15611566
;;
1567+
--embedding-key)
1568+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1569+
echo ${COMPREPLY[@]}
1570+
return 0
1571+
;;
15621572
--embedding-provider)
15631573
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
15641574
echo ${COMPREPLY[@]}
@@ -1583,6 +1593,71 @@ function _complete_astra_group_db_command_createcollection() {
15831593
return 0
15841594
}
15851595

1596+
function _complete_astra_group_db_command_describecollection() {
1597+
# Get completion data
1598+
COMPREPLY=()
1599+
CURR_WORD=${COMP_WORDS[COMP_CWORD]}
1600+
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
1601+
COMMANDS=$1
1602+
1603+
FLAG_OPTS="--no-color --async -v --verbose"
1604+
ARG_OPTS="--token --config-file --keyspace -o --timeout --config -cf -c -conf --collection --env -k --output"
1605+
1606+
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
1607+
SAW_ARG=$?
1608+
if [[ ${SAW_ARG} -eq 0 ]]; then
1609+
ARG_VALUES=
1610+
ARG_GENERATED_VALUES=
1611+
case ${PREV_WORD} in
1612+
--token)
1613+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1614+
echo ${COMPREPLY[@]}
1615+
return 0
1616+
;;
1617+
-cf|--config-file)
1618+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1619+
echo ${COMPREPLY[@]}
1620+
return 0
1621+
;;
1622+
-k|--keyspace)
1623+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1624+
echo ${COMPREPLY[@]}
1625+
return 0
1626+
;;
1627+
-conf|--config)
1628+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1629+
echo ${COMPREPLY[@]}
1630+
return 0
1631+
;;
1632+
-c|--collection)
1633+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1634+
echo ${COMPREPLY[@]}
1635+
return 0
1636+
;;
1637+
--timeout)
1638+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1639+
echo ${COMPREPLY[@]}
1640+
return 0
1641+
;;
1642+
--env)
1643+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1644+
echo ${COMPREPLY[@]}
1645+
return 0
1646+
;;
1647+
-o|--output)
1648+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1649+
echo ${COMPREPLY[@]}
1650+
return 0
1651+
;;
1652+
esac
1653+
fi
1654+
1655+
ARGUMENTS=
1656+
COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${ARGUMENTS}" -- ${CURR_WORD}) )
1657+
echo ${COMPREPLY[@]}
1658+
return 0
1659+
}
1660+
15861661
function _complete_astra_group_db_command_createregion() {
15871662
# Get completion data
15881663
COMPREPLY=()
@@ -4353,25 +4428,25 @@ function _complete_astra_command_setup() {
43534428
COMMANDS=$1
43544429

43554430
FLAG_OPTS="--no-color -v --verbose"
4356-
ARG_OPTS="-cf --token --config-file -o -t -e --env --output"
4431+
ARG_OPTS="--token -cf --config-file -o -e --env --output"
43574432

43584433
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
43594434
SAW_ARG=$?
43604435
if [[ ${SAW_ARG} -eq 0 ]]; then
43614436
ARG_VALUES=
43624437
ARG_GENERATED_VALUES=
43634438
case ${PREV_WORD} in
4364-
-cf|--config-file)
4439+
--token)
43654440
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
43664441
echo ${COMPREPLY[@]}
43674442
return 0
43684443
;;
4369-
-e|--env)
4444+
-cf|--config-file)
43704445
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
43714446
echo ${COMPREPLY[@]}
43724447
return 0
43734448
;;
4374-
-t|--token)
4449+
-e|--env)
43754450
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
43764451
echo ${COMPREPLY[@]}
43774452
return 0
@@ -4398,25 +4473,25 @@ function _complete_astra_command_login() {
43984473
COMMANDS=$1
43994474

44004475
FLAG_OPTS="--no-color -v --verbose"
4401-
ARG_OPTS="-cf --token --config-file -o -t -e --env --output"
4476+
ARG_OPTS="--token -cf --config-file -o -e --env --output"
44024477

44034478
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
44044479
SAW_ARG=$?
44054480
if [[ ${SAW_ARG} -eq 0 ]]; then
44064481
ARG_VALUES=
44074482
ARG_GENERATED_VALUES=
44084483
case ${PREV_WORD} in
4409-
-cf|--config-file)
4484+
--token)
44104485
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
44114486
echo ${COMPREPLY[@]}
44124487
return 0
44134488
;;
4414-
-e|--env)
4489+
-cf|--config-file)
44154490
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
44164491
echo ${COMPREPLY[@]}
44174492
return 0
44184493
;;
4419-
-t|--token)
4494+
-e|--env)
44204495
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
44214496
echo ${COMPREPLY[@]}
44224497
return 0

src/main/java/com/dtsx/astra/cli/AstraCli.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
import com.datastax.astra.client.exception.AuthenticationException;
24+
import com.datastax.astra.internal.utils.AnsiUtils;
2425
import com.dtsx.astra.cli.config.ConfigCreateCmd;
2526
import com.dtsx.astra.cli.config.ConfigDeleteCmd;
2627
import com.dtsx.astra.cli.config.ConfigDescribeCmd;
@@ -55,7 +56,10 @@
5556
import com.dtsx.astra.cli.db.cdc.DbListCdcCmd;
5657
import com.dtsx.astra.cli.db.collection.DbCreateCollectionCmd;
5758
import com.dtsx.astra.cli.db.collection.DbDeleteCollectionCmd;
59+
import com.dtsx.astra.cli.db.collection.DbDescribeCollectionCmd;
60+
import com.dtsx.astra.cli.db.collection.DbDescribeEmbeddingProviderCmd;
5861
import com.dtsx.astra.cli.db.collection.DbListCollectionsCmd;
62+
import com.dtsx.astra.cli.db.collection.DbListEmbeddingProvidersCmd;
5963
import com.dtsx.astra.cli.db.cqlsh.DbCqlShellCmd;
6064
import com.dtsx.astra.cli.db.dsbulk.DbCountCmd;
6165
import com.dtsx.astra.cli.db.dsbulk.DbLoadCmd;
@@ -177,7 +181,9 @@
177181
// Keyspaces
178182
DbCreateKeyspaceCmd.class, DbDeleteKeyspaceCmd.class, DbListKeyspacesCmd.class,
179183
// Collections
180-
DbListCollectionsCmd.class, DbDeleteCollectionCmd.class, DbCreateCollectionCmd.class,
184+
DbListCollectionsCmd.class, DbDeleteCollectionCmd.class, DbCreateCollectionCmd.class, DbDescribeCollectionCmd.class,
185+
// Vectorize
186+
DbListEmbeddingProvidersCmd.class, DbDescribeEmbeddingProviderCmd.class,
181187
// Regions
182188
DbCreateRegionCmd.class, DbListRegionsCmd.class, DbDeleteRegionCmd.class,
183189
// DB Service Regions and Cloud
@@ -295,12 +301,11 @@ public static ExitCode run(Class<?> clazz, String[] args) {
295301
"You provided unknown or not well formatted argument.");
296302
return ExitCode.INVALID_ARGUMENT;
297303
} catch(ParseOptionIllegalValueException | ParseOptionMissingException ex) {
298-
LoggerShell.exception(ex,
299-
"You provided unknown or not well formatted option. (-option)");
304+
LoggerShell.exception(ex, null);
300305
return ExitCode.INVALID_OPTION;
301306
} catch(ParseRestrictionViolatedException | ParseOptionConversionException ex) {
302307
LoggerShell.exception(ex,
303-
"You provided an invalid value for option. (-option)");
308+
"You provided an invalid value for option.");
304309
return ExitCode.INVALID_OPTION_VALUE;
305310
} catch(InvalidRegionException regionException) {
306311
LoggerShell.exception(regionException,null);

src/main/java/com/dtsx/astra/cli/config/SetupCmd.java

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* #L%
2121
*/
2222

23+
import com.datastax.astra.internal.utils.AnsiUtils;
2324
import com.dtsx.astra.cli.core.AbstractCmd;
2425
import com.dtsx.astra.cli.core.exception.InvalidTokenException;
2526
import com.dtsx.astra.cli.core.out.AstraCliConsole;
@@ -29,6 +30,7 @@
2930
import com.dtsx.astra.sdk.utils.AstraEnvironment;
3031
import com.github.rvesse.airline.annotations.Command;
3132
import com.github.rvesse.airline.annotations.Option;
33+
import com.github.rvesse.airline.annotations.restrictions.Required;
3234

3335
import java.io.Console;
3436
import java.util.Arrays;
@@ -45,8 +47,9 @@
4547
public class SetupCmd extends AbstractCmd {
4648

4749
/** Authentication token used if not provided in config. */
48-
@Option(name = { "-t", "--token" },
49-
title = "TOKEN",
50+
@Required
51+
@Option(name = { "--token" },
52+
title = "TOKEN",
5053
description = "Key to use authenticate each call.")
5154
protected String token;
5255

@@ -62,31 +65,7 @@ public void execute() {
6265
AstraEnvironment targetEnv = AstraCliUtils.parseEnvironment(env);
6366
// As not token is provided we ask for it in the console
6467
if (token == null || token.isBlank()) {
65-
verbose = true;
66-
AstraCliConsole.banner();
67-
boolean validToken = false;
68-
Console cons;
69-
char[] tokenFromConsole;
70-
while (!validToken) {
71-
try {
72-
if ((cons = System.console()) != null &&
73-
(tokenFromConsole = cons.readPassword("[%s]", "$ Enter an Astra token:")) != null) {
74-
token = String.valueOf(tokenFromConsole);
7568

76-
// Clear the password from memory immediately when done
77-
Arrays.fill(tokenFromConsole, ' ');
78-
} else {
79-
try (Scanner scanner = new Scanner(System.in)) {
80-
AstraCliConsole.println("$ Enter an Astra token:", CYAN_400);
81-
token = scanner.nextLine();
82-
}
83-
}
84-
sectionName = new AstraOpsClient(token, targetEnv).getOrganization().getName();
85-
validToken = true;
86-
} catch(InvalidTokenException ite) {
87-
LoggerShell.error("Your token in invalid please retry " + ite.getMessage());
88-
}
89-
}
9069
}
9170
createDefaultSection();
9271
}
@@ -108,7 +87,12 @@ private void createDefaultSection()
10887
AstraCliConsole.outputSuccess("Setup completed.");
10988
LoggerShell.info("Enter 'astra help' to list available commands.");
11089
} catch(Exception e) {
111-
LoggerShell.warning("Invalid token: Must be start with 'AstraCS:..' and have Organization Administrator privileges.");
90+
LoggerShell.error(AnsiUtils.yellow("Invalid Token") + ", please check that:" +
91+
"\n- Your token starts with " + AnsiUtils.cyan("AstraCS:") +
92+
"\n- Your token has " + AnsiUtils.cyan("Organization Administrator") + " permissions to run all commands." +
93+
"\n- Your token has " + AnsiUtils.cyan("97") + " characters, for information yours had " + AnsiUtils.cyan(String.valueOf(token.length())) +
94+
"\n- You are targeting " + AnsiUtils.cyan("Astra Production") + ". if not, use " + AnsiUtils.cyan("astra config create default --token ${token} --env ${env}") +
95+
"\n- Your token is not expired.");
11296
throw new InvalidTokenException(token, e);
11397
}
11498
}

src/main/java/com/dtsx/astra/cli/core/AbstractConnectedCmd.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public void run() {
5757
token = removeQuotesIfAny(token);
5858
configSectionName = removeQuotesIfAny(configSectionName);
5959
validateOptions();
60-
6160
ctx().init(new CoreOptions(verbose, noColor, OutputFormat.valueOf(output.toUpperCase(Locale.ROOT)), configFilename));
6261
ctx().initToken(new TokenOptions(token, configSectionName, AstraCliUtils.parseEnvironment(env)));
6362
execute();

src/main/java/com/dtsx/astra/cli/core/CliContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private void loadCredentialsFromSection()
168168
tokenOptions.section(), targetEnv);
169169

170170
} else {
171-
throw new TokenNotFoundException();
171+
throw new TokenNotFoundException(tokenOptions.section(), null);
172172
}
173173
}
174174

0 commit comments

Comments
 (0)