Skip to content

Commit 64d7ef2

Browse files
authored
feat: Add gRPCs to get the server of a user (#126)
* feat: Changed gRPCs * feat: Implement rust part
1 parent 87be561 commit 64d7ef2

File tree

35 files changed

+895
-188
lines changed

35 files changed

+895
-188
lines changed

cli/src/application/network/connection/wrapper.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ use color_eyre::eyre::Result;
44
use tonic::Streaming;
55

66
use crate::application::network::proto::{
7-
common::notify,
7+
common::{common_group, common_server, common_user, notify},
88
manage::{
99
group, node, plugin,
1010
resource::{DelReq, SetReq},
1111
screen, server,
1212
transfer::TransferReq,
13-
user,
1413
},
1514
};
1615

@@ -162,7 +161,7 @@ impl EstablishedConnection {
162161
})
163162
}
164163

165-
pub fn get_groups(&self) -> NetworkTask<Result<Vec<group::Short>>> {
164+
pub fn get_groups(&self) -> NetworkTask<Result<Vec<common_group::Short>>> {
166165
let connection = self.connection.clone();
167166
let request = self.create_request(());
168167

@@ -194,7 +193,7 @@ impl EstablishedConnection {
194193
})
195194
}
196195

197-
pub fn get_servers(&self) -> NetworkTask<Result<Vec<server::Short>>> {
196+
pub fn get_servers(&self) -> NetworkTask<Result<Vec<common_server::Short>>> {
198197
let connection = self.connection.clone();
199198
let request = self.create_request(());
200199

@@ -236,7 +235,7 @@ impl EstablishedConnection {
236235
})
237236
}
238237

239-
pub fn get_users(&self) -> NetworkTask<Result<Vec<user::Item>>> {
238+
pub fn get_users(&self) -> NetworkTask<Result<Vec<common_user::Item>>> {
240239
let connection = self.connection.clone();
241240
let request = self.create_request(());
242241

cli/src/application/window/connect/tab/group/create.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tonic::async_trait;
1414
use crate::application::{
1515
network::{
1616
connection::{task::EmptyTask, EstablishedConnection},
17-
proto::manage::group,
17+
proto::{common::common_group, manage::group},
1818
},
1919
util::{
2020
fancy_toml::FancyToml,
@@ -50,7 +50,9 @@ pub struct CreateGroupTab {
5050
impl CreateGroupTab {
5151
/// Creates a new create group tab.
5252
/// This function will create a window stack to get the required information to create a group.
53-
pub fn new_stack(connection: Arc<EstablishedConnection>) -> FetchWindow<Vec<group::Short>> {
53+
pub fn new_stack(
54+
connection: Arc<EstablishedConnection>,
55+
) -> FetchWindow<Vec<common_group::Short>> {
5456
FetchWindow::new(
5557
connection.get_groups(),
5658
connection,

cli/src/application/window/connect/tab/group/get.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ use ratatui::{
1414
use tonic::async_trait;
1515

1616
use crate::application::{
17-
network::{connection::EstablishedConnection, proto::manage::group},
17+
network::{
18+
connection::EstablishedConnection,
19+
proto::{common::common_group, manage::group},
20+
},
1821
util::fancy_toml::FancyToml,
1922
window::{
2023
connect::tab::util::{fetch::FetchWindow, select::SelectWindow},
@@ -34,7 +37,9 @@ pub struct GetGroupTab {
3437
impl GetGroupTab {
3538
/// Creates a new get group tab.
3639
/// This function will create a window stack to get the required information to display the group.
37-
pub fn new_stack(connection: Arc<EstablishedConnection>) -> FetchWindow<Vec<group::Short>> {
40+
pub fn new_stack(
41+
connection: Arc<EstablishedConnection>,
42+
) -> FetchWindow<Vec<common_group::Short>> {
3843
FetchWindow::new(
3944
connection.get_groups(),
4045
connection,
@@ -130,7 +135,7 @@ impl GetGroupTab {
130135
}
131136
}
132137

133-
impl Display for group::Short {
138+
impl Display for common_group::Short {
134139
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
135140
write!(formatter, "{}", self.name)
136141
}

cli/src/application/window/connect/tab/server/get.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ use tonic::async_trait;
1313
use crate::application::{
1414
network::{
1515
connection::EstablishedConnection,
16-
proto::manage::server::{self},
16+
proto::{
17+
common::common_server,
18+
manage::server::{self},
19+
},
1720
},
1821
util::fancy_toml::FancyToml,
1922
window::{
@@ -34,7 +37,9 @@ pub struct GetServerTab {
3437
impl GetServerTab {
3538
/// Creates a new get server tab.
3639
/// This function will create a window stack to get the required information to display the server.
37-
pub fn new_stack(connection: Arc<EstablishedConnection>) -> FetchWindow<Vec<server::Short>> {
40+
pub fn new_stack(
41+
connection: Arc<EstablishedConnection>,
42+
) -> FetchWindow<Vec<common_server::Short>> {
3843
FetchWindow::new(
3944
connection.get_servers(),
4045
connection,

cli/src/application/window/connect/tab/server/screen.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ use tui_textarea::TextArea;
2222
use crate::application::{
2323
network::{
2424
connection::EstablishedConnection,
25-
proto::manage::{
26-
screen::{self, WriteReq},
27-
server,
25+
proto::{
26+
common::common_server,
27+
manage::screen::{self, WriteReq},
2828
},
2929
},
3030
util::{
@@ -41,7 +41,7 @@ use crate::application::{
4141
pub struct ScreenTab {
4242
/* Connection */
4343
connection: Arc<EstablishedConnection>,
44-
server: server::Short,
44+
server: common_server::Short,
4545
stream: Streaming<screen::Lines>,
4646

4747
/* State */
@@ -63,7 +63,9 @@ pub struct ScreenTab {
6363
impl ScreenTab {
6464
/// Creates a new screen tab.
6565
/// This function will create a window stack to get the required information to display the screen.
66-
pub fn new_stack(connection: Arc<EstablishedConnection>) -> FetchWindow<Vec<server::Short>> {
66+
pub fn new_stack(
67+
connection: Arc<EstablishedConnection>,
68+
) -> FetchWindow<Vec<common_server::Short>> {
6769
FetchWindow::new(
6870
connection.get_servers(),
6971
connection,
@@ -90,7 +92,7 @@ impl ScreenTab {
9092

9193
pub fn new(
9294
connection: Arc<EstablishedConnection>,
93-
server: server::Short,
95+
server: common_server::Short,
9496
stream: Streaming<screen::Lines>,
9597
) -> Self {
9698
let mut command = TextArea::default();
@@ -265,7 +267,7 @@ impl ScreenTab {
265267

266268
// Calculate the height/lines of the content area
267269
self.update_lines(
268-
paragraph.line_count(content_area.width), // Might be removed in the future my ratatui
270+
paragraph.line_count(content_area.width), // Might be removed in the future by ratatui
269271
content_area.height,
270272
);
271273

@@ -297,7 +299,7 @@ impl ScreenTab {
297299
}
298300
}
299301

300-
impl Display for server::Short {
302+
impl Display for common_server::Short {
301303
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
302304
write!(formatter, "{}", self.name)
303305
}

cli/src/application/window/connect/tab/user/transfer.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use tonic::async_trait;
1515
use crate::application::{
1616
network::{
1717
connection::{task::EmptyTask, EstablishedConnection},
18-
proto::manage::{
19-
transfer::{target::Type, Target, TransferReq},
20-
user,
18+
proto::{
19+
common::common_user,
20+
manage::transfer::{target::Type, Target, TransferReq},
2121
},
2222
},
2323
util::status::{Status, StatusDisplay},
@@ -42,7 +42,9 @@ pub struct TransferUserTab {
4242
impl TransferUserTab {
4343
/// Creates a new transfer user tab.
4444
/// This function will create a window stack to get the required information to transfer the users.
45-
pub fn new_stack(connection: Arc<EstablishedConnection>) -> FetchWindow<Vec<user::Item>> {
45+
pub fn new_stack(
46+
connection: Arc<EstablishedConnection>,
47+
) -> FetchWindow<Vec<common_user::Item>> {
4648
FetchWindow::new(
4749
connection.get_users(),
4850
connection,
@@ -114,7 +116,7 @@ impl TransferUserTab {
114116
target: Option<String>,
115117
) -> Self
116118
where
117-
T: IntoIterator<Item = user::Item>,
119+
T: IntoIterator<Item = common_user::Item>,
118120
{
119121
Self {
120122
request: connection.transfer_users(TransferReq {
@@ -205,7 +207,7 @@ impl TransferUserTab {
205207
}
206208
}
207209

208-
impl Display for user::Item {
210+
impl Display for common_user::Item {
209211
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
210212
write!(formatter, "{} ({})", self.name, self.id)
211213
}

clients/java/api/src/main/java/io/atomic/cloud/api/resource/Resources.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import io.atomic.cloud.api.resource.simple.SimpleCloudGroup;
44
import io.atomic.cloud.api.resource.simple.SimpleCloudServer;
5+
import java.util.Optional;
6+
import java.util.UUID;
57
import java.util.concurrent.CompletableFuture;
68

79
/** The Resources interface provides methods to access cloud groups and cloud servers. */
@@ -14,10 +16,50 @@ public interface Resources {
1416
*/
1517
CompletableFuture<SimpleCloudGroup[]> groups();
1618

19+
/**
20+
* Retrieves a SimpleGroup object that matches the specified name.
21+
*
22+
* @param name the name of the group to retrieve
23+
* @return a SimpleGroup instance
24+
*/
25+
CompletableFuture<Optional<SimpleCloudGroup>> groupFromName(String name);
26+
27+
/**
28+
* Retrieves a SimpleGroup object that contains the specified user as a member.
29+
*
30+
* @param uuid the uuid of the user to retrieve the group for
31+
* @return a SimpleGroup instance
32+
*/
33+
CompletableFuture<Optional<SimpleCloudGroup>> groupFromUser(UUID uuid);
34+
1735
/**
1836
* Retrieves an array of SimpleServer objects.
1937
*
2038
* @return an array of SimpleServer instances
2139
*/
2240
CompletableFuture<SimpleCloudServer[]> servers();
41+
42+
/**
43+
* Retrieves a SimpleServer object that matches the specified name.
44+
*
45+
* @param name the name of the server to retrieve
46+
* @return a SimpleServer instance
47+
*/
48+
CompletableFuture<Optional<SimpleCloudServer>> serverFromName(String name);
49+
50+
/**
51+
* Retrieves a SimpleServer object that matches the specified uuid.
52+
*
53+
* @param uuid the uuid of the server to retrieve
54+
* @return a SimpleServer instance
55+
*/
56+
CompletableFuture<Optional<SimpleCloudServer>> serverFromUuid(UUID uuid);
57+
58+
/**
59+
* Retrieves a SimpleServer object that contains the specified user as a member.
60+
*
61+
* @param uuid the uuid of the user to retrieve the server for
62+
* @return a SimpleServer instance
63+
*/
64+
CompletableFuture<Optional<SimpleCloudServer>> serverFromUser(UUID uuid);
2365
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.atomic.cloud.api.user;
2+
3+
import java.util.Optional;
4+
import java.util.UUID;
5+
6+
public interface CloudUser {
7+
8+
String name();
9+
10+
UUID uuid();
11+
12+
Optional<String> group();
13+
14+
Optional<UUID> server();
15+
}

clients/java/api/src/main/java/io/atomic/cloud/api/user/Users.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package io.atomic.cloud.api.user;
22

3+
import java.util.Optional;
4+
import java.util.UUID;
35
import java.util.concurrent.CompletableFuture;
46

7+
/** The Users interface provides methods to access cloud users. */
58
public interface Users {
69

710
/**
@@ -10,4 +13,20 @@ public interface Users {
1013
* @return The number of users on the network
1114
*/
1215
CompletableFuture<Integer> userCount();
16+
17+
/**
18+
* Retrieves a User object that matches the specified name.
19+
*
20+
* @param name the uuid of the server to retrieve
21+
* @return a User instance
22+
*/
23+
CompletableFuture<Optional<CloudUser>> userFromName(String name);
24+
25+
/**
26+
* Retrieves a User object that matches the specified uuid.
27+
*
28+
* @param uuid the uuid of the user to retrieve
29+
* @return a User instance
30+
*/
31+
CompletableFuture<Optional<CloudUser>> userFromUuid(UUID uuid);
1332
}

0 commit comments

Comments
 (0)