From 30474671f8c4278f6a604acf2cc2433379c0436a Mon Sep 17 00:00:00 2001 From: Le Ma Date: Fri, 19 Dec 2025 13:12:26 +1300 Subject: [PATCH] Remove sensitive information and initialize. --- .gitignore | 33 +++ README.md | 2 + pom.xml | 134 +++++++++++++ src/main/docker/dockerfile | 6 + .../flagnote/config/ConfigApplication.java | 16 ++ src/main/resources/bootstrap.yml | 36 ++++ .../configs/flagnote-gateway-dev.yml | 189 ++++++++++++++++++ .../configs/flagnote-service-dev.yml | 49 +++++ src/main/resources/logback-spring.xml | 35 ++++ .../FlagnoteConfigApplicationTests.java | 13 ++ 10 files changed, 513 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 pom.xml create mode 100644 src/main/docker/dockerfile create mode 100644 src/main/java/com/flagnote/config/ConfigApplication.java create mode 100644 src/main/resources/bootstrap.yml create mode 100644 src/main/resources/configs/flagnote-gateway-dev.yml create mode 100644 src/main/resources/configs/flagnote-service-dev.yml create mode 100644 src/main/resources/logback-spring.xml create mode 100644 src/test/java/com/flagnote/flagnoteconfig/FlagnoteConfigApplicationTests.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..9b22fc0 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# flagnote-config +flagnote-config diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7a4ae72 --- /dev/null +++ b/pom.xml @@ -0,0 +1,134 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.3 + + + com.flagnote + flagnote-config + 0.0.1 + flagnote-config + Demo project for Spring Boot + + 17 + 17 + 17 + 17 + 2023.0.0 + registry.openif.com:5000 + flagnote + + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + + org.springframework.cloud + spring-cloud-config-server + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + UTF-8 + true + true + + + + + org.apache.maven.plugins + maven-jar-plugin + + + **/configs/*.yml + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + com.spotify + docker-maven-plugin + 1.2.2 + + docker-openif + http://${docker.repository} + true + http://144.34.221.20:42375 + + ${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version} + + src/main/docker + + + / + ${project.build.directory} + ${project.build.finalName}.jar + + + + + + + diff --git a/src/main/docker/dockerfile b/src/main/docker/dockerfile new file mode 100644 index 0000000..350fbae --- /dev/null +++ b/src/main/docker/dockerfile @@ -0,0 +1,6 @@ +FROM registry.openif.com:5000/flagnote/flagnote-docker-image:0.0.1 +VOLUME /tmp +ADD flagnote-config-0.0.1.jar app.jar +RUN sh -c 'touch /app.jar' +ENV JAVA_OPTS="" +ENTRYPOINT [ "sh", "-c", "exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] \ No newline at end of file diff --git a/src/main/java/com/flagnote/config/ConfigApplication.java b/src/main/java/com/flagnote/config/ConfigApplication.java new file mode 100644 index 0000000..2cc4aee --- /dev/null +++ b/src/main/java/com/flagnote/config/ConfigApplication.java @@ -0,0 +1,16 @@ +package com.flagnote.config; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.config.server.EnableConfigServer; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@SpringBootApplication +@EnableConfigServer +public class ConfigApplication { + + public static void main(String[] args) { + SpringApplication.run(ConfigApplication.class, args); + } +} diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..782013c --- /dev/null +++ b/src/main/resources/bootstrap.yml @@ -0,0 +1,36 @@ +server: + port: 20000 + +spring: + application: + name: flagnote-config + + profiles: + active: native + cloud: + config: + server: + native: + searchLocations: classpath:/configs,file:/usr/local/flagnote/etc + +management: +# server: +# address: 127.0.0.1 +# port: 19000 + endpoint: + shutdown: + enabled: true + health: + enabled: true + show-details: always + endpoints: + web: + base-path: /xxxxxx/actuator + exposure: + include: shutdown,health + + +logging: + config: classpath:logback-spring.xml +logback: + logPath: /tmp/logs/ diff --git a/src/main/resources/configs/flagnote-gateway-dev.yml b/src/main/resources/configs/flagnote-gateway-dev.yml new file mode 100644 index 0000000..5217d96 --- /dev/null +++ b/src/main/resources/configs/flagnote-gateway-dev.yml @@ -0,0 +1,189 @@ +server: +# address: 127.0.0.1 + port: 21000 +spring: + data: + redis: + database: 10 + host: localhost + port: 6379 + timeout: 10000 + poolMaxTotal: 10 + poolMaxIdle: 10 + poolMaxWait: 3 + password: redispassword + codec: + max-in-memory-size: 10MB + servlet: + multipart: + # 最大支持文件大小 + max-file-size: 10MB + # 最大支持请求大小 + max-request-size: 10MB + + cloud: + gateway: + routes: + - id: redirect + uri: lb://flagnote-service + order: -1 + predicates: + - Path=/html/redirect + - Method=GET + filters: + - name: RequestRateLimiter + args: + # 如果返回的key是空的话,false则不进行限流 + # deny-empty-key: true + # status-code: TOO_MANY_REQUESTS + # 每秒产生多少个令牌 + redis-rate-limiter.replenishRate: 1 + # 1秒内最大的令牌,即在1s内可以允许的突发流程,设置为0,表示阻止所有的请求 + redis-rate-limiter.burstCapacity: 10 + # 每次请求申请几个令牌 + redis-rate-limiter.requestedTokens: 1 + # IP 地址限流 + key-resolver: "#{@remoteAddrKeyResolver}" + + + - name: RequestRateLimiter + args: + # 如果返回的key是空的话,false则不进行限流 + # deny-empty-key: true + # status-code: TOO_MANY_REQUESTS + # 每秒产生多少个令牌 + redis-rate-limiter.replenishRate: 1 + # 1秒内最大的令牌,即在1s内可以允许的突发流程,设置为0,表示阻止所有的请求 + redis-rate-limiter.burstCapacity: 10 + # 每次请求申请几个令牌 + redis-rate-limiter.requestedTokens: 2 + # IP 地址限流 + key-resolver: "#{@remoteSessionKeyResolver}" + + - id: keyMeta + uri: lb://flagnote-service + order: -1 + predicates: + - Path=/note/keyMeta + - Method=GET + filters: + - name: RequestRateLimiter + args: + # 如果返回的key是空的话,false则不进行限流 +# deny-empty-key: true +# status-code: TOO_MANY_REQUESTS + # 每秒产生多少个令牌 + redis-rate-limiter.replenishRate: 1 + # 1秒内最大的令牌,即在1s内可以允许的突发流程,设置为0,表示阻止所有的请求 + redis-rate-limiter.burstCapacity: 10 + # 每次请求申请几个令牌 + redis-rate-limiter.requestedTokens: 1 + # IP 地址限流 + key-resolver: "#{@remoteAddrKeyResolver}" + + + - name: RequestRateLimiter + args: + # 如果返回的key是空的话,false则不进行限流 +# deny-empty-key: true +# status-code: TOO_MANY_REQUESTS + # 每秒产生多少个令牌 + redis-rate-limiter.replenishRate: 1 + # 1秒内最大的令牌,即在1s内可以允许的突发流程,设置为0,表示阻止所有的请求 + redis-rate-limiter.burstCapacity: 10 + # 每次请求申请几个令牌 + redis-rate-limiter.requestedTokens: 2 + # IP 地址限流 + key-resolver: "#{@remoteSessionKeyResolver}" + + + + - id: noteMeta + uri: lb://flagnote-service + order: -1 + predicates: + - Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}/noteMeta + - Method=GET + filters: + - ValidateNoteKey + - id: getNote + uri: lb://flagnote-service + order: -1 + predicates: + - Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}} + - Method=GET + filters: + - ValidateNoteKey + - id: saveNote + uri: lb://flagnote-service + order: -1 + predicates: + - Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}} + - Method=POST + filters: + - ValidateNoteKey + - id: deleteNote + uri: lb://flagnote-service + order: -1 + predicates: + - Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}/delete + - Method=POST + filters: + - ValidateNoteKey + - id: secretKey + uri: lb://flagnote-service + order: -1 + predicates: + - Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}/secretKey + - Method=POST + filters: + - ValidateNoteKey + - id: getNoteTxt + uri: lb://flagnote-service + order: -1 + predicates: + - Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}.txt + - Method=GET + filters: + - ValidateNoteKey + + zookeeper: + connect-string: localhost:2181 + discovery: + enabled: true + + loadbalancer: + configurations: health-check + health-check: + path: + noteCommonService: /xxxxxx/actuator/health + keyMetaService: /xxxxxx/actuator/health + initial-delay: 0 + interval: 5s + inetutils: + # 指定此客户端的ip + default-ip-address: localhost + + + +management: +# server: +# address: 127.0.0.1 +# port: 19000 + endpoint: + shutdown: + enabled: true + health: + enabled: true + show-details: always + endpoints: + web: + base-path: /xxxxxx/actuator + exposure: + include: shutdown,health + +logging: + level: + org.springframework.cloud.gateway: trace + org.springframework.cloud.loadbalancer: trace + org.springframework.web.reactive: trace \ No newline at end of file diff --git a/src/main/resources/configs/flagnote-service-dev.yml b/src/main/resources/configs/flagnote-service-dev.yml new file mode 100644 index 0000000..58eee89 --- /dev/null +++ b/src/main/resources/configs/flagnote-service-dev.yml @@ -0,0 +1,49 @@ +server: + port: 22000 + +spring: + codec: + max-in-memory-size: 10MB + data: + mongodb: + authentication-database: admin + database: flagnote + host: localhost + port: 27017 + username: mongoadmin + password: mongopassword + autoConnectRetry: true + socketKeepAlive: true + socketTimeout: 10000 + cloud: + zookeeper: + connect-string: localhost:2181 + discovery: + enabled: true + freemarker: + suffix: .ftl + content-type: text/html;charset=utf-8 + enabled: true + cache: true + template-loader-path: classpath:/templates/ + charset: UTF-8 +management: + endpoint: + shutdown: + enabled: true + health: + enabled: true + endpoints: + web: + base-path: /xxxxxx/actuator + exposure: + include: shutdown,health + +logging: + level: + org: + springframework: + data: + mongodb: + core: + MongoTemplate: DEBUG \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..a0464d2 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,35 @@ + + + + + + + + + ${pattern} + ${charsetEncoding} + + + + true + + ${pattern} + ${charsetEncoding} + + + + ${LOG_HOME}${file.separator}%d{yyMMdd}_info_%i.log + + 30 + 20MB + + + INFO + + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/flagnote/flagnoteconfig/FlagnoteConfigApplicationTests.java b/src/test/java/com/flagnote/flagnoteconfig/FlagnoteConfigApplicationTests.java new file mode 100644 index 0000000..26b6909 --- /dev/null +++ b/src/test/java/com/flagnote/flagnoteconfig/FlagnoteConfigApplicationTests.java @@ -0,0 +1,13 @@ +package com.flagnote.flagnoteconfig; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class FlagnoteConfigApplicationTests { + + @Test + void contextLoads() { + } + +}