Skip to content

Commit d1bc425

Browse files
committed
Merge branch 'develop'
2 parents 09fd20c + c3d5c02 commit d1bc425

File tree

11 files changed

+79
-44
lines changed

11 files changed

+79
-44
lines changed

deploy/docker/.env

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
IDENTITY_SERVER_PORT=8080
22
COMMUNITY_SERVER_PORT=8087
33
WORKSHOP_SERVER_PORT=8000
4-
ENABLE_LOG4J=false
4+
ENABLE_SHELL_INJECTION=false
5+
ENABLE_LOG4J=false
6+
LISTEN_IP="127.0.0.1"
7+
TLS_ENABLED=false
8+
VERSION=latest

deploy/docker/docker-compose.yml

+36-36
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212

13-
1413
services:
1514

1615
crapi-identity:
@@ -39,6 +38,7 @@ services:
3938
4039
- SMTP_AUTH=true
4140
- SMTP_STARTTLS=true
41+
- JWT_EXPIRATION=604800000
4242
- ENABLE_LOG4J=${ENABLE_LOG4J:-false}
4343
- API_GATEWAY_URL=https://api.mypremiumdealership.com
4444
- TLS_ENABLED=${TLS_ENABLED:-false}
@@ -53,10 +53,10 @@ services:
5353
mongodb:
5454
condition: service_healthy
5555
healthcheck:
56-
test: /app/health.sh
57-
interval: 15s
58-
timeout: 15s
59-
retries: 15
56+
test: /app/health.sh
57+
interval: 15s
58+
timeout: 15s
59+
retries: 15
6060
deploy:
6161
resources:
6262
limits:
@@ -92,10 +92,10 @@ services:
9292
crapi-identity:
9393
condition: service_healthy
9494
healthcheck:
95-
test: /app/health.sh
96-
interval: 15s
97-
timeout: 15s
98-
retries: 15
95+
test: /app/health.sh
96+
interval: 15s
97+
timeout: 15s
98+
retries: 15
9999
deploy:
100100
resources:
101101
limits:
@@ -135,10 +135,10 @@ services:
135135
crapi-community:
136136
condition: service_healthy
137137
healthcheck:
138-
test: /app/health.sh
139-
interval: 15s
140-
timeout: 15s
141-
retries: 15
138+
test: /app/health.sh
139+
interval: 15s
140+
timeout: 15s
141+
retries: 15
142142
deploy:
143143
resources:
144144
limits:
@@ -164,10 +164,10 @@ services:
164164
crapi-workshop:
165165
condition: service_healthy
166166
healthcheck:
167-
test: curl 0.0.0.0:80/web/health
168-
interval: 15s
169-
timeout: 15s
170-
retries: 15
167+
test: curl 0.0.0.0:80/web/health
168+
interval: 15s
169+
timeout: 15s
170+
retries: 15
171171
deploy:
172172
resources:
173173
limits:
@@ -184,10 +184,10 @@ services:
184184
#ports:
185185
# - "${LISTEN_IP:-127.0.0.1}:5432:5432"
186186
healthcheck:
187-
test: ["CMD-SHELL", "pg_isready"]
188-
interval: 15s
189-
timeout: 15s
190-
retries: 15
187+
test: [ "CMD-SHELL", "pg_isready" ]
188+
interval: 15s
189+
timeout: 15s
190+
retries: 15
191191
volumes:
192192
- postgresql-data:/var/lib/postgresql/data/
193193
deploy:
@@ -205,11 +205,11 @@ services:
205205
#ports:
206206
# - "${LISTEN_IP:-127.0.0.1}:27017:27017"
207207
healthcheck:
208-
test: echo 'db.runCommand("ping").ok' | mongo mongodb:27017/test --quiet
209-
interval: 15s
210-
timeout: 15s
211-
retries: 15
212-
start_period: 20s
208+
test: echo 'db.runCommand("ping").ok' | mongo mongodb:27017/test --quiet
209+
interval: 15s
210+
timeout: 15s
211+
retries: 15
212+
start_period: 20s
213213
volumes:
214214
- mongodb-data:/data/db
215215
deploy:
@@ -226,13 +226,13 @@ services:
226226
MH_MONGO_URI: admin:crapisecretpassword@mongodb:27017
227227
MH_STORAGE: mongodb
228228
ports:
229-
# - "127.0.0.1:1025:1025" # smtp server
229+
# - "127.0.0.1:1025:1025" # smtp server
230230
- "${LISTEN_IP:-127.0.0.1}:8025:8025" # Mail ui
231231
healthcheck:
232-
test: ["CMD", "nc", "-z", "localhost", "8025"]
233-
interval: 15s
234-
timeout: 15s
235-
retries: 15
232+
test: [ "CMD", "nc", "-z", "localhost", "8025" ]
233+
interval: 15s
234+
timeout: 15s
235+
retries: 15
236236
deploy:
237237
resources:
238238
limits:
@@ -245,11 +245,11 @@ services:
245245
#ports:
246246
# - "${LISTEN_IP:-127.0.0.1}:8443:443" # https
247247
healthcheck:
248-
test: curl -vk 0.0.0.0:443
249-
interval: 15s
250-
timeout: 15s
251-
retries: 15
252-
start_period: 15s
248+
test: echo -n "GET / HTTP/1.1\n\n" > /dev/tcp/api.mypremiumdealership.com/443
249+
interval: 15s
250+
timeout: 15s
251+
retries: 15
252+
start_period: 15s
253253
deploy:
254254
resources:
255255
limits:

deploy/docker/scripts/load.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
docker load -i mailhog.tar
2+
docker load -i gateway-service.tar
3+
docker load -i crapi-identity.tar
4+
docker load -i crapi-community.tar
5+
docker load -i crapi-workshop.tar
6+
docker load -i crapi-web.tar
7+
docker load -i postgres.tar
8+
docker load -i mongo.tar

deploy/docker/scripts/save.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
docker save crapi/mailhog:develop -o mailhog.tar
2+
docker save crapi/gateway-service:develop -o gateway-service.tar
3+
docker save crapi/crapi-identity:develop -o crapi-identity.tar
4+
docker save crapi/crapi-community:develop -o crapi-community.tar
5+
docker save crapi/crapi-workshop:develop -o crapi-workshop.tar
6+
docker save crapi/crapi-web:develop -o crapi-web.tar
7+
docker save postgres:14 -o postgres.tar
8+
docker save mongo:4.4 -o mongo.tar

deploy/helm/templates/identity/config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ data:
2727
SMTP_PASS: {{ .Values.identity.config.smtpPass }}
2828
SMTP_FROM: {{ .Values.identity.config.smtpFrom }}
2929
SMTP_AUTH: {{ .Values.identity.config.smtpAuth | quote }}
30+
JWT_EXPIRATION: {{ .Values.identity.config.jwtExpiration | quote }}
3031
SMTP_STARTTLS: {{ .Values.identity.config.smtpStartTLS | quote }}
3132
SERVER_PORT: {{ .Values.identity.port | quote }}
3233
API_GATEWAY_URL: {{ if .Values.apiGatewayServiceInstall }}"https://{{ .Values.apiGatewayService.service.name }}"{{ else }}{{ .Values.apiGatewayServiceUrl }}{{ end }}

deploy/helm/values.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ enableShellInjection: true
88
imagePullPolicy: Always
99
apiGatewayServiceUrl: https://api.mypremiumdealership.com
1010
apiGatewayServiceInstall: true
11-
apiGatewayPassword:
11+
apiGatewayPassword:
1212
tlsEnabled: false
1313

1414
waitForK8sResources:
@@ -73,6 +73,7 @@ identity:
7373
smtpFrom: "[email protected]"
7474
smtpAuth: true
7575
smtpStartTLS: true
76+
jwtExpiration: 604800000
7677
keyStoreType: PKCS12
7778
keyStore: classpath:certs/server.p12
7879
keyStorePassword: passw0rd

deploy/k8s/base/identity/config.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
data:
88
DB_HOST: postgresdb
99
DB_DRIVER: postgresql
10-
JWT_SECRET: crapi #Used for creating a JWT. Can be anything
10+
JWT_SECRET: crapi #Used for creating a JWT. Can be anything
1111
DB_USER: admin
1212
DB_PASSWORD: crapisecretpassword
1313
DB_NAME: crapi
@@ -24,5 +24,6 @@ data:
2424
SMTP_PASS: "xxxxxxxxxxxxxx"
2525
SMTP_FROM: "[email protected]"
2626
SMTP_AUTH: "true"
27+
JWT_EXPIRATION: "604800000"
2728
SMTP_STARTTLS: "true"
2829
SERVER_PORT: "8080"

services/community/api/router/routes.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"net/http"
2020
"os"
21+
"time"
2122

2223
"crapi.proj/goservice/api/config"
2324
"crapi.proj/goservice/api/controllers"
@@ -59,6 +60,12 @@ func (server *Server) InitializeRoutes() *mux.Router {
5960

6061
func (server *Server) Run(addr string) {
6162
fmt.Println("Listening to port " + os.Getenv("SERVER_PORT"))
63+
srv := &http.Server{
64+
Addr: addr,
65+
Handler: server.Router,
66+
ReadTimeout: 30 * time.Second,
67+
WriteTimeout: 30 * time.Second,
68+
}
6269
if utils.IsTLSEnabled() {
6370
// Check if env variable TLS_CERTIFICATE is set then use it as certificate else default to certs/server.crt
6471
certificate, is_cert := os.LookupEnv("TLS_CERTIFICATE")
@@ -70,12 +77,12 @@ func (server *Server) Run(addr string) {
7077
if !is_key || key == "" {
7178
key = "certs/server.key"
7279
}
73-
err := http.ListenAndServeTLS(addr, certificate, key, server.Router)
80+
err := srv.ListenAndServeTLS(certificate, key)
7481
if err != nil {
7582
fmt.Println(err)
7683
}
7784
} else {
78-
err := http.ListenAndServe(addr, server.Router)
85+
err := srv.ListenAndServe()
7986
if err != nil {
8087
fmt.Println(err)
8188
}

services/identity/.env

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export [email protected]
1919
export ENABLE_SHELL_INJECTION=false
2020
export JWT_SECRET=crapi
2121
export SMTP_HOST=smtp.example.com
22+
export JWT_EXPIRATION=604800000
2223
export API_GATEWAY_URL=https://api.mypremiumdealership.com
2324
export TLS_ENABLED=false
2425
export TLS_KEYSTORE_TYPE=PKCS12

services/identity/src/main/java/com/crapi/config/JwtProvider.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.ByteArrayInputStream;
2929
import java.io.IOException;
3030
import java.io.InputStream;
31+
import java.math.BigDecimal;
3132
import java.net.URI;
3233
import java.net.URLConnection;
3334
import java.nio.charset.StandardCharsets;
@@ -45,7 +46,7 @@ public class JwtProvider {
4546
private static final Logger logger = LoggerFactory.getLogger(JwtProvider.class);
4647

4748
@Value("${app.jwtExpiration}")
48-
private int jwtExpiration;
49+
private String jwtExpiration;
4950

5051
private KeyPair keyPair;
5152

@@ -82,11 +83,14 @@ public String getPublicJwkSet() {
8283
* @return generated token with expire date
8384
*/
8485
public String generateJwtToken(User user) {
86+
int jwtExpirationInt;
87+
if (jwtExpiration.contains("e+")) jwtExpirationInt = new BigDecimal(jwtExpiration).intValue();
88+
else jwtExpirationInt = Integer.parseInt(jwtExpiration);
8589
return Jwts.builder()
8690
.setSubject((user.getEmail()))
8791
.claim("role", user.getRole().getName())
8892
.setIssuedAt(new Date())
89-
.setExpiration(new Date((new Date()).getTime() + jwtExpiration))
93+
.setExpiration(new Date((new Date()).getTime() + jwtExpirationInt))
9094
.signWith(SignatureAlgorithm.RS256, this.keyPair.getPrivate())
9195
.compact();
9296
}

services/identity/src/main/resources/application.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ spring.jpa.hibernate.ddl-auto=update
1515

1616

1717
app.jwksJson=${JWKS}
18-
app.jwtExpiration=604800000
18+
app.jwtExpiration=${JWT_EXPIRATION}
1919

2020
#Mail Configuration
2121
mail.from=${SMTP_FROM}

0 commit comments

Comments
 (0)