Skip to content

Commit 1edf2ba

Browse files
Copilotcoopernetes
andcommitted
Add configuration tests and documentation
Co-authored-by: coopernetes <57812123+coopernetes@users.noreply.github.com>
1 parent c5d99e8 commit 1edf2ba

3 files changed

Lines changed: 263 additions & 1 deletion

File tree

CONFIGURATION.md

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# Configuration Guide
2+
3+
The Jetty-based GitProxy server supports configuration via YAML files. This allows you to configure providers, filters, and other server settings without modifying code.
4+
5+
## Configuration Files
6+
7+
The server loads configuration from the following files in order:
8+
1. `src/main/resources/application.yml` - Base configuration
9+
2. `src/main/resources/application-local.yml` - Local overrides (merged with base)
10+
11+
Configuration from `application-local.yml` will override or extend settings from `application.yml`.
12+
13+
## Server Configuration
14+
15+
```yaml
16+
server:
17+
port: 8080 # HTTP port for the server
18+
```
19+
20+
## Provider Configuration
21+
22+
Providers define the Git hosting services that the proxy will forward requests to.
23+
24+
### Built-in Providers
25+
26+
The following providers are built-in:
27+
- `github` - GitHub (https://github.com)
28+
- `gitlab` - GitLab (https://gitlab.com)
29+
- `bitbucket` - Bitbucket (https://bitbucket.org)
30+
31+
### Example Provider Configuration
32+
33+
```yaml
34+
git-proxy:
35+
base-path: "/git" # Optional base path for all servlets
36+
providers:
37+
github:
38+
enabled: true
39+
gitlab:
40+
enabled: true
41+
servlet-path: /custom-gitlab # Optional custom path
42+
bitbucket:
43+
enabled: false
44+
# Custom provider example
45+
internal-github:
46+
enabled: true
47+
servlet-path: /enterprise-github
48+
uri: https://githubserver.example.com
49+
```
50+
51+
### Provider Options
52+
53+
- `enabled` (boolean): Enable/disable the provider
54+
- `uri` (string): Custom URI for the provider (for self-hosted instances)
55+
- `servlet-path` (string): Custom servlet path (default is based on provider name)
56+
- `log-proxy` (boolean): Enable proxy logging (default: true)
57+
- `connect-timeout` (int): Connection timeout in milliseconds (default: -1, no timeout)
58+
- `read-timeout` (int): Read timeout in milliseconds (default: -1, no timeout)
59+
60+
## Filter Configuration
61+
62+
Filters control access to repositories and enforce policies.
63+
64+
### GitHub User Authentication Filter
65+
66+
Requires authentication for GitHub operations.
67+
68+
```yaml
69+
git-proxy:
70+
filters:
71+
github-user-authenticated:
72+
enabled: true
73+
order: 1
74+
operations:
75+
- PUSH
76+
required-auth-schemes: bearer, token, basic # Can be comma-separated or list
77+
providers:
78+
- github
79+
```
80+
81+
Options:
82+
- `enabled` (boolean): Enable/disable the filter
83+
- `order` (int): Filter execution order (lower numbers run first)
84+
- `operations` (list): Git operations to apply filter to (PUSH, FETCH)
85+
- `required-auth-schemes` (string or list): Required authentication schemes (bearer, token, basic)
86+
- `providers` (list): Provider names to apply filter to
87+
88+
### Whitelist Filters
89+
90+
Control which repositories can be accessed.
91+
92+
```yaml
93+
git-proxy:
94+
filters:
95+
whitelists:
96+
- enabled: true
97+
order: 5
98+
operations:
99+
- FETCH
100+
- PUSH
101+
providers:
102+
- github
103+
slugs:
104+
- coopernetes/test-repo
105+
- finos/git-proxy
106+
- enabled: true
107+
order: 10
108+
operations:
109+
- PUSH
110+
providers:
111+
- gitlab
112+
owners:
113+
- finosfoundation
114+
- enabled: true
115+
order: 20
116+
operations:
117+
- FETCH
118+
providers:
119+
- github
120+
names:
121+
- hello-world
122+
```
123+
124+
Options:
125+
- `enabled` (boolean): Enable/disable the filter
126+
- `order` (int): Filter execution order
127+
- `operations` (list): Git operations to apply filter to (PUSH, FETCH)
128+
- `providers` (list): Provider names to apply filter to
129+
- `slugs` (list): Repository slugs (owner/repo) to whitelist
130+
- `owners` (list): Repository owners to whitelist
131+
- `names` (list): Repository names to whitelist
132+
133+
Note: You can use `slugs`, `owners`, and `names` together in a single whitelist entry, or separately for more granular control.
134+
135+
## Running the Server
136+
137+
```bash
138+
# Build the application
139+
./gradlew build
140+
141+
# Run the application
142+
./gradlew run
143+
144+
# Or run the JAR directly
145+
java -jar build/libs/jgit-proxy-*.jar
146+
```
147+
148+
The server will read configuration from the YAML files and start with the configured providers and filters.
149+
150+
## Example Usage
151+
152+
Once the server is running, you can use it as a proxy for Git operations:
153+
154+
```bash
155+
# Clone via proxy
156+
git clone http://localhost:8080/github.com/finos/git-proxy.git
157+
158+
# Clone from GitLab via proxy
159+
git clone http://localhost:8080/gitlab.com/coopernetes/test-repo.git
160+
161+
# Clone from custom provider
162+
git clone http://localhost:8080/debian/salsa/test-repo.git
163+
```
164+
165+
## Logging
166+
167+
The application uses SLF4J with Logback. You can configure logging levels in the YAML files:
168+
169+
```yaml
170+
logging:
171+
level:
172+
org.finos.gitproxy: DEBUG
173+
org.finos.gitproxy.git: DEBUG
174+
```

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,53 @@ This is a simple implementation of a git proxy in Java. This is a possible succe
44
## Usage
55
To use this project, you need to have Java 17 or higher installed on your machine. You can run the project using the following command:
66
```shell
7-
./gradlew bootRun
7+
./gradlew run
8+
```
9+
10+
## Configuration
11+
12+
The Jetty-based server supports YAML-based configuration for providers and filters. Configuration files:
13+
- `src/main/resources/application.yml` - Base configuration
14+
- `src/main/resources/application-local.yml` - Local overrides
15+
16+
See [CONFIGURATION.md](CONFIGURATION.md) for detailed configuration options.
17+
18+
### Quick Configuration Example
19+
20+
Configure providers and filters in `application-local.yml`:
21+
22+
```yaml
23+
server:
24+
port: 8080
25+
26+
git-proxy:
27+
providers:
28+
github:
29+
enabled: true
30+
gitlab:
31+
enabled: true
32+
bitbucket:
33+
enabled: true
34+
filters:
35+
github-user-authenticated:
36+
enabled: true
37+
order: 1
38+
operations:
39+
- PUSH
40+
required-auth-schemes: bearer, token, basic
41+
providers:
42+
- github
43+
whitelists:
44+
- enabled: true
45+
order: 5
46+
operations:
47+
- FETCH
48+
- PUSH
49+
providers:
50+
- github
51+
slugs:
52+
- coopernetes/test-repo
53+
- finos/git-proxy
854
```
955
1056
## Endpoints
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.finos.gitproxy.config;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import java.util.List;
6+
import java.util.Map;
7+
import org.finos.gitproxy.provider.GitProxyProvider;
8+
import org.junit.jupiter.api.Test;
9+
10+
class JettyConfigurationLoaderTest {
11+
12+
@Test
13+
void testLoadDefaultConfiguration() {
14+
JettyConfigurationLoader loader = new JettyConfigurationLoader();
15+
assertNotNull(loader.getConfig());
16+
assertNotNull(loader.getGitProxyConfig());
17+
}
18+
19+
@Test
20+
void testGetProviders() {
21+
JettyConfigurationLoader loader = new JettyConfigurationLoader();
22+
Map<String, Map<String, Object>> providers = loader.getProviders();
23+
assertNotNull(providers);
24+
assertTrue(providers.containsKey("github"));
25+
}
26+
27+
@Test
28+
void testGetServerPort() {
29+
JettyConfigurationLoader loader = new JettyConfigurationLoader();
30+
int port = loader.getServerPort();
31+
assertEquals(8080, port);
32+
}
33+
34+
@Test
35+
void testBuildProviders() {
36+
JettyConfigurationLoader loader = new JettyConfigurationLoader();
37+
JettyConfigurationBuilder builder = new JettyConfigurationBuilder(loader);
38+
List<GitProxyProvider> providers = builder.buildProviders();
39+
assertNotNull(providers);
40+
assertTrue(providers.size() >= 1); // At least github in test config
41+
}
42+
}

0 commit comments

Comments
 (0)