Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Fix CLI for the new API
Browse files Browse the repository at this point in the history
  • Loading branch information
afsalthaj committed Mar 20, 2024
1 parent e1978fa commit 7d9f714
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
10 changes: 6 additions & 4 deletions src/clients/gateway/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ pub trait DefinitionClient {
api_definition_id: Option<&str>,
) -> Result<Vec<ApiDefinition>, GolemError>;

async fn update(&self, api_definition: ApiDefinition) -> Result<ApiDefinition, GolemError>;
async fn update(&self, project_id: ProjectId, api_definition: ApiDefinition) -> Result<ApiDefinition, GolemError>;

async fn delete(
&self,
project_id: ProjectId,
api_definition_id: &str,
version: &str
) -> Result<String, GolemError>;
}

Expand All @@ -50,15 +51,16 @@ impl<C: golem_gateway_client::api::ApiDefinitionClient + Sync + Send> Definition
Ok(self.client.get(&project_id.0, api_definition_id).await?)
}

async fn update(&self, api_definition: ApiDefinition) -> Result<ApiDefinition, GolemError> {
Ok(self.client.put(&api_definition).await?)
async fn update(&self, project_id: ProjectId, api_definition: ApiDefinition) -> Result<ApiDefinition, GolemError> {
Ok(self.client.put(&project_id.0, &api_definition).await?)
}

async fn delete(
&self,
project_id: ProjectId,
api_definition_id: &str,
version: &str
) -> Result<String, GolemError> {
Ok(self.client.delete(&project_id.0, api_definition_id).await?)
Ok(self.client.delete(&project_id.0, api_definition_id, version).await?)
}
}
4 changes: 2 additions & 2 deletions src/clients/gateway/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use golem_gateway_client::api::{
ApiCertificateError, ApiDefinitionError, ApiDeploymentError, ApiDomainError, HealthcheckError,
ApiCertificateError, ApiDefinitionError, ApiDeploymentError, ApiDomainError, HealthCheckError,
};

pub trait ResponseContentErrorMapper {
Expand Down Expand Up @@ -120,7 +120,7 @@ impl ResponseContentErrorMapper for ApiDomainError {
}
}

impl ResponseContentErrorMapper for HealthcheckError {
impl ResponseContentErrorMapper for HealthCheckError {
fn map(self) -> String {
match self {}
}
Expand Down
6 changes: 3 additions & 3 deletions src/clients/gateway/healthcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ pub trait HealthcheckClient {
async fn healthcheck(&self) -> Result<(), GolemError>;
}

pub struct HealthcheckClientLive<C: golem_gateway_client::api::HealthcheckClient + Sync + Send> {
pub struct HealthcheckClientLive<C: golem_gateway_client::api::HealthCheckClient + Sync + Send> {
pub client: C,
}

#[async_trait]
impl<C: golem_gateway_client::api::HealthcheckClient + Sync + Send> HealthcheckClient
impl<C: golem_gateway_client::api::HealthCheckClient + Sync + Send> HealthcheckClient
for HealthcheckClientLive<C>
{
async fn healthcheck(&self) -> Result<(), GolemError> {
self.client.healthcheck_get().await?;
self.client.healthcheck().await?;
Ok(())
}
}
2 changes: 1 addition & 1 deletion src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<'p, P: ProjectClient + Sync + Send> GatewayHandler for GatewayHandlerLive<'
};

let healthcheck_client = HealthcheckClientLive {
client: golem_gateway_client::api::HealthcheckClientLive {
client: golem_gateway_client::api::HealthCheckClientLive {
context: context.clone(),
},
};
Expand Down
13 changes: 10 additions & 3 deletions src/gateway/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub enum DefinitionSubcommand {
},
#[command()]
Update {
#[command(flatten)]
project_ref: ProjectRef,
#[arg(value_name = "definition-file", value_hint = clap::ValueHint::FilePath)]
definition_file: Option<PathBufOrStdin>,
},
Expand All @@ -45,6 +47,8 @@ pub enum DefinitionSubcommand {
project_ref: ProjectRef,
#[arg(value_name = "api-definition-id", value_hint = clap::ValueHint::Other)]
definition_id: String,
#[arg(value_name = "version", value_hint = clap::ValueHint::Other)]
version: String
},
}

Expand Down Expand Up @@ -110,7 +114,9 @@ impl<'p, C: DefinitionClient + Sync + Send, P: ProjectClient + Sync + Send> Defi

Ok(GolemResult::Ok(Box::new(res)))
}
DefinitionSubcommand::Update { definition_file } => {
DefinitionSubcommand::Update { project_ref, definition_file } => {
let project_id = self.projects.resolve_id_or_default(project_ref).await?;

let definition = match definition_file.unwrap_or(PathBufOrStdin::Stdin) {
PathBufOrStdin::Path(path) => {
let file = File::open(&path).map_err(|e| {
Expand All @@ -124,16 +130,17 @@ impl<'p, C: DefinitionClient + Sync + Send, P: ProjectClient + Sync + Send> Defi
PathBufOrStdin::Stdin => read_definition(format, io::stdin(), "stdin")?,
};

let res = self.client.update(definition).await?;
let res = self.client.update(project_id, definition).await?;

Ok(GolemResult::Ok(Box::new(res)))
}
DefinitionSubcommand::Delete {
project_ref,
definition_id,
version
} => {
let project_id = self.projects.resolve_id_or_default(project_ref).await?;
let res = self.client.delete(project_id, &definition_id).await?;
let res = self.client.delete(project_id, &definition_id, version.as_str()).await?;
Ok(GolemResult::Ok(Box::new(res)))
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/gateway/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub enum DeploymentSubcommand {
project_ref: ProjectRef,
#[arg(short, long, value_name = "api-definition-id", value_hint = clap::ValueHint::Other)]
definition_id: String,
#[arg(short = 'V', long, value_name = "version", value_hint = clap::ValueHint::Other)]
version: String,
#[arg(short = 'H', long, value_name = "site-host", value_hint = clap::ValueHint::Other)]
host: String,
#[arg(short, long, value_name = "site-subdomain", value_hint = clap::ValueHint::Other)]
Expand Down Expand Up @@ -83,12 +85,14 @@ impl<'p, C: DeploymentClient + Sync + Send, P: ProjectClient + Sync + Send> Depl
}
DeploymentSubcommand::Add {
project_ref,
version,
definition_id,
host,
subdomain,
} => {
let deployment = ApiDeployment {
project_id: self.projects.resolve_id_or_default(project_ref).await?.0,
version,
api_definition_id: definition_id,
site: ApiSite { host, subdomain },
};
Expand Down

0 comments on commit 7d9f714

Please sign in to comment.