Skip to content

Commit

Permalink
Refactor/profiles and small improvements (#27)
Browse files Browse the repository at this point in the history
* refactor(#20): logback refactor profiles

* feat: renovate add labels

* typo: README.md fix typos

* refactor(#20): logback refactor profiles update README.md

* typo: README.md fix typos

* ♻️ #18: refactor hazelcast profiles

* ♻️ #18: refactor hazelcast profiles

* 🎨 reformat WebSessionConfiguration

* ♻️ (#22) reformat spring banner

* 🎨 #20 fix log pattern format
  • Loading branch information
simonhir authored Jul 29, 2024
1 parent 19b7d76 commit cab778f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 56 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Refarch
# RefArch

[![Made with love by it@M][made-with-love-shield]][itm-opensource]
<!-- feel free to add more shields, style 'for-the-badge' -> see https://shields.io/badges -->

Collection of different reference architecture (Refarch) components developed by it@M.
Collection of different reference architecture (RefArch) components developed by it@M.

## Usage

Expand Down
11 changes: 7 additions & 4 deletions refarch-gateway/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Refarch Gateway
# RefArch Gateway

## Usage

Expand All @@ -20,9 +20,12 @@ Beside the default behaviour there are some special route prefixes which are han

## Profiles

| Profile | Description |
|---------------|---------------------------------------------------------------------------------------------------|
| `no-security` | Disables complete security like authentication, authorization, csrf etc. Routing works as normal. |
| Profile | Description |
|-------------------|---------------------------------------------------------------------------------------------------|
| `json-logging` | Switches logging from textual to JSON output. |
| `no-security` | Disables complete security like authentication, authorization, csrf etc. Routing works as normal. |
| `hazelcast-local` | Configures Spring Session Hazelcast for connection via localhost (i.e. local development). |
| `hazelcast-k8s` | Configures Spring Session Hazelcast for usage in Kubernetes/OpenShift cluster. |

## Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.hazelcast.config.Config;
import com.hazelcast.config.EvictionPolicy;
import com.hazelcast.config.MapConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -25,6 +25,7 @@
*/
@Configuration
@EnableSpringWebSession
@Profile({ "hazelcast-local", "hazelcast-k8s" })
public class WebSessionConfiguration {

@Value("${hazelcast.instance:hazl_instance}")
Expand All @@ -45,13 +46,18 @@ public ServerOAuth2AuthorizedClientRepository authorizedClientRepository() {
}

@Bean
public ReactiveSessionRepository<MapSession> reactiveSessionRepository(@Qualifier("hazelcastInstance") @Autowired HazelcastInstance hazelcastInstance) {
public ReactiveSessionRepository<MapSession> reactiveSessionRepository(@Autowired HazelcastInstance hazelcastInstance) {
final IMap<String, Session> map = hazelcastInstance.getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME);
return new ReactiveMapSessionRepository(map);
}

@Bean
@Profile({ "local", "test" })
public HazelcastInstance hazelcastInstance(@Autowired final Config config) {
return Hazelcast.getOrCreateHazelcastInstance(config);
}

@Bean
@Profile({ "hazelcast-local" })
public Config localConfig(@Value(
"${spring.session.timeout}"
) int timeout) {
Expand All @@ -73,7 +79,7 @@ public Config localConfig(@Value(
}

@Bean
@Profile({ "dev", "kon", "prod" })
@Profile({ "hazelcast-k8s" })
public Config config(@Value("${spring.session.timeout}") int timeout) {
final var hazelcastConfig = new Config();
hazelcastConfig.setInstanceName(hazelcastInstanceName);
Expand Down
8 changes: 2 additions & 6 deletions refarch-gateway/src/main/resources/banner.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
---------------------------------------------------------------------------------------------------------------------------------------------------
____ __ _ ____ _
| _ \ ___ / _| __ _ _ __ ___| |__ / ___| __ _| |_ _____ ____ _ _ _
| |_) / _ \ |_ / _` | '__/ __| '_ \| | _ / _` | __/ _ \ \ /\ / / _` | | | |
| _ < __/ _| (_| | | | (__| | | | |_| | (_| | || __/\ V V / (_| | |_| |
|_| \_\___|_| \__,_|_| \___|_| |_|\____|\__,_|\__\___| \_/\_/ \__,_|\__, |
|___/
RefArch-Gateway
https://github.com/it-at-m/refarch

Application Name : ${spring.application.name} (v${info.application.version})
Spring Boot Version : ${spring-boot.formatted-version}
Expand Down
49 changes: 10 additions & 39 deletions refarch-gateway/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,53 @@
<springProperty scope="context" name="springAppName" source="spring.application.name"/>


<springProfile name="local,test">
<springProfile name="!json-logger">

<!-- Log appender -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- @formatter:off -->
<pattern>
%date{yyyy.MM.dd HH:mm:ss.SSS} | ${springAppName} | TraceId: %X{traceId:-} | SpanId: %X{spanId:-}] | %level | [%thread] | %logger{0} | [%file : %line] - %msg%n
</pattern>
<!-- @formatter:on -->
</encoder>
</appender>

<!-- Logger -->
<logger name="de.muenchen.oss.refarch.gateway"
level="debug"
additivity="false">
<appender-ref ref="STDOUT" />
</logger>

<logger name="de.muenchen.allgemein"
level="debug"
additivity="false">
<appender-ref ref="STDOUT" />
<appender-ref ref="STDOUT"/>
</logger>

<logger name="org.springframework.web"
level="debug"
additivity="false">
<appender-ref ref="STDOUT" />
<appender-ref ref="STDOUT"/>
</logger>

<logger name="org.springframework.cloud.gateway"
level="debug"
additivity="false">
<appender-ref ref="STDOUT" />
<appender-ref ref="STDOUT"/>
</logger>

<logger name="org.springframework.security"
level="debug"
additivity="false">
<appender-ref ref="STDOUT" />
<appender-ref ref="STDOUT"/>
</logger>

<!-- Logger usage -->
<root level="info">
<appender-ref ref="STDOUT" />
<appender-ref ref="STDOUT"/>
</root>

</springProfile>


<springProfile name="dev,kon,prod">
<springProfile name="json-logger">

<!-- Log appender -->
<appender name="JSON_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
Expand Down Expand Up @@ -88,34 +84,9 @@
</encoder>
</appender>

<!-- Logger -->
<logger name="de.muenchen.oss.refarch.gateway"
level="info"
additivity="false">
<appender-ref ref="JSON_STDOUT" />
</logger>

<logger name="de.muenchen.allgemein"
level="info"
additivity="false">
<appender-ref ref="JSON_STDOUT" />
</logger>

<logger name="org.springframework.web"
level="info"
additivity="false">
<appender-ref ref="JSON_STDOUT" />
</logger>

<logger name="org.springframework.cloud.gateway"
level="info"
additivity="false">
<appender-ref ref="JSON_STDOUT" />
</logger>

<!-- Logger usage -->
<root level="info">
<appender-ref ref="JSON_STDOUT" />
<appender-ref ref="JSON_STDOUT"/>
</root>

</springProfile>
Expand Down
7 changes: 6 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:recommended"]
"extends": [
"config:recommended"
],
"labels": [
"dependencies"
]
}

0 comments on commit cab778f

Please sign in to comment.