From e8258a43703b87b31fd523890ed32deff0ae0cf0 Mon Sep 17 00:00:00 2001 From: Pranshi Date: Wed, 5 Jun 2024 11:29:53 +0530 Subject: [PATCH] update cli to start connector by default --- .../.hasura-connector/Dockerfile | 2 +- .../.hasura-connector/connector-metadata.yaml | 1 - src/cli/index.ts | 32 +++++++++++++++- src/cli/start.ts | 37 ------------------- 4 files changed, 31 insertions(+), 41 deletions(-) delete mode 100644 src/cli/start.ts diff --git a/connector-definition/.hasura-connector/Dockerfile b/connector-definition/.hasura-connector/Dockerfile index 7db4a00..879419d 100644 --- a/connector-definition/.hasura-connector/Dockerfile +++ b/connector-definition/.hasura-connector/Dockerfile @@ -12,4 +12,4 @@ ENV HASURA_CONNECTOR_PORT=8080 # Expose the port specified by the HASURA_CONNECTOR_PORT environment variable EXPOSE $HASURA_CONNECTOR_PORT -ENTRYPOINT [ "./dist/cli/index.js", "start" ] \ No newline at end of file +ENTRYPOINT [ "./dist/cli/index.js" ] \ No newline at end of file diff --git a/connector-definition/.hasura-connector/connector-metadata.yaml b/connector-definition/.hasura-connector/connector-metadata.yaml index 9ab864d..b40d4a8 100644 --- a/connector-definition/.hasura-connector/connector-metadata.yaml +++ b/connector-definition/.hasura-connector/connector-metadata.yaml @@ -12,4 +12,3 @@ supportedEnvironmentVariables: default: "100" commands: update: docker run --rm -e AZURE_COSMOS_KEY="$AZURE_COSMOS_KEY" -e AZURE_COSMOS_DB_NAME="$AZURE_COSMOS_DB_NAME" -e AZURE_COSMOS_ENDPOINT="$AZURE_COSMOS_ENDPOINT" -v "$HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH":/etc/connector ghcr.io/hasura/ndc-azure-cosmos:v0.1.1 update - start: docker run --rm -e AZURE_COSMOS_KEY="$AZURE_COSMOS_KEY" -e AZURE_COSMOS_DB_NAME="$AZURE_COSMOS_DB_NAME" -e AZURE_COSMOS_ENDPOINT="$AZURE_COSMOS_ENDPOINT" -v "$HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH":/etc/connector ghcr.io/hasura/ndc-azure-cosmos:v0.1.1 start diff --git a/src/cli/index.ts b/src/cli/index.ts index 929a6b5..2e4350e 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -2,7 +2,6 @@ import { Command, Option } from "commander"; import * as updateCmd from "./update"; -import * as startCmd from "./start"; import { createConnector } from "../connector"; import { version } from "../../package.json" import * as sdk from "@hasura/ndc-sdk-typescript"; @@ -12,9 +11,38 @@ function main() { program.addCommand(updateCmd.cmd); - program.addCommand(startCmd.cmd); + program.action(async (options: sdk.ServerOptions) => { + program.addOption( + new Option("--configuration ") + .env("HASURA_CONFIGURATION_DIRECTORY") + .default(".") + ) + program.addOption( + new Option("--port ") + .env("HASURA_CONNECTOR_PORT") + .default(8080) + .argParser(parseIntOption) + ) + program.addOption( + new Option("--service-token-secret ").env("HASURA_SERVICE_TOKEN_SECRET") + ) + program.addOption(new Option("--log-level ").env("HASURA_LOG_LEVEL").default("info")) + program.addOption(new Option("--pretty-print-logs").env("HASURA_PRETTY_PRINT_LOGS").default(false)) + + const connector = createConnector(); + await sdk.startServer(connector, options) + }); program.parse(process.argv); } +function parseIntOption(value: string, _previous: number): number { + // parseInt takes a string and a radix + const parsedValue = parseInt(value, 10); + if (isNaN(parsedValue)) { + console.error("Not a valid integer."); + } + return parsedValue; +} + main() diff --git a/src/cli/start.ts b/src/cli/start.ts deleted file mode 100644 index 7037a13..0000000 --- a/src/cli/start.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Command, Option } from "commander"; -import * as sdk from "@hasura/ndc-sdk-typescript"; -import { createConnector } from "../connector" - -export const cmd = new Command("start") - .description( - "Imports the containers from the specified Azure Cosmos DB and infers the schema by introspecting the containers." - ) - .addOption( - new Option("--configuration ") - .env("HASURA_CONFIGURATION_DIRECTORY") - .default(".") - ) - .addOption( - new Option("--port ") - .env("HASURA_CONNECTOR_PORT") - .default(8080) - .argParser(parseIntOption) - ) - .addOption( - new Option("--service-token-secret ").env("HASURA_SERVICE_TOKEN_SECRET") - ) - .addOption(new Option("--log-level ").env("HASURA_LOG_LEVEL").default("info")) - .addOption(new Option("--pretty-print-logs").env("HASURA_PRETTY_PRINT_LOGS").default(false)) - .action(async (options: sdk.ServerOptions) => { - const connector = createConnector(); - await sdk.startServer(connector, options) - }); - -function parseIntOption(value: string, _previous: number): number { - // parseInt takes a string and a radix - const parsedValue = parseInt(value, 10); - if (isNaN(parsedValue)) { - console.error("Not a valid integer."); - } - return parsedValue; -}