-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add permissions to velocity #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lusu007
wants to merge
3
commits into
main
Choose a base branch
from
feat/permission
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package gg.grounds.grpc | ||
|
|
||
| import io.grpc.ManagedChannel | ||
| import io.grpc.ManagedChannelBuilder | ||
| import java.util.concurrent.TimeUnit | ||
|
|
||
| abstract class BaseGrpcClient(protected val channel: ManagedChannel) : AutoCloseable { | ||
| override fun close() { | ||
| closeChannel(channel) | ||
| } | ||
|
|
||
| companion object { | ||
| fun createChannel(target: String): ManagedChannel { | ||
| val channelBuilder = ManagedChannelBuilder.forTarget(target) | ||
| channelBuilder.usePlaintext() | ||
| return channelBuilder.build() | ||
| } | ||
|
|
||
| fun closeChannel(channel: ManagedChannel) { | ||
| channel.shutdown() | ||
| try { | ||
| if (!channel.awaitTermination(3, TimeUnit.SECONDS)) { | ||
| channel.shutdownNow() | ||
| channel.awaitTermination(3, TimeUnit.SECONDS) | ||
| } | ||
| } catch (e: InterruptedException) { | ||
| Thread.currentThread().interrupt() | ||
| channel.shutdownNow() | ||
| } | ||
| } | ||
| } | ||
| } |
86 changes: 86 additions & 0 deletions
86
common/src/main/kotlin/gg/grounds/permissions/GrpcPermissionsAdminClient.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| package gg.grounds.permissions | ||
|
|
||
| import gg.grounds.grpc.BaseGrpcClient | ||
| import gg.grounds.grpc.permissions.AddGroupPermissionsReply | ||
| import gg.grounds.grpc.permissions.AddGroupPermissionsRequest | ||
| import gg.grounds.grpc.permissions.AddPlayerGroupsReply | ||
| import gg.grounds.grpc.permissions.AddPlayerGroupsRequest | ||
| import gg.grounds.grpc.permissions.AddPlayerPermissionsReply | ||
| import gg.grounds.grpc.permissions.AddPlayerPermissionsRequest | ||
| import gg.grounds.grpc.permissions.CreateGroupReply | ||
| import gg.grounds.grpc.permissions.CreateGroupRequest | ||
| import gg.grounds.grpc.permissions.DeleteGroupReply | ||
| import gg.grounds.grpc.permissions.DeleteGroupRequest | ||
| import gg.grounds.grpc.permissions.GetGroupReply | ||
| import gg.grounds.grpc.permissions.GetGroupRequest | ||
| import gg.grounds.grpc.permissions.ListGroupsReply | ||
| import gg.grounds.grpc.permissions.ListGroupsRequest | ||
| import gg.grounds.grpc.permissions.PermissionsAdminServiceGrpc | ||
| import gg.grounds.grpc.permissions.RemoveGroupPermissionsReply | ||
| import gg.grounds.grpc.permissions.RemoveGroupPermissionsRequest | ||
| import gg.grounds.grpc.permissions.RemovePlayerGroupsReply | ||
| import gg.grounds.grpc.permissions.RemovePlayerGroupsRequest | ||
| import gg.grounds.grpc.permissions.RemovePlayerPermissionsReply | ||
| import gg.grounds.grpc.permissions.RemovePlayerPermissionsRequest | ||
| import io.grpc.ManagedChannel | ||
| import java.util.concurrent.TimeUnit | ||
|
|
||
| class GrpcPermissionsAdminClient | ||
| private constructor( | ||
| channel: ManagedChannel, | ||
| private val stub: PermissionsAdminServiceGrpc.PermissionsAdminServiceBlockingStub, | ||
| ) : BaseGrpcClient(channel) { | ||
| fun createGroup(request: CreateGroupRequest): CreateGroupReply = | ||
| stub.withDeadlineAfter(DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS).createGroup(request) | ||
|
|
||
| fun deleteGroup(request: DeleteGroupRequest): DeleteGroupReply = | ||
| stub.withDeadlineAfter(DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS).deleteGroup(request) | ||
|
|
||
| fun getGroup(request: GetGroupRequest): GetGroupReply = | ||
| stub.withDeadlineAfter(DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS).getGroup(request) | ||
|
|
||
| fun listGroups(request: ListGroupsRequest): ListGroupsReply = | ||
| stub.withDeadlineAfter(DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS).listGroups(request) | ||
|
|
||
| fun addGroupPermissions(request: AddGroupPermissionsRequest): AddGroupPermissionsReply = | ||
| stub | ||
| .withDeadlineAfter(DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS) | ||
| .addGroupPermissions(request) | ||
|
|
||
| fun removeGroupPermissions( | ||
| request: RemoveGroupPermissionsRequest | ||
| ): RemoveGroupPermissionsReply = | ||
| stub | ||
| .withDeadlineAfter(DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS) | ||
| .removeGroupPermissions(request) | ||
|
|
||
| fun addPlayerPermissions(request: AddPlayerPermissionsRequest): AddPlayerPermissionsReply = | ||
| stub | ||
| .withDeadlineAfter(DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS) | ||
| .addPlayerPermissions(request) | ||
|
|
||
| fun removePlayerPermissions( | ||
| request: RemovePlayerPermissionsRequest | ||
| ): RemovePlayerPermissionsReply = | ||
| stub | ||
| .withDeadlineAfter(DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS) | ||
| .removePlayerPermissions(request) | ||
|
|
||
| fun addPlayerGroups(request: AddPlayerGroupsRequest): AddPlayerGroupsReply = | ||
| stub.withDeadlineAfter(DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS).addPlayerGroups(request) | ||
|
|
||
| fun removePlayerGroups(request: RemovePlayerGroupsRequest): RemovePlayerGroupsReply = | ||
| stub | ||
| .withDeadlineAfter(DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS) | ||
| .removePlayerGroups(request) | ||
|
|
||
| companion object { | ||
| fun create(target: String): GrpcPermissionsAdminClient { | ||
| val channel = createChannel(target) | ||
| val stub = PermissionsAdminServiceGrpc.newBlockingStub(channel) | ||
| return GrpcPermissionsAdminClient(channel, stub) | ||
| } | ||
|
|
||
| private const val DEFAULT_TIMEOUT_MS = 2000L | ||
| } | ||
| } |
64 changes: 64 additions & 0 deletions
64
common/src/main/kotlin/gg/grounds/permissions/GrpcPermissionsClient.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package gg.grounds.permissions | ||
|
|
||
| import gg.grounds.grpc.BaseGrpcClient | ||
| import gg.grounds.grpc.permissions.CheckPlayerPermissionReply | ||
| import gg.grounds.grpc.permissions.CheckPlayerPermissionRequest | ||
| import gg.grounds.grpc.permissions.GetPlayerPermissionsReply | ||
| import gg.grounds.grpc.permissions.GetPlayerPermissionsRequest | ||
| import gg.grounds.grpc.permissions.PermissionsServiceGrpc | ||
| import io.grpc.ManagedChannel | ||
| import io.grpc.Status | ||
| import io.grpc.StatusRuntimeException | ||
| import java.util.UUID | ||
| import java.util.concurrent.TimeUnit | ||
|
|
||
| class GrpcPermissionsClient | ||
| private constructor( | ||
| channel: ManagedChannel, | ||
| private val stub: PermissionsServiceGrpc.PermissionsServiceBlockingStub, | ||
| ) : BaseGrpcClient(channel) { | ||
| fun getPlayerPermissions( | ||
| playerId: UUID, | ||
| includeEffectivePermissions: Boolean = true, | ||
| includeDirectPermissions: Boolean = true, | ||
| includeGroups: Boolean = true, | ||
| ): GetPlayerPermissionsReply { | ||
| return stub | ||
| .withDeadlineAfter(DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS) | ||
| .getPlayerPermissions( | ||
| GetPlayerPermissionsRequest.newBuilder() | ||
| .setPlayerId(playerId.toString()) | ||
| .setIncludeEffectivePermissions(includeEffectivePermissions) | ||
| .setIncludeDirectPermissions(includeDirectPermissions) | ||
| .setIncludeGroups(includeGroups) | ||
| .build() | ||
| ) | ||
| } | ||
|
|
||
| fun checkPlayerPermission(playerId: UUID, permission: String): CheckPlayerPermissionReply { | ||
| return stub | ||
| .withDeadlineAfter(DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS) | ||
| .checkPlayerPermission( | ||
| CheckPlayerPermissionRequest.newBuilder() | ||
| .setPlayerId(playerId.toString()) | ||
| .setPermission(permission) | ||
| .build() | ||
| ) | ||
| } | ||
|
|
||
| companion object { | ||
| fun create(target: String): GrpcPermissionsClient { | ||
| val channel = createChannel(target) | ||
| val stub = PermissionsServiceGrpc.newBlockingStub(channel) | ||
| return GrpcPermissionsClient(channel, stub) | ||
| } | ||
|
|
||
| fun isServiceUnavailable(status: Status.Code): Boolean = | ||
| status == Status.Code.UNAVAILABLE || status == Status.Code.DEADLINE_EXCEEDED | ||
|
|
||
| fun isServiceUnavailable(error: StatusRuntimeException): Boolean = | ||
| isServiceUnavailable(error.status.code) | ||
|
|
||
| private const val DEFAULT_TIMEOUT_MS = 2000L | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
common/src/main/kotlin/gg/grounds/permissions/GrpcPermissionsEventsClient.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package gg.grounds.permissions | ||
|
|
||
| import gg.grounds.grpc.BaseGrpcClient | ||
| import gg.grounds.grpc.permissions.PermissionsChangeEvent | ||
| import gg.grounds.grpc.permissions.PermissionsEventsServiceGrpc | ||
| import gg.grounds.grpc.permissions.SubscribePermissionsChangesRequest | ||
| import io.grpc.ManagedChannel | ||
| import io.grpc.stub.StreamObserver | ||
|
|
||
| class GrpcPermissionsEventsClient | ||
| private constructor( | ||
| channel: ManagedChannel, | ||
| private val stub: PermissionsEventsServiceGrpc.PermissionsEventsServiceStub, | ||
| ) : BaseGrpcClient(channel) { | ||
| fun subscribe( | ||
| request: SubscribePermissionsChangesRequest, | ||
| observer: StreamObserver<PermissionsChangeEvent>, | ||
| ) { | ||
| stub.subscribePermissionsChanges(request, observer) | ||
| } | ||
|
|
||
| companion object { | ||
| fun create(target: String): GrpcPermissionsEventsClient { | ||
| val channel = createChannel(target) | ||
| val stub = PermissionsEventsServiceGrpc.newStub(channel) | ||
| return GrpcPermissionsEventsClient(channel, stub) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...unds/player/presence/PlayerLoginResult.kt β .../gg/grounds/presence/PlayerLoginResult.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package gg.grounds.player.presence | ||
| package gg.grounds.presence | ||
|
|
||
| import gg.grounds.grpc.player.PlayerLoginReply | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.