-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update config file and remove todo reminders
Also, update test and docker related files
- Loading branch information
1 parent
1107e9a
commit 3ae10ba
Showing
7 changed files
with
87 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,17 @@ package config | |
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
var ( | ||
Version string | ||
port string | ||
env string | ||
) | ||
|
||
type Config struct { | ||
BaseURL string | ||
Port int | ||
Env string | ||
DB struct { | ||
Port int | ||
Env string | ||
DB struct { | ||
Dsn string | ||
MaxOpenConns int | ||
MaxIdleConns int | ||
|
@@ -37,34 +32,41 @@ type Config struct { | |
Jwt struct { | ||
Secret string | ||
} | ||
Auth struct { | ||
HttpBaseURL string | ||
GrpcBaseURL string | ||
GrpcServerPort int | ||
HttpPort int | ||
} | ||
} | ||
|
||
func Init() (cfg Config, err error) { | ||
intPort, _ := strconv.Atoi(port) | ||
|
||
flag.StringVar(&cfg.BaseURL, "base-url", os.Getenv("BASE_URL"), "base URL for the application") | ||
flag.IntVar(&cfg.Port, "port", intPort, "API server port") | ||
flag.StringVar(&cfg.Env, "env", env, "Environment (development|staging|production)") | ||
flag.StringVar(&cfg.DB.Dsn, "db-dsn", os.Getenv( | ||
"DATABASE_URL"), "PostgreSQL DSN") | ||
flag.IntVar(&cfg.Port, "port", 8080, "API server port") | ||
flag.StringVar(&cfg.Env, "env", "development", "Environment (development|staging|production)") | ||
flag.StringVar(&cfg.DB.Dsn, "db-dsn", "postgres://greenlight:pa55word@localhost/greenlight?sslmode=disable", "PostgreSQL DSN") | ||
flag.IntVar(&cfg.DB.MaxOpenConns, "db-max-open-conns", 25, "PostgreSQL max open connections") | ||
flag.IntVar(&cfg.DB.MaxIdleConns, "db-max-idle-conns", 25, "PostgreSQL max idle connections") | ||
flag.StringVar(&cfg.DB.MaxIdleTime, "db-max-idle-time", "15m", "PostgreSQL max connection idle time") | ||
|
||
smtpPort, _ := strconv.Atoi(os.Getenv("SMTP_PORT")) | ||
|
||
flag.StringVar(&cfg.Smtp.Host, "smtp-host", os.Getenv("SMTP_HOST"), "SMTP host") | ||
flag.IntVar(&cfg.Smtp.Port, "smtp-port", smtpPort, "SMTP port") | ||
flag.StringVar(&cfg.Smtp.Username, "smtp-username", os.Getenv("SMTP_USERNAME"), "SMTP username") | ||
flag.StringVar(&cfg.Smtp.Password, "smtp-password", os.Getenv("SMTP_PASSWORD"), "SMTP password") | ||
flag.StringVar(&cfg.Smtp.From, "smtp-sender", os.Getenv("SMTP_SENDER"), "SMTP sender") | ||
flag.StringVar(&cfg.Smtp.Host, "smtp-host", "example.smtp.host", "SMTP host") | ||
flag.IntVar(&cfg.Smtp.Port, "smtp-port", 25, "SMTP port") | ||
flag.StringVar(&cfg.Smtp.Username, "smtp-username", "example_username", "SMTP username") | ||
flag.StringVar(&cfg.Smtp.Password, "smtp-password", "example_password", "SMTP password") | ||
flag.StringVar(&cfg.Smtp.From, "smtp-sender", "Example Name <[email protected]>", "SMTP sender") | ||
|
||
flag.Func("cors-trusted-origins", "Trusted CORS origins (space separated)", func(val string) error { | ||
cfg.Cors.TrustedOrigins = strings.Fields(val) | ||
return nil | ||
}) | ||
|
||
flag.StringVar(&cfg.Jwt.Secret, "jwt-secret", os.Getenv("JWT_SECRET"), "JWT secret") | ||
flag.StringVar(&cfg.Jwt.Secret, "jwt-secret", "56vphh6sheco5sbtfkxwesy3wx7fpiip", "JWT secret") | ||
|
||
flag.StringVar(&cfg.Auth.HttpBaseURL, "base-url", "http://localhost:8080", "base URL for the application") | ||
flag.StringVar(&cfg.Auth.GrpcBaseURL, "auth-grpc-client-base-url", "localhost:50051", "GRPC client") | ||
|
||
flag.IntVar(&cfg.Auth.HttpPort, "auth-http-port", 8082, "port to listen on for HTTP requests for auth module") | ||
|
||
flag.IntVar(&cfg.Auth.GrpcServerPort, "auth-grpc-port", 50051, "port to listen on for GRPC methods for auth module") | ||
|
||
displayVersion := flag.Bool("version", false, "Display version and exit") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ func Init() (mocks.UserRepository, mocks.TokenRepository, mocks.PermissionReposi | |
permissionRepo := mocks.PermissionRepository{} | ||
wg := sync.WaitGroup{} | ||
cfg := config.Config{ | ||
BaseURL: "localhost:8082", | ||
Jwt: struct { | ||
Secret string | ||
}{ | ||
|
@@ -43,6 +42,17 @@ func Init() (mocks.UserRepository, mocks.TokenRepository, mocks.PermissionReposi | |
Password: "password", | ||
From: "Greenlight <[email protected]>", | ||
}, | ||
Auth: struct { | ||
HttpBaseURL string | ||
GrpcBaseURL string | ||
GrpcServerPort int | ||
HttpPort int | ||
}{ | ||
HttpBaseURL: "localhost:8082", | ||
GrpcBaseURL: "localhost:50051", | ||
GrpcServerPort: 50051, | ||
HttpPort: 8082, | ||
}, | ||
} | ||
return userRepo, tokenRepo, permissionRepo, cfg, wg | ||
} | ||
|
@@ -282,8 +292,8 @@ func TestAppl_CreateAuthTokenUseCase(t *testing.T) { | |
|
||
expectedUserID := int64(1) | ||
expectedSubject := strconv.FormatInt(expectedUserID, 10) | ||
expectedIssuer := cfg.BaseURL | ||
expectedAudience := []string{cfg.BaseURL} | ||
expectedIssuer := cfg.Auth.HttpBaseURL | ||
expectedAudience := []string{cfg.Auth.HttpBaseURL} | ||
|
||
// Act | ||
tokenBytes, err := appl.CreateAuthTokenUseCase(expectedUserID) | ||
|
@@ -299,7 +309,17 @@ func TestAppl_CreateAuthTokenUseCase(t *testing.T) { | |
t.Run("Error", func(t *testing.T) { | ||
// Arrange | ||
cfg := config.Config{ | ||
BaseURL: "localhost:8082", | ||
Auth: struct { | ||
HttpBaseURL string | ||
GrpcBaseURL string | ||
GrpcServerPort int | ||
HttpPort int | ||
}{ | ||
HttpBaseURL: "localhost:8082", | ||
GrpcBaseURL: "localhost:50051", | ||
GrpcServerPort: 50051, | ||
HttpPort: 8082, | ||
}, | ||
} | ||
userRepo, tokenRepo, permissionRepo, _, wg := Init() | ||
appl := NewAppl(&userRepo, &tokenRepo, &permissionRepo, &wg, cfg) | ||
|
@@ -341,7 +361,17 @@ func TestAppl_ValidateAuthTokenUseCase(t *testing.T) { | |
// Arrange | ||
userRepo, tokenRepo, permissionRepo, _, wg := Init() | ||
cfg := config.Config{ | ||
BaseURL: "localhost:8082", | ||
Auth: struct { | ||
HttpBaseURL string | ||
GrpcBaseURL string | ||
GrpcServerPort int | ||
HttpPort int | ||
}{ | ||
HttpBaseURL: "localhost:8082", | ||
GrpcBaseURL: "localhost:50051", | ||
GrpcServerPort: 50051, | ||
HttpPort: 8082, | ||
}, | ||
} | ||
appl := NewAppl(&userRepo, &tokenRepo, &permissionRepo, &wg, cfg) | ||
expectedUserID := int64(1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters