Compare commits

...

6 Commits

Author SHA1 Message Date
Lakhan Samani
8b510ed556 fix: env parsing 2021-10-09 23:49:20 +05:30
Lakhan Samani
3ac0b44446 fix: remove unused env and fix typo 2021-10-09 22:29:10 +05:30
Lakhan Samani
b1dd6f2c3b chore: update app dependencies 2021-10-09 18:27:38 +05:30
Lakhan Samani
f5ea94f63c Merge branch 'main' of https://github.com/authorizerdev/authorizer 2021-10-09 10:06:15 +05:30
Lakhan Samani
6fed439ec2 Merge branch 'main' of https://github.com/authorizerdev/authorizer 2021-10-09 10:01:47 +05:30
Lakhan Samani
75709e9f48 fix: role validation for given token 2021-10-09 09:39:50 +05:30
6 changed files with 1471 additions and 1484 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2832
app/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,25 +1,25 @@
{ {
"name": "app", "name": "app",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "esbuild src/index.tsx --bundle --minify --sourcemap --outfile=build/bundle.js" "build": "esbuild src/index.tsx --bundle --minify --sourcemap --outfile=build/bundle.js"
}, },
"keywords": [], "keywords": [],
"author": "Lakhan Samani", "author": "Lakhan Samani",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@authorizerdev/authorizer-react": "^0.1.0-beta.17", "@authorizerdev/authorizer-react": "^0.1.0-beta.18",
"@types/react": "^17.0.15", "@types/react": "^17.0.15",
"@types/react-dom": "^17.0.9", "@types/react-dom": "^17.0.9",
"esbuild": "^0.12.17", "esbuild": "^0.12.17",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
"react-router-dom": "^5.2.0", "react-router-dom": "^5.2.0",
"typescript": "^4.3.5" "typescript": "^4.3.5"
}, },
"devDependencies": { "devDependencies": {
"@types/react-router-dom": "^5.1.8" "@types/react-router-dom": "^5.1.8"
} }
} }

View File

@@ -13,7 +13,6 @@ var (
JWT_TYPE = "" JWT_TYPE = ""
JWT_SECRET = "" JWT_SECRET = ""
ALLOWED_ORIGINS = []string{} ALLOWED_ORIGINS = []string{}
ALLOWED_CALLBACK_URLS = []string{}
AUTHORIZER_URL = "" AUTHORIZER_URL = ""
PORT = "8080" PORT = "8080"
REDIS_URL = "" REDIS_URL = ""

View File

@@ -11,43 +11,33 @@ import (
) )
// build variables // build variables
var Version string var (
Version string
// ParseArgs -> to parse the cli flag and get db url. This is useful with heroku button ARG_DB_URL *string
func ParseArgs() { ARG_DB_TYPE *string
dbURL := flag.String("database_url", "", "Database connection string") ARG_AUTHORIZER_URL *string
dbType := flag.String("databse_type", "", "Database type, possible values are postgres,mysql,sqlite") ARG_ENV_FILE *string
authorizerURL := flag.String("authorizer_url", "", "URL for authorizer instance, eg: https://xyz.herokuapp.com") )
flag.Parse()
if *dbURL != "" {
constants.DATABASE_URL = *dbURL
}
if *dbType != "" {
constants.DATABASE_TYPE = *dbType
}
if *authorizerURL != "" {
constants.AUTHORIZER_URL = *authorizerURL
}
}
// InitEnv -> to initialize env and through error if required env are not present // InitEnv -> to initialize env and through error if required env are not present
func InitEnv() { func InitEnv() {
envPath := `.env` envPath := `.env`
envFile := flag.String("env_file", "", "Env file path") ARG_DB_URL = flag.String("database_url", "", "Database connection string")
ARG_DB_TYPE = flag.String("database_type", "", "Database type, possible values are postgres,mysql,sqlite")
ARG_AUTHORIZER_URL = flag.String("authorizer_url", "", "URL for authorizer instance, eg: https://xyz.herokuapp.com")
ARG_ENV_FILE = flag.String("env_file", "", "Env file path")
flag.Parse() flag.Parse()
if *envFile != "" { if *ARG_ENV_FILE != "" {
envPath = *envFile envPath = *ARG_ENV_FILE
} }
err := godotenv.Load(envPath) err := godotenv.Load(envPath)
if err != nil { if err != nil {
log.Println("Error loading .env file") log.Println("Error loading .env file")
} }
constants.VERSION = Version constants.VERSION = Version
constants.ADMIN_SECRET = os.Getenv("ADMIN_SECRET") constants.ADMIN_SECRET = os.Getenv("ADMIN_SECRET")
constants.ENV = os.Getenv("ENV") constants.ENV = os.Getenv("ENV")
constants.DATABASE_TYPE = os.Getenv("DATABASE_TYPE") constants.DATABASE_TYPE = os.Getenv("DATABASE_TYPE")
@@ -104,20 +94,18 @@ func InitEnv() {
} }
constants.ALLOWED_ORIGINS = allowedOrigins constants.ALLOWED_ORIGINS = allowedOrigins
allowedCallbackSplit := strings.Split(os.Getenv("ALLOWED_CALLBACK_URLS"), ",") if *ARG_AUTHORIZER_URL != "" {
allowedCallbacks := []string{} constants.AUTHORIZER_URL = *ARG_AUTHORIZER_URL
for _, val := range allowedCallbackSplit { }
trimVal := strings.TrimSpace(val)
if trimVal != "" { if *ARG_DB_URL != "" {
allowedCallbacks = append(allowedCallbacks, trimVal) constants.DATABASE_URL = *ARG_DB_URL
} }
if *ARG_DB_TYPE != "" {
constants.DATABASE_TYPE = *ARG_DB_TYPE
} }
if len(allowedCallbackSplit) == 0 {
allowedCallbackSplit = []string{"*"}
}
constants.ALLOWED_CALLBACK_URLS = allowedCallbackSplit
ParseArgs()
if constants.DATABASE_URL == "" { if constants.DATABASE_URL == "" {
panic("Database url is required") panic("Database url is required")
} }