Skip to content

Commit

Permalink
fix: make flags more consumable (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop authored Apr 25, 2022
1 parent 3448703 commit a04e154
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
8 changes: 5 additions & 3 deletions build/dev/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ services:
- '8000:8000'
environment:
DEBUG: "true"
HASURA_METADATA: 1
HASURA_ENDPOINT: http://graphql-engine:8080/v1
HASURA_ADMIN_SECRET: ${HASURA_ADMIN_SECRET:-hello123}
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET:-hello123}
S3_ENDPOINT: http://minio:9000
S3_ACCESS_KEY: ${S3_ACCESS_KEY:-5a7bdb5f42c41e0622bf61d6e08d5537}
S3_SECRET_KEY: ${S3_SECRET_KEY:-9e1c40c65a615a5b52f52aeeaf549944ec53acb1dff4a0bf01fb58e969f915c8}
S3_REGION: "us-east-1"
S3_BUCKET: "default"
S3_ROOT_FOLDER: "f215cf48-7458-4596-9aa5-2159fc6a3caf"
command: serve --postgres-migrations --postgres-migrations-source ${HASURA_GRAPHQL_DATABASE_URL:-postgres://postgres:hejsan@postgres:5432/postgres?sslmode=disable} --hasura-metadata --hasura-admin-secret ${HASURA_ADMIN_SECRET:-hello123}
POSTGRES_MIGRATIONS: 1
POSTGRES_MIGRATIONS_SOURCE: ${HASURA_GRAPHQL_DATABASE_URL:-postgres://postgres:hejsan@postgres:5432/postgres?sslmode=disable}
command: serve
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"strings"

"github.com/nhost/hasura-storage/controller"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -40,6 +41,7 @@ func init() {

func initConfig() {
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))

if cfgFile != "" {
// Use config file from the flag.
Expand Down
40 changes: 20 additions & 20 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const (
publicURLFlag = "public-url"
bindFlag = "bind"
trustedProxiesFlag = "trusted-proxies"
hasuraEndpointFlag = "hasura_endpoint"
hasuraEndpointFlag = "hasura-endpoint"
hasuraMetadataFlag = "hasura-metadata"
hasuraAdminSecretFlag = "hasura-admin-secret" // nolint: gosec
s3EndpointFlag = "s3_endpoint"
s3AccessKeyFlag = "s3_access_key"
s3SecretKeyFlag = "s3_secret_key" // nolint: gosec
s3RegionFlag = "s3_region"
s3BucketFlag = "s3_bucket"
s3RootFolderFlag = "s3_root_folder"
hasuraAdminSecretFlag = "hasura-graphql-admin-secret" // nolint: gosec
s3EndpointFlag = "s3-endpoint"
s3AccessKeyFlag = "s3-access-key"
s3SecretKeyFlag = "s3-secret-key" // nolint: gosec
s3RegionFlag = "s3-region"
s3BucketFlag = "s3-bucket"
s3RootFolderFlag = "s3-root-folder"
postgresMigrationsFlag = "postgres-migrations"
postgresMigrationsSourceFlag = "postgres-migrations-source"
)
Expand Down Expand Up @@ -117,7 +117,7 @@ func applymigrations(
) {
if postgresMigrations {
if postgresSource == "" {
logger.Error("you need to specify --postgres-migrations-source")
logger.Error("you need to specify " + postgresMigrationsSourceFlag)
os.Exit(1)
}
logger.Info("applying postgres migrations")
Expand Down Expand Up @@ -163,7 +163,7 @@ func init() {
addStringFlag(serveCmd.Flags(), s3EndpointFlag, "", "S3 Endpoint")
addStringFlag(serveCmd.Flags(), s3AccessKeyFlag, "", "S3 Access key")
addStringFlag(serveCmd.Flags(), s3SecretKeyFlag, "", "S3 Secret key")
addStringFlag(serveCmd.Flags(), s3RegionFlag, "", "S3 region")
addStringFlag(serveCmd.Flags(), s3RegionFlag, "no-region", "S3 region")
addStringFlag(serveCmd.Flags(), s3BucketFlag, "", "S3 bucket")
addStringFlag(serveCmd.Flags(), s3RootFolderFlag, "", "All buckets will be created inside this root")
}
Expand Down Expand Up @@ -205,16 +205,16 @@ var serveCmd = &cobra.Command{

logger.WithFields(
logrus.Fields{
"debug": viper.GetBool(debugFlag),
"bind": viper.GetString(bindFlag),
"trusted-proxies": viper.GetStringSlice(trustedProxiesFlag),
"hasura_endpoint": viper.GetString(hasuraEndpointFlag),
"postgres-migrations": viper.GetBool(postgresMigrationsFlag),
"hasura-metadata": viper.GetBool(hasuraMetadataFlag),
"s3_endpoint": viper.GetString(s3EndpointFlag),
"s3_region": viper.GetString(s3RegionFlag),
"s3_bucket": viper.GetString(s3BucketFlag),
"s3_root_folder": viper.GetString(s3RootFolderFlag),
debugFlag: viper.GetBool(debugFlag),
bindFlag: viper.GetString(bindFlag),
trustedProxiesFlag: viper.GetStringSlice(trustedProxiesFlag),
hasuraEndpointFlag: viper.GetString(hasuraEndpointFlag),
postgresMigrationsFlag: viper.GetBool(postgresMigrationsFlag),
hasuraMetadataFlag: viper.GetBool(hasuraMetadataFlag),
s3EndpointFlag: viper.GetString(s3EndpointFlag),
s3RegionFlag: viper.GetString(s3RegionFlag),
s3BucketFlag: viper.GetString(s3BucketFlag),
s3RootFolderFlag: viper.GetString(s3RootFolderFlag),
},
).Debug("parameters")

Expand Down
16 changes: 8 additions & 8 deletions hasura-storage.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
debug: true
hasura_endpoint: http://localhost:8080/v1
hasura-endpoint: http://localhost:8080/v1
hasura-metadata: true
hasura-admin-secret: hello123
s3_endpoint: "http://localhost:9000"
s3_access_key: "5a7bdb5f42c41e0622bf61d6e08d5537"
s3_secret_key: "9e1c40c65a615a5b52f52aeeaf549944ec53acb1dff4a0bf01fb58e969f915c8"
s3_region: "us-east-1"
s3_bucket: "default"
s3_root_folder: "f215cf48-7458-4596-9aa5-2159fc6a3caf"
hasura-graphql-admin-secret: hello123
s3-endpoint: "http://localhost:9000"
s3-access-key: "5a7bdb5f42c41e0622bf61d6e08d5537"
s3-secret-key: "9e1c40c65a615a5b52f52aeeaf549944ec53acb1dff4a0bf01fb58e969f915c8"
s3-region: "us-east-1"
s3-bucket: "default"
s3-root-folder: "f215cf48-7458-4596-9aa5-2159fc6a3caf"
postgres-migrations: true
postgres-migrations-source: postgres://postgres:hejsan@localhost:5432/postgres?sslmode=disable

0 comments on commit a04e154

Please sign in to comment.