Skip to content

Commit 18a2140

Browse files
authored
Merge pull request #2 from daystram/dev
Dev
2 parents b3572b9 + 83eb62c commit 18a2140

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1301
-288
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ build ratify-be:
99
image: daystram/go-builder:1.15
1010
script:
1111
- cd ratify-be
12+
- swag init
1213
- go mod tidy
1314
- go build -a -o app .
1415
artifacts:
1516
paths:
1617
- ratify-be/app
18+
- ratify-be/docs/swagger.json
1719

1820
test ratify-be:
1921
stage: test

docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: "3"
2+
services:
3+
postgres:
4+
image: postgres:13.1-alpine
5+
ports:
6+
- "5432:5432"
7+
volumes:
8+
- /opt/postgres:/var/lib/postgresql/data
9+
restart: always
10+
redis:
11+
image: redis:6.0-alpine
12+
ports:
13+
- "6379:6379"
14+
volumes:
15+
- /opt/redis:/data
16+
restart: always

ratify-be/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Edit at https://www.toptal.com/developers/gitignore?templates=go,visualstudiocode,intellij+all,linux,macos,windows,vim,git
44

55
ratify-be
6+
config/config.yaml
7+
.air.toml
8+
docs/
69

710
### Git ###
811
# Created by git for backups. To disable backups in Git:

ratify-be/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM daystram/go-builder:1.15 as builder
22
WORKDIR /build
33
COPY . ./
4+
RUN swag init
45
RUN go mod tidy
56
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o app .
67

ratify-be/config/config.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
var AppConfig Config
1010

1111
type Config struct {
12+
Hostname string
1213
Port int
1314
Environment string
1415
Debug bool
@@ -19,6 +20,11 @@ type Config struct {
1920
DBUsername string
2021
DBPassword string
2122

23+
RedisHostname string
24+
RedisPort int
25+
RedisPassword string
26+
RedisDatabase int
27+
2228
Domain string
2329
JWTSecret string
2430
}
@@ -34,6 +40,11 @@ func InitializeAppConfig() {
3440
log.Fatalf("[INIT] Unable to load configuration. %+v\n", err)
3541
}
3642

43+
// Hostname
44+
if AppConfig.Hostname = viper.GetString("hostname"); AppConfig.Hostname == "" {
45+
log.Fatalln("[INIT] hostname is missing in config.yaml")
46+
}
47+
3748
// Port
3849
AppConfig.Port = viper.GetInt("port")
3950

@@ -46,27 +57,31 @@ func InitializeAppConfig() {
4657
AppConfig.Debug = viper.GetBool("debug")
4758

4859
// DBHostname
49-
if AppConfig.DBHostname = viper.GetString("db_hostname"); AppConfig.DBHostname == "" {
50-
log.Fatalln("[INIT] db_hostname is missing in config.yaml")
51-
}
60+
AppConfig.DBHostname = viper.GetString("db_hostname")
5261

5362
// DBPort
5463
AppConfig.DBPort = viper.GetInt("db_port")
5564

5665
// DBDatabase
57-
if AppConfig.DBDatabase = viper.GetString("db_database"); AppConfig.DBDatabase == "" {
58-
log.Fatalln("[INIT] db_database is missing in config.yaml")
59-
}
66+
AppConfig.DBDatabase = viper.GetString("db_database")
6067

6168
// DBUsername
62-
if AppConfig.DBUsername = viper.GetString("db_username"); AppConfig.DBUsername == "" {
63-
log.Fatalln("[INIT] db_username is missing in config.yaml")
64-
}
69+
AppConfig.DBUsername = viper.GetString("db_username")
6570

6671
// DBPassword
67-
if AppConfig.DBPassword = viper.GetString("db_password"); AppConfig.DBPassword == "" {
68-
log.Fatalln("[INIT] db_password is missing in config.yaml")
69-
}
72+
AppConfig.DBPassword = viper.GetString("db_password")
73+
74+
// RedisHostname
75+
AppConfig.RedisHostname = viper.GetString("redis_hostname")
76+
77+
// RedisPort
78+
AppConfig.RedisPort = viper.GetInt("redis_port")
79+
80+
// RedisPassword
81+
AppConfig.RedisPassword = viper.GetString("redis_password")
82+
83+
// RedisDatabase
84+
AppConfig.RedisDatabase = viper.GetInt("redis_database")
7085

7186
// Domain
7287
if AppConfig.Domain = viper.GetString("domain"); AppConfig.Domain == "" {

ratify-be/config/config.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

ratify-be/config/example.config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
hostname: localhost
2+
port: 9000
3+
environment: dev
4+
debug: true
5+
6+
db_hostname: localhost
7+
db_port: 5432
8+
db_database: ratify
9+
db_username: ratify-be
10+
db_password: ratify-be
11+
12+
redis_hostname: localhost
13+
redis_port: 6379
14+
redis_password: ratify-be
15+
redis_database: 0
16+
17+
domain: ratify.daystram.com
18+
secret: secret1234

ratify-be/constants/oauth.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package constants
2+
3+
import (
4+
"time"
5+
)
6+
7+
const (
8+
FlowAuthorizationCode = "flow:authorization_code"
9+
FlowAuthorizationCodeWithPKCE = "flow:authorization_code_pkce"
10+
FlowUnsupported = "flow:unsupported"
11+
12+
ResponseTypeCode = "code"
13+
ResponseTypeToken = "token"
14+
15+
PKCEChallengeMethodS256 = "S256"
16+
PKCEChallengeMethodPlain = "plain"
17+
18+
GrantTypeAuthorizationCode = "authorization_code"
19+
20+
AuthorizationCodeLength = 20
21+
AuthorizationCodeExpiry = time.Second * 300
22+
23+
AccessTokenLength = 64
24+
AccessTokenExpiry = time.Hour * 10
25+
RefreshTokenLength = 64
26+
RefreshTokenExpiry = time.Hour * 24 * 14
27+
)

ratify-be/constants/redis.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package constants
2+
3+
const (
4+
RDDelimiter = "::"
5+
defaultDelimiter = RDDelimiter + "%s"
6+
7+
RDKeyAuthorizationCode = GrantTypeAuthorizationCode + defaultDelimiter
8+
RDKeyCodeChallenge = "code_challenge" + defaultDelimiter
9+
RDKeyAccessToken = "access_token" + defaultDelimiter
10+
RDKeyRefreshToken = "refresh_token" + defaultDelimiter
11+
)

ratify-be/constants/router.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ package constants
22

33
const (
44
IsAuthenticatedKey = "is_authenticated"
5-
UserIDKey = "user_id"
5+
UserSubjectKey = "user_subject"
6+
IsSuperuserKey = "is_superuser"
67
)

0 commit comments

Comments
 (0)