Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions .github/workflows/ci.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

on:
pull_request:
branches: [ main ]

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Start the cluster
run: docker compose -f ci/docker-compose.yml up -d

- name: Run test
run: ./gradlew test

spell-check:
name: Spell Check
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v2

- name: Check Spelling
uses: crate-ci/typos@master
23 changes: 21 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import com.adarshr.gradle.testlogger.TestLoggerExtension
import com.adarshr.gradle.testlogger.theme.ThemeType

group = "cloud.xline"
version = "1.0-SNAPSHOT"
version = "0.1.0-SNAPSHOT"

buildscript {
repositories {
Expand All @@ -27,6 +27,7 @@ subprojects {
apply(plugin = "java-library")
apply(plugin = "org.gradle.test-retry")
apply(plugin = "com.adarshr.test-logger")
apply(plugin = "maven-publish")

tasks {
named<JavaCompile>("compileJava") {
Expand All @@ -47,8 +48,26 @@ subprojects {
}
}

extensions.getByType<TestLoggerExtension>().apply {
configure<PublishingExtension> {
publications {
create<MavenPublication>("maven") {
groupId = rootProject.group.toString()
version = rootProject.version.toString()

from(components["java"])

}
}
}

configure<JavaPluginExtension> {
withSourcesJar()
withJavadocJar()
}

configure<TestLoggerExtension> {
theme = ThemeType.MOCHA_PARALLEL
showStandardStreams = false
}

}
71 changes: 71 additions & 0 deletions ci/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
version: '3.9'

networks:
xline_network:
driver: bridge
ipam:
driver: default
config:
- subnet: "172.18.0.0/16"

services:
node1:
image: ghcr.io/xline-kv/xline:latest
networks:
xline_network:
ipv4_address: 172.18.0.2
volumes:
- .:/mnt
ports:
- "2379:2379"
environment:
RUST_LOG: curp=debug,xline=debug
command: >
xline
--name node1
--members node1=http://172.18.0.2:2379,node2=http://172.18.0.3:2379,node3=http://172.18.0.4:2379
--storage-engine rocksdb
--data-dir /usr/local/xline/data-dir
--auth-public-key /mnt/public.pem
--auth-private-key /mnt/private.pem
--is-leader

node2:
image: ghcr.io/xline-kv/xline:latest
networks:
xline_network:
ipv4_address: 172.18.0.3
volumes:
- .:/mnt
ports:
- "2380:2379"
environment:
RUST_LOG: curp=debug,xline=debug
command: >
xline
--name node2
--members node1=http://172.18.0.2:2379,node2=http://172.18.0.3:2379,node3=http://172.18.0.4:2379
--storage-engine rocksdb
--data-dir /usr/local/xline/data-dir
--auth-public-key /mnt/public.pem
--auth-private-key /mnt/private.pem

node3:
image: ghcr.io/xline-kv/xline:latest
networks:
xline_network:
ipv4_address: 172.18.0.4
volumes:
- .:/mnt
ports:
- "2381:2379"
environment:
RUST_LOG: curp=debug,xline=debug
command: >
xline
--name node3
--members node1=http://172.18.0.2:2379,node2=http://172.18.0.3:2379,node3=http://172.18.0.4:2379
--storage-engine rocksdb
--data-dir /usr/local/xline/data-dir
--auth-public-key /mnt/public.pem
--auth-private-key /mnt/private.pem
28 changes: 28 additions & 0 deletions ci/private.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCnAxxSXJYWZCKr
6f6j0HRUwkhX/0+GXjEclWoLA5+KZAuWMSu8bz6X+IScv4vNwORlGSWOnrz+8mb2
I0F6teVZWfWFqsnyWk7IxM+h9yTg7aY/8685YfWTL7fpWq1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ybo3kMbq6wyB7xWyRLvdkuZ+WmXVumgb/uL0K0nIfzMscrAoGAeA1e
K845YSslBQaSbk7/e/X1iguyDWT2eRO01zvTYgPNwZipl2CPHjkPM2km0fy5oaps
N/94IUd7+EsSmsAKL5LytGbtRFyR+c376rw8+OIFz/iy4BsQCRqJQjWa1lHZf96x
PIg2hW2xhD9OTv3IS94sdeG4NmUdipMQryhEqoECgYEAkvXOg66IAVTrO6qgoyl5
42oufa/QE+qOAYoQEpmx3SZx6tMkycfAQqUHYcXhW1HNjyGbbg/sl13yddnPQqig
+ObtQNSIqGZWCc/HIqM//pPI3MHPhWARMOmAbk0I1mT0QKhuFfSugV2xb1Dj/Rvf
0VdB8txY+5Wz6zP1F2g46gM=
-----END PRIVATE KEY-----
9 changes: 9 additions & 0 deletions ci/public.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApwMcUlyWFmQiq+n+o9B0
VMJIV/9Phl4xHJVqCwOfimQLljErvG8+l/iEnL+LzcDkZRkljp68/vJm9iNBerXl
WVn1harJ8lpOyMTPofck4O2mP/OvOWH1ky+36Vqtf9xZ4s+EG7GBbswdVYGmeXw9
gkmCCs0g/qlUpVxduSQxR1e29jnR619FCmTk1mP1RP/0k7fjySnV/Ud6ZZBsAMyS
JJHAGctL4b6k9wEk4F3ITXjfMBmGG92Iq5KiLEAeV3LNUdVvss/iK1Wuv9FjHMhO
qrST2dJb4sk9Jx1f6WY17g+AdGo2v9X5Px5lwzzI6StQbggU0rTPypXKwKAMaPmA
4QIDAQAB
-----END PUBLIC KEY-----
1 change: 1 addition & 0 deletions jxline-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dependencies {
api(libs.jetcd)

testImplementation(libs.bundles.testing)
testRuntimeOnly(libs.bundles.log4j)
}
139 changes: 139 additions & 0 deletions jxline-core/src/main/java/cloud/xline/jxline/Auth.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package cloud.xline.jxline;

import cloud.xline.jxline.auth.*;
import io.etcd.jetcd.ByteSequence;
import io.etcd.jetcd.support.CloseableClient;

import java.util.concurrent.CompletableFuture;

public interface Auth extends CloseableClient {
/**
* enables auth of an etcd cluster.
*
* @return the response.
*/
CompletableFuture<AuthEnableResponse> authEnable();

/**
* disables auth of an etcd cluster.
*
* @return the response.
*/
CompletableFuture<AuthDisableResponse> authDisable();

/**
* adds a new user to an etcd cluster.
*
* @param user the user
* @param password the password
* @return the response.
*/
CompletableFuture<AuthUserAddResponse> userAdd(ByteSequence user, ByteSequence password);

/**
* deletes a user from an etcd cluster.
*
* @param user the user
* @return the response.
*/
CompletableFuture<AuthUserDeleteResponse> userDelete(ByteSequence user);

/**
* changes a password of a user.
*
* @param user the user
* @param password the password
* @return the response.
*/
CompletableFuture<AuthUserChangePasswordResponse> userChangePassword(
ByteSequence user, ByteSequence password);

/**
* gets detailed information of a user.
*
* @param user the user
* @return the response.
*/
CompletableFuture<AuthUserGetResponse> userGet(ByteSequence user);

/**
* gets a list of all users.
*
* @return the response.
*/
CompletableFuture<AuthUserListResponse> userList();

/**
* grants a role to a user.
*
* @param user the user
* @param role the role to grant
* @return the response.
*/
CompletableFuture<AuthUserGrantRoleResponse> userGrantRole(
ByteSequence user, ByteSequence role);

/**
* revokes a role of a user.
*
* @param user the user
* @param role the role to revoke
* @return the response.
*/
CompletableFuture<AuthUserRevokeRoleResponse> userRevokeRole(
ByteSequence user, ByteSequence role);

/**
* adds a new role to an etcd cluster.
*
* @param role the role to add
* @return the response.
*/
CompletableFuture<AuthRoleAddResponse> roleAdd(ByteSequence role);

/**
* grants a permission to a role.
*
* @param role the role
* @param key the key
* @param rangeEnd the range end
* @param permType the type
* @return the response.
*/
CompletableFuture<AuthRoleGrantPermissionResponse> roleGrantPermission(
ByteSequence role, ByteSequence key, ByteSequence rangeEnd, Permission.Type permType);

/**
* gets detailed information of a role.
*
* @param role the role to get
* @return the response.
*/
CompletableFuture<AuthRoleGetResponse> roleGet(ByteSequence role);

/**
* gets a list of all roles.
*
* @return the response.
*/
CompletableFuture<AuthRoleListResponse> roleList();

/**
* revokes a permission from a role.
*
* @param role the role
* @param key the key
* @param rangeEnd the range end
* @return the response.
*/
CompletableFuture<AuthRoleRevokePermissionResponse> roleRevokePermission(
ByteSequence role, ByteSequence key, ByteSequence rangeEnd);

/**
* RoleDelete deletes a role.
*
* @param role the role to delete.
* @return the response.
*/
CompletableFuture<AuthRoleDeleteResponse> roleDelete(ByteSequence role);
}
10 changes: 9 additions & 1 deletion jxline-core/src/main/java/cloud/xline/jxline/Client.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package cloud.xline.jxline;

public interface Client extends io.etcd.jetcd.Client {
public interface Client extends AutoCloseable {

ProtocolClient getProtocolClient();

Auth getAuthClient();

KV getKVClient();

Watch getWatchClient();

/**
* Override the jetcd.cloud.xline.client.Client.builder
Expand Down
Loading