Skip to content
Merged
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
9 changes: 4 additions & 5 deletions cli/src/application/network/connection/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use color_eyre::eyre::Result;
use tonic::Streaming;

use crate::application::network::proto::{
common::notify,
common::{common_group, common_server, common_user, notify},
manage::{
group, node, plugin,
resource::{DelReq, SetReq},
screen, server,
transfer::TransferReq,
user,
},
};

Expand Down Expand Up @@ -162,7 +161,7 @@ impl EstablishedConnection {
})
}

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

Expand Down Expand Up @@ -194,7 +193,7 @@ impl EstablishedConnection {
})
}

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

Expand Down Expand Up @@ -236,7 +235,7 @@ impl EstablishedConnection {
})
}

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

Expand Down
6 changes: 4 additions & 2 deletions cli/src/application/window/connect/tab/group/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tonic::async_trait;
use crate::application::{
network::{
connection::{task::EmptyTask, EstablishedConnection},
proto::manage::group,
proto::{common::common_group, manage::group},
},
util::{
fancy_toml::FancyToml,
Expand Down Expand Up @@ -50,7 +50,9 @@ pub struct CreateGroupTab {
impl CreateGroupTab {
/// Creates a new create group tab.
/// This function will create a window stack to get the required information to create a group.
pub fn new_stack(connection: Arc<EstablishedConnection>) -> FetchWindow<Vec<group::Short>> {
pub fn new_stack(
connection: Arc<EstablishedConnection>,
) -> FetchWindow<Vec<common_group::Short>> {
FetchWindow::new(
connection.get_groups(),
connection,
Expand Down
11 changes: 8 additions & 3 deletions cli/src/application/window/connect/tab/group/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use ratatui::{
use tonic::async_trait;

use crate::application::{
network::{connection::EstablishedConnection, proto::manage::group},
network::{
connection::EstablishedConnection,
proto::{common::common_group, manage::group},
},
util::fancy_toml::FancyToml,
window::{
connect::tab::util::{fetch::FetchWindow, select::SelectWindow},
Expand All @@ -34,7 +37,9 @@ pub struct GetGroupTab {
impl GetGroupTab {
/// Creates a new get group tab.
/// This function will create a window stack to get the required information to display the group.
pub fn new_stack(connection: Arc<EstablishedConnection>) -> FetchWindow<Vec<group::Short>> {
pub fn new_stack(
connection: Arc<EstablishedConnection>,
) -> FetchWindow<Vec<common_group::Short>> {
FetchWindow::new(
connection.get_groups(),
connection,
Expand Down Expand Up @@ -130,7 +135,7 @@ impl GetGroupTab {
}
}

impl Display for group::Short {
impl Display for common_group::Short {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
write!(formatter, "{}", self.name)
}
Expand Down
9 changes: 7 additions & 2 deletions cli/src/application/window/connect/tab/server/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use tonic::async_trait;
use crate::application::{
network::{
connection::EstablishedConnection,
proto::manage::server::{self},
proto::{
common::common_server,
manage::server::{self},
},
},
util::fancy_toml::FancyToml,
window::{
Expand All @@ -34,7 +37,9 @@ pub struct GetServerTab {
impl GetServerTab {
/// Creates a new get server tab.
/// This function will create a window stack to get the required information to display the server.
pub fn new_stack(connection: Arc<EstablishedConnection>) -> FetchWindow<Vec<server::Short>> {
pub fn new_stack(
connection: Arc<EstablishedConnection>,
) -> FetchWindow<Vec<common_server::Short>> {
FetchWindow::new(
connection.get_servers(),
connection,
Expand Down
18 changes: 10 additions & 8 deletions cli/src/application/window/connect/tab/server/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use tui_textarea::TextArea;
use crate::application::{
network::{
connection::EstablishedConnection,
proto::manage::{
screen::{self, WriteReq},
server,
proto::{
common::common_server,
manage::screen::{self, WriteReq},
},
},
util::{
Expand All @@ -41,7 +41,7 @@ use crate::application::{
pub struct ScreenTab {
/* Connection */
connection: Arc<EstablishedConnection>,
server: server::Short,
server: common_server::Short,
stream: Streaming<screen::Lines>,

/* State */
Expand All @@ -63,7 +63,9 @@ pub struct ScreenTab {
impl ScreenTab {
/// Creates a new screen tab.
/// This function will create a window stack to get the required information to display the screen.
pub fn new_stack(connection: Arc<EstablishedConnection>) -> FetchWindow<Vec<server::Short>> {
pub fn new_stack(
connection: Arc<EstablishedConnection>,
) -> FetchWindow<Vec<common_server::Short>> {
FetchWindow::new(
connection.get_servers(),
connection,
Expand All @@ -90,7 +92,7 @@ impl ScreenTab {

pub fn new(
connection: Arc<EstablishedConnection>,
server: server::Short,
server: common_server::Short,
stream: Streaming<screen::Lines>,
) -> Self {
let mut command = TextArea::default();
Expand Down Expand Up @@ -265,7 +267,7 @@ impl ScreenTab {

// Calculate the height/lines of the content area
self.update_lines(
paragraph.line_count(content_area.width), // Might be removed in the future my ratatui
paragraph.line_count(content_area.width), // Might be removed in the future by ratatui
content_area.height,
);

Expand Down Expand Up @@ -297,7 +299,7 @@ impl ScreenTab {
}
}

impl Display for server::Short {
impl Display for common_server::Short {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
write!(formatter, "{}", self.name)
}
Expand Down
14 changes: 8 additions & 6 deletions cli/src/application/window/connect/tab/user/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use tonic::async_trait;
use crate::application::{
network::{
connection::{task::EmptyTask, EstablishedConnection},
proto::manage::{
transfer::{target::Type, Target, TransferReq},
user,
proto::{
common::common_user,
manage::transfer::{target::Type, Target, TransferReq},
},
},
util::status::{Status, StatusDisplay},
Expand All @@ -42,7 +42,9 @@ pub struct TransferUserTab {
impl TransferUserTab {
/// Creates a new transfer user tab.
/// This function will create a window stack to get the required information to transfer the users.
pub fn new_stack(connection: Arc<EstablishedConnection>) -> FetchWindow<Vec<user::Item>> {
pub fn new_stack(
connection: Arc<EstablishedConnection>,
) -> FetchWindow<Vec<common_user::Item>> {
FetchWindow::new(
connection.get_users(),
connection,
Expand Down Expand Up @@ -114,7 +116,7 @@ impl TransferUserTab {
target: Option<String>,
) -> Self
where
T: IntoIterator<Item = user::Item>,
T: IntoIterator<Item = common_user::Item>,
{
Self {
request: connection.transfer_users(TransferReq {
Expand Down Expand Up @@ -205,7 +207,7 @@ impl TransferUserTab {
}
}

impl Display for user::Item {
impl Display for common_user::Item {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
write!(formatter, "{} ({})", self.name, self.id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io.atomic.cloud.api.resource.simple.SimpleCloudGroup;
import io.atomic.cloud.api.resource.simple.SimpleCloudServer;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

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

/**
* Retrieves a SimpleGroup object that matches the specified name.
*
* @param name the name of the group to retrieve
* @return a SimpleGroup instance
*/
CompletableFuture<Optional<SimpleCloudGroup>> groupFromName(String name);

/**
* Retrieves a SimpleGroup object that contains the specified user as a member.
*
* @param uuid the uuid of the user to retrieve the group for
* @return a SimpleGroup instance
*/
CompletableFuture<Optional<SimpleCloudGroup>> groupFromUser(UUID uuid);

/**
* Retrieves an array of SimpleServer objects.
*
* @return an array of SimpleServer instances
*/
CompletableFuture<SimpleCloudServer[]> servers();

/**
* Retrieves a SimpleServer object that matches the specified name.
*
* @param name the name of the server to retrieve
* @return a SimpleServer instance
*/
CompletableFuture<Optional<SimpleCloudServer>> serverFromName(String name);

/**
* Retrieves a SimpleServer object that matches the specified uuid.
*
* @param uuid the uuid of the server to retrieve
* @return a SimpleServer instance
*/
CompletableFuture<Optional<SimpleCloudServer>> serverFromUuid(UUID uuid);

/**
* Retrieves a SimpleServer object that contains the specified user as a member.
*
* @param uuid the uuid of the user to retrieve the server for
* @return a SimpleServer instance
*/
CompletableFuture<Optional<SimpleCloudServer>> serverFromUser(UUID uuid);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.atomic.cloud.api.user;

import java.util.Optional;
import java.util.UUID;

public interface CloudUser {

String name();

UUID uuid();

Optional<String> group();

Optional<UUID> server();
}
19 changes: 19 additions & 0 deletions clients/java/api/src/main/java/io/atomic/cloud/api/user/Users.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.atomic.cloud.api.user;

import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

/** The Users interface provides methods to access cloud users. */
public interface Users {

/**
Expand All @@ -10,4 +13,20 @@ public interface Users {
* @return The number of users on the network
*/
CompletableFuture<Integer> userCount();

/**
* Retrieves a User object that matches the specified name.
*
* @param name the uuid of the server to retrieve
* @return a User instance
*/
CompletableFuture<Optional<CloudUser>> userFromName(String name);

/**
* Retrieves a User object that matches the specified uuid.
*
* @param uuid the uuid of the user to retrieve
* @return a User instance
*/
CompletableFuture<Optional<CloudUser>> userFromUuid(UUID uuid);
}
Loading