Skip to content

Commit

Permalink
Remove unused structs supporting v2 Capella API
Browse files Browse the repository at this point in the history
  • Loading branch information
Westwooo committed Aug 13, 2024
1 parent 937f074 commit ca530c0
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 261 deletions.
2 changes: 1 addition & 1 deletion src/cli/buckets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub fn get_capella_buckets(
)?;

let buckets = client
.get_buckets(org_id, project_id, json_cluster.id(), deadline, ctrl_c)
.list_buckets(org_id, project_id, json_cluster.id(), deadline, ctrl_c)
.map_err(|e| client_error_to_shell_error(e, span))?;
let mut buckets_settings: Vec<BucketSettings> = vec![];
for bucket in buckets.items() {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/clusters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn clusters(
)?;

let clusters = client
.get_clusters(org_id, project_id, deadline, ctrl_c)
.list_clusters(org_id, project_id, deadline, ctrl_c)
.map_err(|e| client_error_to_shell_error(e, span))?;

let mut results = vec![];
Expand Down
2 changes: 1 addition & 1 deletion src/cli/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn organizations(

let deadline = Instant::now().add(org.timeout());
let orgs = client
.get_organizations(deadline, ctrl_c.clone())
.list_organizations(deadline, ctrl_c.clone())
.map_err(|e| client_error_to_shell_error(e, span))?;

for org in orgs.items() {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn projects(
let org_id = find_org_id(ctrl_c.clone(), &client, deadline, span)?;

let projects = client
.get_projects(org_id, deadline, ctrl_c)
.list_projects(org_id, deadline, ctrl_c)
.map_err(|e| client_error_to_shell_error(e, span))?;

let mut results = vec![];
Expand Down
52 changes: 17 additions & 35 deletions src/cli/util.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use crate::cli::error::CBShellError::{
MustNotBeCapella, ProjectNotFound, UnexpectedResponseStatus,
};
use crate::cli::error::CBShellError::{MustNotBeCapella, ProjectNotFound};
use crate::cli::error::{
client_error_to_shell_error, cluster_not_found_error, deserialize_error,
malformed_response_error, no_active_bucket_error, unexpected_status_code_error,
client_error_to_shell_error, cluster_not_found_error, malformed_response_error,
no_active_bucket_error, unexpected_status_code_error,
};
use crate::cli::generic_error;
use crate::cli::CBShellError::ClusterNotFound;
use crate::client::cloud_json::{Cluster, OrganizationsResponse, ProjectsResponse};
use crate::client::{CapellaClient, CapellaRequest, HttpResponse};
use crate::client::cloud_json::Cluster;
use crate::client::{CapellaClient, HttpResponse};
use crate::state::State;
use crate::{read_input, RemoteCluster, RemoteClusterType};
use nu_engine::CallExt;
Expand Down Expand Up @@ -307,7 +305,7 @@ pub(crate) fn cluster_from_conn_str(
project_id: String,
) -> Result<Cluster, ShellError> {
let response = client
.get_clusters(org_id, project_id, deadline, ctrl_c)
.list_clusters(org_id, project_id, deadline, ctrl_c)
.map_err(|e| client_error_to_shell_error(e, span))?;

for c in response.items() {
Expand All @@ -329,21 +327,11 @@ pub(crate) fn find_project_id(
span: Span,
org_id: String,
) -> Result<String, ShellError> {
let response = client
.capella_request(CapellaRequest::GetProjects { org_id }, deadline, ctrl_c)
let projects = client
.list_projects(org_id, deadline, ctrl_c)
.map_err(|e| client_error_to_shell_error(e, span))?;
if response.status() != 200 {
return Err(UnexpectedResponseStatus {
status_code: response.status(),
message: response.content().to_string(),
span,
}
.into());
}
let content: ProjectsResponse = serde_json::from_str(response.content())
.map_err(|e| deserialize_error(e.to_string(), span))?;

for p in content.items() {
for p in projects.items() {
if p.name() == name.clone() {
return Ok(p.id().to_string());
}
Expand All @@ -358,22 +346,16 @@ pub(crate) fn find_org_id(
deadline: Instant,
span: Span,
) -> Result<String, ShellError> {
let response = client
.capella_request(CapellaRequest::GetOrganizations {}, deadline, ctrl_c)
let orgs = client
.list_organizations(deadline, ctrl_c.clone())
.map_err(|e| client_error_to_shell_error(e, span))?;
if response.status() != 200 {
return Err(UnexpectedResponseStatus {
status_code: response.status(),
message: response.content().to_string(),
span,
}
.into());
}
let content: OrganizationsResponse = serde_json::from_str(response.content())
.map_err(|e| deserialize_error(e.to_string(), span))?;

let org = content.items().first().unwrap().id();
Ok(org.to_string())
let org_id = match orgs.items().first() {
Some(org) => org.id(),
None => return Err(generic_error("No organizations in response", None, None)),
};

Ok(org_id.to_string())
}

// duration_to_golang_string creates a golang formatted string to use with timeouts. Unlike Golang
Expand Down
Loading

0 comments on commit ca530c0

Please sign in to comment.