Skip to content

Commit 4a143d8

Browse files
committed
feat: initial commit
0 parents  commit 4a143d8

20 files changed

Lines changed: 952 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# name
2+
name: ci
3+
4+
# triggers
5+
on:
6+
workflow_dispatch:
7+
push:
8+
branches:
9+
- main
10+
tags:
11+
- v*.*.*
12+
paths-ignore:
13+
- README.md
14+
- LICENSE
15+
- .github/**
16+
- .gitignore
17+
- .editorconfig
18+
- renovate.json
19+
pull_request:
20+
branches:
21+
- main
22+
paths-ignore:
23+
- README.md
24+
- LICENSE
25+
- .github/**
26+
- .gitignore
27+
- .editorconfig
28+
- renovate.json
29+
30+
jobs:
31+
check:
32+
uses: cidverse/catalog/.github/workflows/shared-ci.yml@main
33+
permissions:
34+
contents: write # create release
35+
packages: write # publish packages
36+
security-events: write # sarif reports
37+
pages: write # pages
38+
id-token: write # signing
39+
with:
40+
cid-workflow: main
41+
cid-version: latest
42+
secrets:
43+
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
44+
SONAR_ORGANIZATION: ${{ secrets.SONAR_ORGANIZATION }}
45+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.gitignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Java class files
2+
*.class
3+
4+
# Mobile Tools for Java (J2ME)
5+
.mtj.tmp/
6+
7+
# Package Files #
8+
*.jar
9+
*.war
10+
*.ear
11+
12+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
13+
hs_err_pid*
14+
15+
# generated files
16+
bin/
17+
gen/
18+
build/
19+
out/
20+
21+
# Eclipse project files
22+
.classpath
23+
.project
24+
.settings/
25+
26+
# Proguard folder generated by Eclipse
27+
proguard/
28+
29+
# Local configuration file (sdk path, etc)
30+
local.properties
31+
32+
# Intellij project files
33+
*.iml
34+
*.ipr
35+
*.iws
36+
.idea/
37+
38+
#Gradle
39+
.gradletasknamecache
40+
.gradle/
41+
gradle.properties
42+
43+
# Exceptions
44+
!gradle/wrapper/*.jar
45+
46+
# Logs / Save Files
47+
config/*
48+
client.log
49+
50+
# JavaDoc
51+
/docs/javadoc/*
52+
53+
# Example Code
54+
/src/main/java/me/philippheuer/twitch4j/example/*
55+
56+
# Modules
57+
/modules/
58+
59+
# ci
60+
.dist
61+
.tmp

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Philipp Heuer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# *PrimeCodeGen Libraries*
2+
3+
A collection of libraries used in generated code for the [PrimeCodeGen](https://github.com/primelib/primecodegen) project.
4+
5+
## License
6+
7+
Released under the [MIT License](./LICENSE).

bom/build.gradle.kts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
plugins {
2+
`java-platform`
3+
}
4+
5+
projectConfiguration {
6+
artifactId.set("bom")
7+
artifactDisplayName.set("PrimeLib Java - BOM")
8+
artifactDescription.set("PrimeLib Java - Bill of materials")
9+
type.set(me.philippheuer.projectcfg.domain.ProjectType.LIBRARY)
10+
}
11+
12+
dependencies {
13+
constraints {
14+
api(project(":feign-common"))
15+
api(project(":feign-resilience4j"))
16+
}
17+
}

build.gradle.kts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Plugins
2+
plugins {
3+
`java-library`
4+
id("me.philippheuer.configuration") version "0.10.7"
5+
}
6+
7+
version = properties["version"] as String
8+
9+
// All-Projects
10+
allprojects {
11+
apply(plugin = "me.philippheuer.configuration")
12+
13+
projectConfiguration {
14+
language.set(me.philippheuer.projectcfg.domain.ProjectLanguage.JAVA)
15+
type.set(me.philippheuer.projectcfg.domain.ProjectType.LIBRARY)
16+
javaVersion.set(JavaVersion.VERSION_17)
17+
artifactGroupId.set("io.github.primelib.primecodegenlib.java")
18+
19+
pom = { pom ->
20+
pom.url.set("https://github.com/primelib/primecodegen-lib-java")
21+
pom.issueManagement {
22+
system.set("GitHub")
23+
url.set("https://github.com/primelib/primecodegen-lib-java")
24+
}
25+
pom.inceptionYear.set("2023")
26+
pom.developers {
27+
developer {
28+
id.set("PhilippHeuer")
29+
name.set("Philipp Heuer")
30+
email.set("git@philippheuer.me")
31+
roles.addAll("maintainer")
32+
}
33+
}
34+
pom.licenses {
35+
license {
36+
name.set("MIT Licence")
37+
distribution.set("repo")
38+
url.set("https://github.com/primelib/primecodegen-lib-java/blob/main/LICENSE")
39+
}
40+
}
41+
pom.scm {
42+
connection.set("scm:git:https://github.com/primelib/primecodegen-lib-java.git")
43+
developerConnection.set("scm:git:git@github.com:primelib/primecodegen-lib-java.git")
44+
url.set("https://github.com/primelib/primecodegen-lib-java")
45+
}
46+
}
47+
}
48+
}
49+
50+
// Subprojects
51+
subprojects {
52+
if (!name.contains("bom")) {
53+
apply(plugin = "java-library")
54+
55+
dependencies {
56+
// bom
57+
add("api", platform("io.github.openfeign:feign-bom:12.4"))
58+
add("api", platform("io.github.resilience4j:resilience4j-bom:2.1.0"))
59+
}
60+
}
61+
}

feign-common/build.gradle.kts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
plugins {
2+
`java-library`
3+
}
4+
5+
projectConfiguration {
6+
artifactId.set("feign-common")
7+
artifactDisplayName.set("Feign Common")
8+
artifactDescription.set("Feign Common")
9+
}
10+
11+
dependencies {
12+
// annotations
13+
implementation("org.jetbrains:annotations:24.0.1")
14+
15+
// feign
16+
api("io.github.openfeign:feign-core")
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.github.primelib.primecodegenlib.java.feign.common.api;
2+
3+
import java.util.Map;
4+
5+
public interface AuthMethod {
6+
Map<String, String> headerMap();
7+
Map<String, String> queryMap();
8+
Map<String, String> cookieMap();
9+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package io.github.primelib.primecodegenlib.java.feign.common.config;
2+
3+
import lombok.AccessLevel;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
import lombok.experimental.Accessors;
7+
import lombok.extern.slf4j.Slf4j;
8+
import org.jetbrains.annotations.ApiStatus;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
import java.net.Proxy;
12+
import java.net.URI;
13+
import java.net.URISyntaxException;
14+
import java.util.HashSet;
15+
import java.util.Objects;
16+
import java.util.Set;
17+
import java.util.function.Consumer;
18+
19+
@Data
20+
@Accessors(fluent = true)
21+
@NoArgsConstructor(access = AccessLevel.PRIVATE, force = true)
22+
@Slf4j
23+
public class ProxySpec {
24+
/*
25+
* Only HTTP(S) proxies are supported due to library limitations
26+
*/
27+
@NotNull
28+
private Proxy.Type type = Proxy.Type.HTTP;
29+
30+
/**
31+
* The host of the proxy server
32+
*/
33+
private String host;
34+
35+
/**
36+
* The port of the proxy server
37+
*/
38+
private Integer port;
39+
40+
/**
41+
* The username used to authenticate with the proxy, if applicable
42+
*/
43+
private String username;
44+
45+
/**
46+
* The password used to authenticate with the proxy, if applicable
47+
*/
48+
private char[] password;
49+
50+
/**
51+
* Constructs a validated implementation of {@link ProxySpec}.
52+
*
53+
* @param spec the specification to process
54+
*/
55+
@ApiStatus.Internal
56+
public ProxySpec(Consumer<ProxySpec> spec) {
57+
spec.accept(this);
58+
validate();
59+
}
60+
61+
/**
62+
* Validates the Spec, will throw a exception if required parameters are missing
63+
*
64+
* @throws NullPointerException if a required parameter is missing
65+
* @throws IllegalArgumentException if a parameter has an invalid value
66+
*/
67+
public void validate() {
68+
Objects.requireNonNull(type, "type is a required parameter!");
69+
if (type == Proxy.Type.HTTP) {
70+
Objects.requireNonNull(host, "host is a required parameter!");
71+
Objects.requireNonNull(port, "port is a required parameter!");
72+
}
73+
}
74+
75+
/**
76+
* Creates a new {@link ProxySpec} with values taken from the proxy environment variables, if applicable.
77+
*/
78+
public static ProxySpec detect() {
79+
Set<String> proxies = new HashSet<>(2);
80+
proxies.add(System.getenv("http_proxy"));
81+
proxies.add(System.getenv("https_proxy"));
82+
83+
// check if a proxy is configured
84+
for (String p : proxies) {
85+
try {
86+
URI proxyUri = new URI(p);
87+
return new ProxySpec(spec -> {
88+
spec.type(Proxy.Type.HTTP);
89+
spec.host(proxyUri.getHost());
90+
spec.port(proxyUri.getPort() == -1 ? 80 : proxyUri.getPort());
91+
});
92+
} catch (URISyntaxException ignored) {
93+
// ignore invalid proxy settings
94+
}
95+
}
96+
97+
// no proxy configured
98+
return new ProxySpec(spec -> {
99+
spec.type(Proxy.Type.DIRECT);
100+
});
101+
}
102+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.github.primelib.primecodegenlib.java.feign.common.interceptor;
2+
3+
import feign.RequestInterceptor;
4+
import feign.RequestTemplate;
5+
import io.github.primelib.primecodegenlib.java.feign.common.api.AuthMethod;
6+
import lombok.AllArgsConstructor;
7+
8+
import java.util.List;
9+
10+
@AllArgsConstructor
11+
public class AuthInterceptor implements RequestInterceptor {
12+
List<AuthMethod> authMethods;
13+
14+
@Override
15+
public void apply(RequestTemplate template) {
16+
if (authMethods == null || authMethods.isEmpty()) {
17+
return;
18+
}
19+
20+
for (AuthMethod authMethod : authMethods) {
21+
if (authMethod.headerMap() != null) {
22+
authMethod.headerMap().forEach(template::header);
23+
}
24+
if (authMethod.queryMap() != null) {
25+
authMethod.queryMap().forEach(template::query);
26+
}
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)