Skip to content

Commit

Permalink
Merge pull request #183 from skni-kod/issue-182
Browse files Browse the repository at this point in the history
Eureka, auto service registry, commons library
  • Loading branch information
KartVen authored Nov 11, 2024
2 parents 278a969 + a40b6c4 commit 38e7a21
Show file tree
Hide file tree
Showing 160 changed files with 745 additions and 456 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ RABBITMQ_PASSWORD=rabbitmq
ELASTICSEARCH_HOSTS=["http://localhost:9200"]
ELASTICSEARCH_USERNAME=opensearch
ELASTICSEARCH_PASSWORD=opensearch

# Eureka
EUREKA_URL=http://localhost:8761/eureka
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ Before you can run the project, you will need the following applications:
docker-compose up -d
```

4. Go to local database ([localhost:5432](http://localhost:5432)) with the following credentials and execute the SQL command:
4. Go to local database ([localhost:5432](http://localhost:5432)) with the following credentials and execute the SQL
command:

- **Username:** postgres
- **Password:** postgres
- **Username:** postgres
- **Password:** postgres

```sql
CREATE SCHEMA IF NOT EXISTS "kodemy-auth";
Expand All @@ -39,11 +40,11 @@ Before you can run the project, you will need the following applications:

5. Run individual services in IntelliJ with the following settings for `Active profiles`:

- `KodemyAuthApplication`: `local`
- `KodemyBackendApplication`: `local`
- `KodemyGatewayApplication`: `local`
- ~~`KodemyNotificationApplication`: `local`~~
- `KodemySearchApplication`: `local`
- `KodemyAuthApplication`: `local`
- `KodemyBackendApplication`: `local`
- `KodemyGatewayApplication`: `local`
- ~~`KodemyNotificationApplication`: `local`~~
- `KodemySearchApplication`: `local`

6. Once the project is running, you can access the API documentation (OpenAPI v3) for almost all microservices:

Expand All @@ -54,7 +55,8 @@ Before you can run the project, you will need the following applications:

### RabbitMQ

To access the RabbitMQ management UI, go to [http://localhost:15672](http://localhost:15672) with the following credentials:
To access the RabbitMQ management UI, go to [http://localhost:15672](http://localhost:15672) with the following
credentials:

- **Username:** rabbitmq
- **Password:** rabbitmq
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions kodemy-commons/build.gradle → commons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ dependencies {

tasks.named('test') {
useJUnitPlatform()
}

bootJar {
enabled = false
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions commons/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'commons'
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static RuntimeException throwIfFailure(Throwable throwable) {
return getRuntimeOrDefault(throwable, new InternalError500Exception());
}

public static RuntimeException throwIfFailure(Throwable throwable, String pattern, Object ...args) {
public static RuntimeException throwIfFailure(Throwable throwable, String pattern, Object... args) {
return getRuntimeOrDefault(throwable, new InternalError500Exception(pattern, args));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@

import java.security.Principal;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class AuthFacade {
private static SecurityContext getContext(){
private static SecurityContext getContext() {
return SecurityContextHolder.getContext();
}

Expand Down Expand Up @@ -60,7 +59,7 @@ public static Authentication setAuthentication(Authentication authentication) {
return setAuthentication(authentication, false);
}

public static boolean hasAnyAuthority(String... authorities){
public static boolean hasAnyAuthority(String... authorities) {
List<String> authorityList = Arrays.asList(authorities);
return getAuthentication()
.map(Authentication::getAuthorities)
Expand All @@ -70,7 +69,7 @@ public static boolean hasAnyAuthority(String... authorities){
.isPresent();
}

public static boolean hasAuthority(String authority){
public static boolean hasAuthority(String authority) {
return hasAnyAuthority(authority);
}
}
2 changes: 1 addition & 1 deletion config/opensearch-security/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ config:
#internalProxies: '.*' # trust all internal proxies, regex pattern
#remoteIpHeader: 'x-forwarded-for'
authc:
basic_internal_auth_domain: # <- Settings for Basic authentication
basic_internal_auth_domain: # <- Settings for Basic authentication
description: "Authenticate via HTTP Basic against internal users database"
http_enabled: true
transport_enabled: true
Expand Down
2 changes: 1 addition & 1 deletion config/opensearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cluster.name: kodemy-os-cluster
node.name: kodemy-os-n1

# Comma-separated list of hostnames or IP addresses of nodes in the cluster
discovery.seed_hosts: ["kodemy-os-n1"]
discovery.seed_hosts: [ "kodemy-os-n1" ]

# Discovery type for single-node configuration
discovery.type: single-node
Expand Down
1 change: 1 addition & 0 deletions kodemy-api-gateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@EnableDiscoveryClient
public class KodemyGatewayApplication {

public static void main(String[] args) {
Expand Down
7 changes: 6 additions & 1 deletion kodemy-api-gateway/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ app:
security:
cors:
allowed-origins:
- ${network.route.front}
- ${network.route.front}

eureka:
client:
service-url:
defaultZone: ${EUREKA_URL}
50 changes: 13 additions & 37 deletions kodemy-api-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,26 @@ spring:
cloud:
gateway:
routes:
- id: auth
uri: lb://kodemy-auth
predicates:
- Path=/api/auth/**,/api/users/**,/api/roles/**
- id: notification
uri: lb://kodemy-notification
predicates:
- Path=/api/notification/**
- id: oauth2_auth
uri: ${network.route.auth}
predicates:
- Path=/api/oauth2/**,/api/auth/**,/api/logout

- id: search-materials
uri: ${network.route.search}
- id: search
uri: lb://kodemy-search
predicates:
- Path=/api/materials
- Method=GET

- id: materials-get
uri: ${network.route.backend}
predicates:
- Path=/api/materials/{materialId}/**
- Method=GET

- id: materials-post
uri: ${network.route.backend}
predicates:
- Path=/api/materials
- Method=POST

- id: materials-grades
uri: ${network.route.backend}
predicates:
- Path=/api/materials/{materialId}/grades
- Method=POST

- id: users-materials
uri: ${network.route.auth}
predicates:
- Path=/api/users/{userId}/materials

- id: users_roles
uri: ${network.route.auth}
predicates:
- Path=/api/users/**,/api/roles

- id: tags_types_sections_categories_admin
uri: ${network.route.backend}
- id: backend
uri: lb://kodemy-backend
predicates:
- Path=/api/tags,/api/types,/api/sections,/api/categories/{categoryId},/api/admin/**
- Path=/api/**

management:
endpoints:
Expand All @@ -66,7 +43,6 @@ management:

network:
route:
front: ${FRONTEND_PUBLIC_HOST}
auth: http://kodemy-auth:8080
backend: http://kodemy-backend:8080
search: http://kodemy-search:8080
Expand Down

This file was deleted.

13 changes: 12 additions & 1 deletion kodemy-auth/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ plugins {
id 'io.spring.dependency-management' version '1.1.5'
}

ext {
springCloudVersion = "2023.0.3"
}

group = 'pl.sknikod'

java {
Expand Down Expand Up @@ -51,7 +55,8 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-jackson:0.12.6'
implementation 'io.micrometer:micrometer-registry-prometheus'

implementation 'pl.sknikod:kodemy-commons:1.1'
implementation("pl.sknikod:commons")
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'

annotationProcessor 'org.projectlombok:lombok'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final'
Expand All @@ -73,6 +78,12 @@ dependencies {
testAnnotationProcessor 'org.projectlombok:lombok'
}

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"
}
}

tasks.named('test') {
useJUnitPlatform()
}
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

1 change: 1 addition & 0 deletions kodemy-auth/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
rootProject.name = 'kodemy-auth'
includeBuild("../commons")
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.v3.oas.annotations.security.SecuritySchemes;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@OpenAPIDefinition(
Expand All @@ -28,6 +29,7 @@
bearerFormat = "JWT"
)
})
@EnableDiscoveryClient
public class KodemyAuthApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Configuration
public class LogbookConfiguration {
@Bean
public Logbook logbook(){
public Logbook logbook() {
return Logbook.create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
@Slf4j
Expand All @@ -29,4 +23,10 @@ public static class LanNetworkProperties {
private int connectTimeoutMs;
private int readTimeoutMs;
}

@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import pl.sknikod.kodemyauth.infrastructure.database.RefreshToken;
import pl.sknikod.kodemyauth.infrastructure.database.User;
import pl.sknikod.kodemyauth.infrastructure.database.RefreshTokenRepository;
import pl.sknikod.kodemyauth.infrastructure.database.User;
import pl.sknikod.kodemyauth.infrastructure.database.UserRepository;
import pl.sknikod.kodemycommons.exception.InternalError500Exception;
import pl.sknikod.kodemycommons.exception.NotFound404Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;
import pl.sknikod.kodemyauth.configuration.SecurityConfiguration;
import pl.sknikod.kodemyauth.infrastructure.database.Provider;
import pl.sknikod.kodemyauth.infrastructure.database.Role;
import pl.sknikod.kodemyauth.infrastructure.database.User;
import pl.sknikod.kodemyauth.infrastructure.database.RoleRepository;
import pl.sknikod.kodemyauth.infrastructure.database.UserRepository;
import pl.sknikod.kodemyauth.infrastructure.database.*;
import pl.sknikod.kodemyauth.infrastructure.module.oauth2.provider.OAuth2Provider;
import pl.sknikod.kodemycommons.exception.InternalError500Exception;
import pl.sknikod.kodemycommons.exception.NotFound404Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface PermissionRepository extends JpaRepository<Permission, Long> {
}
}
Loading

0 comments on commit 38e7a21

Please sign in to comment.