Skip to content

Commit de34100

Browse files
author
Hadi T
committed
parsed env variables for pwd & users, created a hasher pkg
1 parent abf9546 commit de34100

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

deploy/docker/docker-compose.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ services:
77
dockerfile: deploy/docker/golang/Dockerfile
88
container_name: oauth_app
99
environment:
10-
DATABASE_USR: oauth_usr
11-
DATABASE_PWD: DummyPassword1
10+
POSTGRES_USER: oauth_usr
11+
POSTGRES_PASSWORD: DummyPassword1
12+
POSTGRES_DB: oauth
13+
REDIS_PASSWORD: SyniolIsTheFuture
1214
ports:
1315
- "8080:8080"
1416
networks:
@@ -25,7 +27,7 @@ services:
2527
POSTGRES_USER: oauth_usr
2628
POSTGRES_DB: oauth
2729
volumes:
28-
- database_volume:/var/lib/postgresql/data
30+
- database_data:/var/lib/postgresql/data
2931
networks:
3032
- oauth_authentication
3133

@@ -35,14 +37,16 @@ services:
3537
context: ../..
3638
dockerfile: deploy/docker/redis/Dockerfile
3739
container_name: oauth_cache
40+
environment:
41+
REDIS_PASSWORD: SyniolIsTheFuture
3842
volumes:
39-
- cache_volume:/data
43+
- cache_data:/data
4044
networks:
4145
- oauth_authentication
4246

4347
volumes:
44-
database_volume:
45-
cache_volume:
48+
database_data:
49+
cache_data:
4650

4751
networks:
4852
oauth_authentication:

deploy/docker/redis/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ RUN apk add --update-cache openssl \
1313
&& rm gen-test-certs.sh
1414

1515
ENV ALLOW_EMPTY_PASSWORD=false
16-
ENV REDIS_PASSWORD=SyniolIsTheFuture
1716
ENV REDIS_DISABLE_COMMANDS=FLUSHDB,FLUSHALL
1817
ENV REDIS_TLS_CERT_FILE=/usr/local/etc/redis/tls/redis.crt
1918
ENV REDIS_TLS_KEY_FILE=/usr/local/etc/redis/tls/redis.key

pkg/cache/redis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func newRedisClient(ctx context.Context) Cache {
4141

4242
return "cache:6379"
4343
}(),
44-
Password: "SyniolIsTheFuture",
44+
Password: os.Getenv("REDIS_PASSWORD"),
4545
DB: 0, // use default DB
4646
})
4747

pkg/database/database.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ func NewDatabase(ctx context.Context) (*Database, error) {
2222

2323
// https://www.postgresql.org/docs/current/libpq-ssl.html
2424
connStr := fmt.Sprintf(
25-
"postgresql://%s:%s@%s/oauth?sslmode=require",
26-
//os.Getenv("DATABASE_USR"),
27-
"oauth_usr",
28-
//os.Getenv("DATABASE_PWD"),
29-
"DummyPassword1",
25+
"postgresql://%s:%s@%s/%s?sslmode=require",
26+
os.Getenv("POSTGRES_USER"),
27+
os.Getenv("POSTGRES_PASSWORD"),
28+
os.Getenv("POSTGRES_DB"),
3029
func() string {
3130
if len(os.Getenv("DEBUG")) > 0 {
3231
return "127.0.0.1"

pkg/hash/hash.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package hash
2+
3+
import (
4+
"encoding/base64"
5+
"encoding/hex"
6+
)
7+
8+
func Encode(msg []byte) []byte {
9+
hexHash := make([]byte, hex.EncodedLen(len(msg)))
10+
hex.Encode(hexHash, msg)
11+
12+
hash := make([]byte, base64.StdEncoding.EncodedLen(len(hexHash)))
13+
base64.StdEncoding.Encode(hash, hexHash)
14+
15+
return hash
16+
}
17+
18+
func Decode(msg []byte) []byte {
19+
base64Hash := make([]byte, base64.StdEncoding.DecodedLen(len(msg)))
20+
base64.StdEncoding.Decode(base64Hash, msg)
21+
22+
hash := make([]byte, hex.DecodedLen(len(base64Hash)))
23+
hex.Decode(hash, base64Hash)
24+
25+
return hash
26+
}

0 commit comments

Comments
 (0)