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

Commit

Permalink
947 gateway api cli
Browse files Browse the repository at this point in the history
  • Loading branch information
senia-psm committed Nov 24, 2023
1 parent 6fd747e commit dbf8d5b
Show file tree
Hide file tree
Showing 19 changed files with 1,448 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ clap-verbosity-flag = "2.0.1"
derive_more = "0.99.17"
futures-util = "0.3.28"
golem-client = "0.0.47"
golem-gateway-client = "0.0.47"
golem-examples = "0.1.8"
http = "0.2.9"
indoc = "2.0.4"
Expand Down
1 change: 1 addition & 0 deletions src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use golem_client::model::{TokenSecret, UnsafeToken};
use crate::model::{AccountId, ProjectAction};

pub mod account;
pub mod gateway;
pub mod grant;
pub mod login;
pub mod policy;
Expand Down
6 changes: 6 additions & 0 deletions src/clients/gateway.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod certificate;
pub mod definition;
pub mod deployment;
pub mod domain;
pub mod errors;
pub mod healthcheck;
69 changes: 69 additions & 0 deletions src/clients/gateway/certificate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use async_trait::async_trait;
use golem_gateway_client::apis::api_certificate_api::{
v1_api_certificates_delete, v1_api_certificates_get, v1_api_certificates_post,
};
use golem_gateway_client::apis::configuration::Configuration;
use golem_gateway_client::models::{Certificate, CertificateRequest};
use tracing::info;

use crate::model::{GolemError, ProjectId};

#[async_trait]
pub trait CertificateClient {
async fn get(
&self,
project_id: ProjectId,
certificate_id: Option<&str>,
) -> Result<Vec<Certificate>, GolemError>;

async fn create(&self, certificate: CertificateRequest) -> Result<Certificate, GolemError>;

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

pub struct CertificateClientLive {
pub configuration: Configuration,
}

#[async_trait]
impl CertificateClient for CertificateClientLive {
async fn get(
&self,
project_id: ProjectId,
certificate_id: Option<&str>,
) -> Result<Vec<Certificate>, GolemError> {
info!("Calling v1_api_certificates_get for project_id {project_id:?}, certificate_id {certificate_id:?} on base url {}", self.configuration.base_path);
Ok(v1_api_certificates_get(
&self.configuration,
&project_id.0.to_string(),
certificate_id,
)
.await?)
}

async fn create(&self, certificate: CertificateRequest) -> Result<Certificate, GolemError> {
info!(
"Calling v1_api_certificates_post on base url {}",
self.configuration.base_path
);
Ok(v1_api_certificates_post(&self.configuration, certificate).await?)
}

async fn delete(
&self,
project_id: ProjectId,
certificate_id: &str,
) -> Result<String, GolemError> {
info!("Calling v1_api_certificates_delete for project_id {project_id:?}, certificate_id {certificate_id} on base url {}", self.configuration.base_path);
Ok(v1_api_certificates_delete(
&self.configuration,
&project_id.0.to_string(),
certificate_id,
)
.await?)
}
}
69 changes: 69 additions & 0 deletions src/clients/gateway/definition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use async_trait::async_trait;
use golem_gateway_client::apis::api_definition_api::{
v1_api_definitions_delete, v1_api_definitions_get, v1_api_definitions_put,
};
use golem_gateway_client::apis::configuration::Configuration;
use golem_gateway_client::models::ApiDefinition;
use tracing::info;

use crate::model::{GolemError, ProjectId};

#[async_trait]
pub trait DefinitionClient {
async fn get(
&self,
project_id: ProjectId,
api_definition_id: Option<&str>,
) -> Result<Vec<ApiDefinition>, GolemError>;

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

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

pub struct DefinitionClientLive {
pub configuration: Configuration,
}

#[async_trait]
impl DefinitionClient for DefinitionClientLive {
async fn get(
&self,
project_id: ProjectId,
api_definition_id: Option<&str>,
) -> Result<Vec<ApiDefinition>, GolemError> {
info!("Calling v1_api_definitions_get for project_id {project_id:?}, api_definition_id {api_definition_id:?} on base url {}", self.configuration.base_path);
Ok(v1_api_definitions_get(
&self.configuration,
&project_id.0.to_string(),
api_definition_id,
)
.await?)
}

async fn update(&self, api_definition: ApiDefinition) -> Result<ApiDefinition, GolemError> {
info!(
"Calling v1_api_definitions_put on base url {}",
self.configuration.base_path
);
Ok(v1_api_definitions_put(&self.configuration, api_definition).await?)
}

async fn delete(
&self,
project_id: ProjectId,
api_definition_id: &str,
) -> Result<String, GolemError> {
info!("Calling v1_api_definitions_delete for project_id {project_id:?}, api_definition_id {api_definition_id} on base url {}", self.configuration.base_path);
Ok(v1_api_definitions_delete(
&self.configuration,
&project_id.0.to_string(),
api_definition_id,
)
.await?)
}
}
70 changes: 70 additions & 0 deletions src/clients/gateway/deployment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use async_trait::async_trait;
use golem_gateway_client::apis::api_deployment_api::{
v1_api_deployments_delete, v1_api_deployments_get, v1_api_deployments_put,
};
use golem_gateway_client::apis::configuration::Configuration;
use golem_gateway_client::models::ApiDeployment;
use tracing::info;

use crate::model::{GolemError, ProjectId};

#[async_trait]
pub trait DeploymentClient {
async fn get(
&self,
project_id: ProjectId,
api_definition_id: &str,
) -> Result<Vec<ApiDeployment>, GolemError>;
async fn update(&self, api_deployment: ApiDeployment) -> Result<ApiDeployment, GolemError>;
async fn delete(
&self,
project_id: ProjectId,
api_definition_id: &str,
site: &str,
) -> Result<String, GolemError>;
}

pub struct DeploymentClientLive {
pub configuration: Configuration,
}

#[async_trait]
impl DeploymentClient for DeploymentClientLive {
async fn get(
&self,
project_id: ProjectId,
api_definition_id: &str,
) -> Result<Vec<ApiDeployment>, GolemError> {
info!("Calling v1_api_deployments_get for project_id {project_id:?}, api_definition_id {api_definition_id} on base url: {}", self.configuration.base_path);
Ok(v1_api_deployments_get(
&self.configuration,
&project_id.0.to_string(),
api_definition_id,
)
.await?)
}

async fn update(&self, api_deployment: ApiDeployment) -> Result<ApiDeployment, GolemError> {
info!(
"Calling v1_api_deployments_put on base url: {}",
self.configuration.base_path
);
Ok(v1_api_deployments_put(&self.configuration, api_deployment).await?)
}

async fn delete(
&self,
project_id: ProjectId,
api_definition_id: &str,
site: &str,
) -> Result<String, GolemError> {
info!("Calling v1_api_deployments_delete for project_id {project_id:?}, api_definition_id {api_definition_id}, site {site} on base url: {}", self.configuration.base_path);
Ok(v1_api_deployments_delete(
&self.configuration,
&project_id.0.to_string(),
api_definition_id,
site,
)
.await?)
}
}
61 changes: 61 additions & 0 deletions src/clients/gateway/domain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use async_trait::async_trait;
use golem_gateway_client::apis::api_domain_api::{
v1_api_domains_delete, v1_api_domains_get, v1_api_domains_put,
};
use golem_gateway_client::apis::configuration::Configuration;
use golem_gateway_client::models::{ApiDomain, DomainRequest};
use tracing::info;

use crate::model::{GolemError, ProjectId};

#[async_trait]
pub trait DomainClient {
async fn get(&self, project_id: ProjectId) -> Result<Vec<ApiDomain>, GolemError>;

async fn update(
&self,
project_id: ProjectId,
domain_name: String,
) -> Result<ApiDomain, GolemError>;

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

pub struct DomainClientLive {
pub configuration: Configuration,
}

#[async_trait]
impl DomainClient for DomainClientLive {
async fn get(&self, project_id: ProjectId) -> Result<Vec<ApiDomain>, GolemError> {
info!(
"Calling v1_api_domains_get for project_id {project_id:?} on base url {}",
self.configuration.base_path
);
Ok(v1_api_domains_get(&self.configuration, &project_id.0.to_string()).await?)
}

async fn update(
&self,
project_id: ProjectId,
domain_name: String,
) -> Result<ApiDomain, GolemError> {
info!("Calling v1_api_domains_get for project_id {project_id:?}, domain_name {domain_name} on base url {}", self.configuration.base_path);
Ok(v1_api_domains_put(
&self.configuration,
DomainRequest {
project_id: project_id.0,
domain_name,
},
)
.await?)
}

async fn delete(&self, project_id: ProjectId, domain_name: &str) -> Result<String, GolemError> {
info!("Calling v1_api_domains_get for project_id {project_id:?}, domain_name {domain_name} on base url {}", self.configuration.base_path);
Ok(
v1_api_domains_delete(&self.configuration, &project_id.0.to_string(), domain_name)
.await?,
)
}
}
Loading

0 comments on commit dbf8d5b

Please sign in to comment.