Skip to content

Commit

Permalink
Push embedding functions
Browse files Browse the repository at this point in the history
  • Loading branch information
clun committed Aug 1, 2024
1 parent c88b01d commit 8ab22c2
Show file tree
Hide file tree
Showing 23 changed files with 3,796 additions and 107 deletions.
31 changes: 27 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@
<url>https://github.com/datastax/astra-cli</url>
<properties>

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

<astra-sdk.version>1.2.8-SNAPSHOT</astra-sdk.version>
<astra-db-java.version>1.2.0</astra-db-java.version>
<astra-sdk.version>1.2.8</astra-sdk.version>
<astra-db-java.version>1.4.3</astra-db-java.version>
<jansi.version>2.4.1</jansi.version>
<airline.version>3.0.0</airline.version>
<slf4j.version>2.0.13</slf4j.version>
<httpclient.version>5.1.2</httpclient.version>
<jackson-datatype.version>2.17.1</jackson-datatype.version>
<jackson-datatype.version>2.17.2</jackson-datatype.version>
<commons-compress.version>1.26.2</commons-compress.version>
<!-- Junit -->
<!-- TEST -->
<junit-jupiter.version>5.10.2</junit-jupiter.version>
<awaitibility.version>4.2.1</awaitibility.version>
<!-- Java -->
Expand All @@ -37,6 +39,7 @@
<version.maven.plugin.compiler>3.12.1</version.maven.plugin.compiler>
<version.maven.plugin.coveralls>4.3.0</version.maven.plugin.coveralls>
<version.maven.plugin.dependency>3.6.1</version.maven.plugin.dependency>
<version.maven.plugin.enforcer>3.5.0</version.maven.plugin.enforcer>
<version.maven.plugin.exec>3.3.0</version.maven.plugin.exec>
<version.maven.plugin.jacoco>0.8.12</version.maven.plugin.jacoco>
<version.maven.plugin.javadoc>3.6.0</version.maven.plugin.javadoc>
Expand Down Expand Up @@ -144,6 +147,26 @@
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${version.maven.plugin.enforcer}</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>${required-maven.version}</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand Down
95 changes: 85 additions & 10 deletions src/main/dist/astra-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ function _complete_astra_group_db() {
CURR_CMD=${COMP_WORDS[2]}
fi

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"
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"
if [[ ${COMP_CWORD} -eq 2 ]]; then
COMPREPLY=( $(_complete_astra_group_db_command_list "${COMMANDS}" ) )
DEFAULT_GROUP_COMMAND_COMPLETIONS=(${COMPREPLY[@]})
Expand Down Expand Up @@ -580,6 +580,11 @@ function _complete_astra_group_db() {
echo ${COMPREPLY[@]}
return $?
;;
describe-collection)
COMPREPLY=( $(_complete_astra_group_db_command_describecollection "${COMMANDS}" ) )
echo ${COMPREPLY[@]}
return $?
;;
create-region)
COMPREPLY=( $(_complete_astra_group_db_command_createregion "${COMMANDS}" ) )
echo ${COMPREPLY[@]}
Expand Down Expand Up @@ -1491,7 +1496,7 @@ function _complete_astra_group_db_command_createcollection() {
COMMANDS=$1

FLAG_OPTS="--no-color --async -v --verbose"
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"
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"

$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
SAW_ARG=$?
Expand Down Expand Up @@ -1559,6 +1564,11 @@ function _complete_astra_group_db_command_createcollection() {
echo ${COMPREPLY[@]}
return 0
;;
--embedding-key)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
--embedding-provider)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
Expand All @@ -1583,6 +1593,71 @@ function _complete_astra_group_db_command_createcollection() {
return 0
}

function _complete_astra_group_db_command_describecollection() {
# Get completion data
COMPREPLY=()
CURR_WORD=${COMP_WORDS[COMP_CWORD]}
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
COMMANDS=$1

FLAG_OPTS="--no-color --async -v --verbose"
ARG_OPTS="--token --config-file --keyspace -o --timeout --config -cf -c -conf --collection --env -k --output"

$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
SAW_ARG=$?
if [[ ${SAW_ARG} -eq 0 ]]; then
ARG_VALUES=
ARG_GENERATED_VALUES=
case ${PREV_WORD} in
--token)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-cf|--config-file)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-k|--keyspace)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-conf|--config)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-c|--collection)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
--timeout)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
--env)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-o|--output)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
esac
fi

ARGUMENTS=
COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${ARGUMENTS}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
}

function _complete_astra_group_db_command_createregion() {
# Get completion data
COMPREPLY=()
Expand Down Expand Up @@ -4353,25 +4428,25 @@ function _complete_astra_command_setup() {
COMMANDS=$1

FLAG_OPTS="--no-color -v --verbose"
ARG_OPTS="-cf --token --config-file -o -t -e --env --output"
ARG_OPTS="--token -cf --config-file -o -e --env --output"

$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
SAW_ARG=$?
if [[ ${SAW_ARG} -eq 0 ]]; then
ARG_VALUES=
ARG_GENERATED_VALUES=
case ${PREV_WORD} in
-cf|--config-file)
--token)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-e|--env)
-cf|--config-file)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-t|--token)
-e|--env)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
Expand All @@ -4398,25 +4473,25 @@ function _complete_astra_command_login() {
COMMANDS=$1

FLAG_OPTS="--no-color -v --verbose"
ARG_OPTS="-cf --token --config-file -o -t -e --env --output"
ARG_OPTS="--token -cf --config-file -o -e --env --output"

$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
SAW_ARG=$?
if [[ ${SAW_ARG} -eq 0 ]]; then
ARG_VALUES=
ARG_GENERATED_VALUES=
case ${PREV_WORD} in
-cf|--config-file)
--token)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-e|--env)
-cf|--config-file)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
;;
-t|--token)
-e|--env)
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
echo ${COMPREPLY[@]}
return 0
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/dtsx/astra/cli/AstraCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

import com.datastax.astra.client.exception.AuthenticationException;
import com.datastax.astra.internal.utils.AnsiUtils;
import com.dtsx.astra.cli.config.ConfigCreateCmd;
import com.dtsx.astra.cli.config.ConfigDeleteCmd;
import com.dtsx.astra.cli.config.ConfigDescribeCmd;
Expand Down Expand Up @@ -55,7 +56,10 @@
import com.dtsx.astra.cli.db.cdc.DbListCdcCmd;
import com.dtsx.astra.cli.db.collection.DbCreateCollectionCmd;
import com.dtsx.astra.cli.db.collection.DbDeleteCollectionCmd;
import com.dtsx.astra.cli.db.collection.DbDescribeCollectionCmd;
import com.dtsx.astra.cli.db.collection.DbDescribeEmbeddingProviderCmd;
import com.dtsx.astra.cli.db.collection.DbListCollectionsCmd;
import com.dtsx.astra.cli.db.collection.DbListEmbeddingProvidersCmd;
import com.dtsx.astra.cli.db.cqlsh.DbCqlShellCmd;
import com.dtsx.astra.cli.db.dsbulk.DbCountCmd;
import com.dtsx.astra.cli.db.dsbulk.DbLoadCmd;
Expand Down Expand Up @@ -177,7 +181,9 @@
// Keyspaces
DbCreateKeyspaceCmd.class, DbDeleteKeyspaceCmd.class, DbListKeyspacesCmd.class,
// Collections
DbListCollectionsCmd.class, DbDeleteCollectionCmd.class, DbCreateCollectionCmd.class,
DbListCollectionsCmd.class, DbDeleteCollectionCmd.class, DbCreateCollectionCmd.class, DbDescribeCollectionCmd.class,
// Vectorize
DbListEmbeddingProvidersCmd.class, DbDescribeEmbeddingProviderCmd.class,
// Regions
DbCreateRegionCmd.class, DbListRegionsCmd.class, DbDeleteRegionCmd.class,
// DB Service Regions and Cloud
Expand Down Expand Up @@ -295,12 +301,11 @@ public static ExitCode run(Class<?> clazz, String[] args) {
"You provided unknown or not well formatted argument.");
return ExitCode.INVALID_ARGUMENT;
} catch(ParseOptionIllegalValueException | ParseOptionMissingException ex) {
LoggerShell.exception(ex,
"You provided unknown or not well formatted option. (-option)");
LoggerShell.exception(ex, null);
return ExitCode.INVALID_OPTION;
} catch(ParseRestrictionViolatedException | ParseOptionConversionException ex) {
LoggerShell.exception(ex,
"You provided an invalid value for option. (-option)");
"You provided an invalid value for option.");
return ExitCode.INVALID_OPTION_VALUE;
} catch(InvalidRegionException regionException) {
LoggerShell.exception(regionException,null);
Expand Down
38 changes: 11 additions & 27 deletions src/main/java/com/dtsx/astra/cli/config/SetupCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* #L%
*/

import com.datastax.astra.internal.utils.AnsiUtils;
import com.dtsx.astra.cli.core.AbstractCmd;
import com.dtsx.astra.cli.core.exception.InvalidTokenException;
import com.dtsx.astra.cli.core.out.AstraCliConsole;
Expand All @@ -29,6 +30,7 @@
import com.dtsx.astra.sdk.utils.AstraEnvironment;
import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.Option;
import com.github.rvesse.airline.annotations.restrictions.Required;

import java.io.Console;
import java.util.Arrays;
Expand All @@ -45,8 +47,9 @@
public class SetupCmd extends AbstractCmd {

/** Authentication token used if not provided in config. */
@Option(name = { "-t", "--token" },
title = "TOKEN",
@Required
@Option(name = { "--token" },
title = "TOKEN",
description = "Key to use authenticate each call.")
protected String token;

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

// Clear the password from memory immediately when done
Arrays.fill(tokenFromConsole, ' ');
} else {
try (Scanner scanner = new Scanner(System.in)) {
AstraCliConsole.println("$ Enter an Astra token:", CYAN_400);
token = scanner.nextLine();
}
}
sectionName = new AstraOpsClient(token, targetEnv).getOrganization().getName();
validToken = true;
} catch(InvalidTokenException ite) {
LoggerShell.error("Your token in invalid please retry " + ite.getMessage());
}
}
}
createDefaultSection();
}
Expand All @@ -108,7 +87,12 @@ private void createDefaultSection()
AstraCliConsole.outputSuccess("Setup completed.");
LoggerShell.info("Enter 'astra help' to list available commands.");
} catch(Exception e) {
LoggerShell.warning("Invalid token: Must be start with 'AstraCS:..' and have Organization Administrator privileges.");
LoggerShell.error(AnsiUtils.yellow("Invalid Token") + ", please check that:" +
"\n- Your token starts with " + AnsiUtils.cyan("AstraCS:") +
"\n- Your token has " + AnsiUtils.cyan("Organization Administrator") + " permissions to run all commands." +
"\n- Your token has " + AnsiUtils.cyan("97") + " characters, for information yours had " + AnsiUtils.cyan(String.valueOf(token.length())) +
"\n- You are targeting " + AnsiUtils.cyan("Astra Production") + ". if not, use " + AnsiUtils.cyan("astra config create default --token ${token} --env ${env}") +
"\n- Your token is not expired.");
throw new InvalidTokenException(token, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public void run() {
token = removeQuotesIfAny(token);
configSectionName = removeQuotesIfAny(configSectionName);
validateOptions();

ctx().init(new CoreOptions(verbose, noColor, OutputFormat.valueOf(output.toUpperCase(Locale.ROOT)), configFilename));
ctx().initToken(new TokenOptions(token, configSectionName, AstraCliUtils.parseEnvironment(env)));
execute();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/dtsx/astra/cli/core/CliContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void loadCredentialsFromSection()
tokenOptions.section(), targetEnv);

} else {
throw new TokenNotFoundException();
throw new TokenNotFoundException(tokenOptions.section(), null);
}
}

Expand Down
Loading

0 comments on commit 8ab22c2

Please sign in to comment.