[server] add couchbase envs

This commit is contained in:
Lakhan Samani 2023-01-19 23:28:21 +05:30
parent 44879f1a8f
commit 504d0f34d7
3 changed files with 29 additions and 2 deletions

View File

@ -33,6 +33,10 @@ test-dynamodb:
docker run -d --name dynamodb-local-test -p 8000:8000 amazon/dynamodb-local:latest docker run -d --name dynamodb-local-test -p 8000:8000 amazon/dynamodb-local:latest
cd server && go clean --testcache && TEST_DBS="dynamodb" go test -p 1 -v ./test cd server && go clean --testcache && TEST_DBS="dynamodb" go test -p 1 -v ./test
docker rm -vf dynamodb-local-test docker rm -vf dynamodb-local-test
test-couchbase:
docker run -d --name couchbase-local-test -p 8091-8097:8091-8097 -p 11210:11210 -p 11207:11207 -p 18091-18095:18091-18095 -p 18096:18096 -p 18097:18097 couchbase:latest
cd server && go clean --testcache && TEST_DBS="couchbase" go test -p 1 -v ./test
docker rm -vf couchbase-local-test
test-all-db: test-all-db:
rm -rf server/test/test.db server/test/test.db-shm server/test/test.db-wal && rm -rf test.db test.db-shm test.db-wal rm -rf server/test/test.db server/test/test.db-shm server/test/test.db-wal && rm -rf test.db test.db-shm test.db-wal
docker run -d --name authorizer_scylla_db -p 9042:9042 scylladb/scylla docker run -d --name authorizer_scylla_db -p 9042:9042 scylladb/scylla

20
server/env/env.go vendored
View File

@ -81,6 +81,8 @@ func InitAllEnv() error {
osAwsRegion := os.Getenv(constants.EnvAwsRegion) osAwsRegion := os.Getenv(constants.EnvAwsRegion)
osAwsAccessKey := os.Getenv(constants.EnvAwsAccessKeyID) osAwsAccessKey := os.Getenv(constants.EnvAwsAccessKeyID)
osAwsSecretKey := os.Getenv(constants.EnvAwsSecretAccessKey) osAwsSecretKey := os.Getenv(constants.EnvAwsSecretAccessKey)
osCouchbaseBucket := os.Getenv(constants.EnvCouchbaseBucket)
osCouchbaseScope := os.Getenv(constants.EnvCouchbaseScope)
// os bool vars // os bool vars
osAppCookieSecure := os.Getenv(constants.EnvKeyAppCookieSecure) osAppCookieSecure := os.Getenv(constants.EnvKeyAppCookieSecure)
@ -134,17 +136,31 @@ func InitAllEnv() error {
if val, ok := envData[constants.EnvAwsAccessKeyID]; !ok || val == "" { if val, ok := envData[constants.EnvAwsAccessKeyID]; !ok || val == "" {
envData[constants.EnvAwsAccessKeyID] = osAwsAccessKey envData[constants.EnvAwsAccessKeyID] = osAwsAccessKey
} }
if osAwsAccessKey != "" && envData[constants.EnvAwsAccessKeyID] != osAwsRegion { if osAwsAccessKey != "" && envData[constants.EnvAwsAccessKeyID] != osAwsAccessKey {
envData[constants.EnvAwsAccessKeyID] = osAwsAccessKey envData[constants.EnvAwsAccessKeyID] = osAwsAccessKey
} }
if val, ok := envData[constants.EnvAwsSecretAccessKey]; !ok || val == "" { if val, ok := envData[constants.EnvAwsSecretAccessKey]; !ok || val == "" {
envData[constants.EnvAwsSecretAccessKey] = osAwsSecretKey envData[constants.EnvAwsSecretAccessKey] = osAwsSecretKey
} }
if osAwsSecretKey != "" && envData[constants.EnvAwsSecretAccessKey] != osAwsRegion { if osAwsSecretKey != "" && envData[constants.EnvAwsSecretAccessKey] != osAwsSecretKey {
envData[constants.EnvAwsSecretAccessKey] = osAwsSecretKey envData[constants.EnvAwsSecretAccessKey] = osAwsSecretKey
} }
if val, ok := envData[constants.EnvCouchbaseBucket]; !ok || val == "" {
envData[constants.EnvCouchbaseBucket] = osCouchbaseBucket
}
if osCouchbaseBucket != "" && envData[constants.EnvCouchbaseBucket] != osCouchbaseBucket {
envData[constants.EnvCouchbaseBucket] = osCouchbaseBucket
}
if val, ok := envData[constants.EnvCouchbaseScope]; !ok || val == "" {
envData[constants.EnvCouchbaseScope] = osCouchbaseScope
}
if osCouchbaseScope != "" && envData[constants.EnvCouchbaseScope] != osCouchbaseScope {
envData[constants.EnvCouchbaseScope] = osCouchbaseScope
}
if val, ok := envData[constants.EnvKeyAppURL]; !ok || val == "" { if val, ok := envData[constants.EnvKeyAppURL]; !ok || val == "" {
envData[constants.EnvKeyAppURL] = osAppURL envData[constants.EnvKeyAppURL] = osAppURL
} }

View File

@ -32,6 +32,9 @@ type RequiredEnv struct {
AwsRegion string `json:"AWS_REGION"` AwsRegion string `json:"AWS_REGION"`
AwsAccessKeyID string `json:"AWS_ACCESS_KEY_ID"` AwsAccessKeyID string `json:"AWS_ACCESS_KEY_ID"`
AwsSecretAccessKey string `json:"AWS_SECRET_ACCESS_KEY"` AwsSecretAccessKey string `json:"AWS_SECRET_ACCESS_KEY"`
// Couchbase related envs
CouchbaseBucket string `json:"COUCHBASE_BUCKET"`
CouchbaseScope string `json:"COUCHBASE_SCOPE"`
} }
// RequiredEnvObj is a simple in-memory store for sessions. // RequiredEnvObj is a simple in-memory store for sessions.
@ -93,6 +96,8 @@ func InitRequiredEnv() error {
awsRegion := os.Getenv(constants.EnvAwsRegion) awsRegion := os.Getenv(constants.EnvAwsRegion)
awsAccessKeyID := os.Getenv(constants.EnvAwsAccessKeyID) awsAccessKeyID := os.Getenv(constants.EnvAwsAccessKeyID)
awsSecretAccessKey := os.Getenv(constants.EnvAwsSecretAccessKey) awsSecretAccessKey := os.Getenv(constants.EnvAwsSecretAccessKey)
couchbaseBucket := os.Getenv(constants.EnvCouchbaseBucket)
couchbaseScope := os.Getenv(constants.EnvCouchbaseScope)
if strings.TrimSpace(redisURL) == "" { if strings.TrimSpace(redisURL) == "" {
if cli.ARG_REDIS_URL != nil && *cli.ARG_REDIS_URL != "" { if cli.ARG_REDIS_URL != nil && *cli.ARG_REDIS_URL != "" {
@ -151,6 +156,8 @@ func InitRequiredEnv() error {
AwsRegion: awsRegion, AwsRegion: awsRegion,
AwsAccessKeyID: awsAccessKeyID, AwsAccessKeyID: awsAccessKeyID,
AwsSecretAccessKey: awsSecretAccessKey, AwsSecretAccessKey: awsSecretAccessKey,
CouchbaseBucket: couchbaseBucket,
CouchbaseScope: couchbaseScope,
} }
RequiredEnvStoreObj = &RequiredEnvStore{ RequiredEnvStoreObj = &RequiredEnvStore{