Skip to content
Open
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
19 changes: 19 additions & 0 deletions crates/clickhouse-cloud-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,25 @@ more pages remain and `ApiResponse::limit` echoes the page size. Migrate
the request sent is unchanged, but an organization with more than 250 roles
now needs to follow `next_cursor` to see them all.

The beta Postgres private endpoint methods are `postgres_private_endpoint_get`,
`postgres_private_endpoint_post`, `postgres_private_endpoint_patch` and
`postgres_private_endpoint_delete`. They manage the AWS private endpoint
service of a Postgres service, available only for AWS services in
organizations with the feature enabled. Reads, create and patch return
`PostgresPrivateEndpoint` (state, endpoint service name and ID, private
hostname and DNS name, ports, supported regions and approved VPC endpoints);
get returns `Error::Api { status: 404, .. }` before one is created, and
delete returns no `result`. Create takes `PostgresPrivateEndpointPostRequest`
(optional `supported_regions`) and stays `creating` for about 5 to 10
minutes. Patch takes `PostgresPrivateEndpointPatchRequest`: each list set
(`allowed_vpc_endpoints`, `supported_regions`) replaces the existing one in
full. An approved endpoint is `PostgresPrivateEndpointVpcEndpoint` (required
`vpc_endpoint_id`, optional `description`) in requests and
`PostgresPrivateEndpointVpcEndpointResponse` in responses, with `TryFrom`
from the response type for writing a fetched list back. Get needs
`control-plane:postgres-service:view`; the others need
`control-plane:postgres-service:manage`.

## 0.5.1

No changes to this crate; released in lockstep with `clickhousectl` 0.5.1.
Expand Down
124 changes: 124 additions & 0 deletions crates/clickhouse-cloud-api/src/client/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,130 @@ impl Client {
Ok(serde_json::from_str(&body_text)?)
}

/// Get the AWS private endpoint service of a Postgres service (Beta).
///
/// Returns `Error::Api { status: 404, .. }` if it has not been created.
/// Private endpoints are available only for AWS Postgres services, and only
/// for organizations with the feature enabled.
pub async fn postgres_private_endpoint_get(
&self,
organization_id: &str,
postgres_id: &str,
) -> Result<ApiResponse<PostgresPrivateEndpoint>, Error> {
let req = self.request(
&operations::POSTGRES_PRIVATE_ENDPOINT_GET,
&[organization_id, postgres_id],
)?;
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}

/// Create the AWS private endpoint service of a Postgres service (Beta).
///
/// Creation takes about 5 to 10 minutes: `state` is `creating` until it is
/// `available`. A VPC endpoint can connect only after its ID is approved with
/// [`Client::postgres_private_endpoint_patch`].
/// Private endpoints are available only for AWS Postgres services, and only
/// for organizations with the feature enabled.
pub async fn postgres_private_endpoint_post(
&self,
organization_id: &str,
postgres_id: &str,
body: &PostgresPrivateEndpointPostRequest,
) -> Result<ApiResponse<PostgresPrivateEndpoint>, Error> {
let mut req = self.request(
&operations::POSTGRES_PRIVATE_ENDPOINT_POST,
&[organization_id, postgres_id],
)?;
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}

/// Approve VPC endpoints and set the supported regions of a Postgres private
/// endpoint service (Beta).
///
/// Set at least one field of `body`; each one set replaces that list in full.
/// Private endpoints are available only for AWS Postgres services, and only
/// for organizations with the feature enabled.
pub async fn postgres_private_endpoint_patch(
&self,
organization_id: &str,
postgres_id: &str,
body: &PostgresPrivateEndpointPatchRequest,
) -> Result<ApiResponse<PostgresPrivateEndpoint>, Error> {
let mut req = self.request(
&operations::POSTGRES_PRIVATE_ENDPOINT_PATCH,
&[organization_id, postgres_id],
)?;
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}

/// Delete the AWS private endpoint service of a Postgres service (Beta).
///
/// Connections through approved VPC endpoints stop working. The response
/// carries no `result`.
/// Private endpoints are available only for AWS Postgres services, and only
/// for organizations with the feature enabled.
pub async fn postgres_private_endpoint_delete(
&self,
organization_id: &str,
postgres_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let req = self.request(
&operations::POSTGRES_PRIVATE_ENDPOINT_DELETE,
&[organization_id, postgres_id],
)?;
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}

/// Update Postgres superuser password
pub async fn postgres_service_set_password(
&self,
Expand Down
19 changes: 19 additions & 0 deletions crates/clickhouse-cloud-api/src/convert/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,22 @@ impl TryFrom<PostgresIpAccessListEntryResponse> for PostgresIpAccessListEntry {
}
}
}

impl TryFrom<PostgresPrivateEndpointVpcEndpointResponse> for PostgresPrivateEndpointVpcEndpoint {
type Error = MissingRequiredFields;

/// Turns a fetched approved VPC endpoint into one that can be sent back.
///
/// The patch replaces the approved list in full, so a caller that adds or
/// removes one endpoint writes back every other entry it read. An entry
/// without `vpcEndpointId` cannot be written back.
fn try_from(value: PostgresPrivateEndpointVpcEndpointResponse) -> Result<Self, Self::Error> {
match value.vpc_endpoint_id {
Some(vpc_endpoint_id) => Ok(Self {
description: value.description,
vpc_endpoint_id,
}),
None => Err(MissingRequiredFields::new(vec!["vpcEndpointId"])),
}
}
}
4 changes: 4 additions & 0 deletions crates/clickhouse-cloud-api/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ pub const BETA_OPERATIONS: &[&str] = &[
"organization_public_previews_get_list",
"organization_quota_get",
"organization_quotas_get_list",
"postgres_private_endpoint_delete",
"postgres_private_endpoint_get",
"postgres_private_endpoint_patch",
"postgres_private_endpoint_post",
"postgres_service_create",
"replica_aware_routing_get",
"replica_aware_routing_update",
Expand Down
40 changes: 40 additions & 0 deletions crates/clickhouse-cloud-api/src/meta/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,42 @@ pub const POSTGRES_ORG_PROMETHEUS_GET: OperationMetadata = OperationMetadata {
required_permissions: &["control-plane:organization:view"],
};

/// `DELETE /v1/organizations/{organizationId}/postgres/{postgresId}/privateEndpoint` (`postgresPrivateEndpointDelete`).
pub const POSTGRES_PRIVATE_ENDPOINT_DELETE: OperationMetadata = OperationMetadata {
operation_id: "postgresPrivateEndpointDelete",
rust_method: "postgres_private_endpoint_delete",
method: "DELETE",
path: "/v1/organizations/{organizationId}/postgres/{postgresId}/privateEndpoint",
required_permissions: &["control-plane:postgres-service:manage"],
};

/// `GET /v1/organizations/{organizationId}/postgres/{postgresId}/privateEndpoint` (`postgresPrivateEndpointGet`).
pub const POSTGRES_PRIVATE_ENDPOINT_GET: OperationMetadata = OperationMetadata {
operation_id: "postgresPrivateEndpointGet",
rust_method: "postgres_private_endpoint_get",
method: "GET",
path: "/v1/organizations/{organizationId}/postgres/{postgresId}/privateEndpoint",
required_permissions: &["control-plane:postgres-service:view"],
};

/// `PATCH /v1/organizations/{organizationId}/postgres/{postgresId}/privateEndpoint` (`postgresPrivateEndpointPatch`).
pub const POSTGRES_PRIVATE_ENDPOINT_PATCH: OperationMetadata = OperationMetadata {
operation_id: "postgresPrivateEndpointPatch",
rust_method: "postgres_private_endpoint_patch",
method: "PATCH",
path: "/v1/organizations/{organizationId}/postgres/{postgresId}/privateEndpoint",
required_permissions: &["control-plane:postgres-service:manage"],
};

/// `POST /v1/organizations/{organizationId}/postgres/{postgresId}/privateEndpoint` (`postgresPrivateEndpointPost`).
pub const POSTGRES_PRIVATE_ENDPOINT_POST: OperationMetadata = OperationMetadata {
operation_id: "postgresPrivateEndpointPost",
rust_method: "postgres_private_endpoint_post",
method: "POST",
path: "/v1/organizations/{organizationId}/postgres/{postgresId}/privateEndpoint",
required_permissions: &["control-plane:postgres-service:manage"],
};

/// `GET /v1/organizations/{organizationId}/postgres/{postgresId}/backups` (`postgresServiceBackupGetList`).
pub const POSTGRES_SERVICE_BACKUP_GET_LIST: OperationMetadata = OperationMetadata {
operation_id: "postgresServiceBackupGetList",
Expand Down Expand Up @@ -1814,6 +1850,10 @@ pub const ALL: &[OperationMetadata] = &[
POSTGRES_INSTANCE_RESTORE,
POSTGRES_LOGS_GET_LIST,
POSTGRES_ORG_PROMETHEUS_GET,
POSTGRES_PRIVATE_ENDPOINT_DELETE,
POSTGRES_PRIVATE_ENDPOINT_GET,
POSTGRES_PRIVATE_ENDPOINT_PATCH,
POSTGRES_PRIVATE_ENDPOINT_POST,
POSTGRES_SERVICE_BACKUP_GET_LIST,
POSTGRES_SERVICE_CERTS_GET,
POSTGRES_SERVICE_CREATE,
Expand Down
5 changes: 4 additions & 1 deletion crates/clickhouse-cloud-api/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ pub use postgres::{
PostgresIpAccessListEntry, PostgresIpAccessListEntryResponse, PostgresIpAccessListPatch,
PostgresIpAccessListRuleReference, PostgresLogEntry, PostgresLogsGetListSeverity,
PostgresLogsGetListSortorder, PostgresMetric, PostgresMetricDataPoint, PostgresMetricSeries,
PostgresMetrics, PostgresQueryExecution, PostgresService, PostgresServiceListItem,
PostgresMetrics, PostgresPrivateEndpoint, PostgresPrivateEndpointPatchRequest,
PostgresPrivateEndpointPort, PostgresPrivateEndpointPostRequest,
PostgresPrivateEndpointVpcEndpoint, PostgresPrivateEndpointVpcEndpointResponse,
PostgresQueryExecution, PostgresService, PostgresServiceListItem,
PostgresServicePasswordResource, PostgresServicePatchRequest, PostgresServicePostRequest,
PostgresServiceReadReplicaRequest, PostgresServiceRestoreRequest, PostgresServiceSetPassword,
PostgresServiceSetState, PostgresServiceSetStateCommand, PostgresSlowQueryPattern,
Expand Down
119 changes: 119 additions & 0 deletions crates/clickhouse-cloud-api/src/models/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2038,3 +2038,122 @@ pub struct PostgresBackup {
#[serde(rename = "status", skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
}

/// `PostgresPrivateEndpoint` from the ClickHouse Cloud API: the AWS private
/// endpoint service of a Postgres service.
///
/// Used in response position only: every field is `Option<T>`, so a field the
/// API drops or sends as `null` deserializes as `None`.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct PostgresPrivateEndpoint {
/// VPC endpoints approved to connect.
#[serde(
rename = "allowedVpcEndpoints",
skip_serializing_if = "Option::is_none"
)]
pub allowed_vpc_endpoints: Option<Vec<PostgresPrivateEndpointVpcEndpointResponse>>,
/// ID of the AWS endpoint service. Absent until the service is created.
#[serde(rename = "endpointServiceId", skip_serializing_if = "Option::is_none")]
pub endpoint_service_id: Option<String>,
/// Name of the AWS endpoint service: the service name to use when creating
/// a VPC endpoint. Absent until the service is created.
#[serde(
rename = "endpointServiceName",
skip_serializing_if = "Option::is_none"
)]
pub endpoint_service_name: Option<String>,
/// ID of the private endpoint service.
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// IP address type of the endpoint service, such as `dual`.
#[serde(rename = "ipAddressType", skip_serializing_if = "Option::is_none")]
pub ip_address_type: Option<String>,
/// Ports the endpoint service forwards.
#[serde(skip_serializing_if = "Option::is_none")]
pub ports: Option<Vec<PostgresPrivateEndpointPort>>,
/// Private DNS name of the endpoint service. Absent until it is assigned.
#[serde(rename = "privateDnsName", skip_serializing_if = "Option::is_none")]
pub private_dns_name: Option<String>,
/// Verification state of the private DNS name. Absent until it is assigned.
#[serde(
rename = "privateDnsVerificationState",
skip_serializing_if = "Option::is_none"
)]
pub private_dns_verification_state: Option<String>,
/// Hostname that resolves to the Postgres service from an approved VPC
/// endpoint. Absent until the service is available.
#[serde(rename = "privateHostname", skip_serializing_if = "Option::is_none")]
pub private_hostname: Option<String>,
/// `creating`, `available` or `deleting`; the API may add more states. It
/// is `creating` for about 5 to 10 minutes after creation.
#[serde(skip_serializing_if = "Option::is_none")]
pub state: Option<String>,
/// AWS region IDs, other than the service region, from which VPC endpoints
/// can connect.
#[serde(rename = "supportedRegions", skip_serializing_if = "Option::is_none")]
pub supported_regions: Option<Vec<String>>,
}

/// `PostgresPrivateEndpointPort` from the ClickHouse Cloud API: one port the
/// endpoint service forwards. Used in response position only.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct PostgresPrivateEndpointPort {
/// Port exposed by the endpoint service.
#[serde(skip_serializing_if = "Option::is_none")]
pub port: Option<i64>,
/// Port on the Postgres service it forwards to.
#[serde(rename = "targetPort", skip_serializing_if = "Option::is_none")]
pub target_port: Option<i64>,
}

/// `PostgresPrivateEndpointVpcEndpoint` from the ClickHouse Cloud API: one VPC
/// endpoint approved to connect, as sent in
/// [`PostgresPrivateEndpointPatchRequest`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PostgresPrivateEndpointVpcEndpoint {
/// Optional description, at most 255 characters.
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// ID of the AWS VPC endpoint, such as `vpce-0123456789abcdef0`.
#[serde(rename = "vpcEndpointId")]
pub vpc_endpoint_id: String,
}

/// `PostgresPrivateEndpointVpcEndpoint` in response position: one approved VPC
/// endpoint of [`PostgresPrivateEndpoint`]. Every field is `Option<T>`.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct PostgresPrivateEndpointVpcEndpointResponse {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(rename = "vpcEndpointId", skip_serializing_if = "Option::is_none")]
pub vpc_endpoint_id: Option<String>,
}

/// `PostgresPrivateEndpointPostRequest` from the ClickHouse Cloud API: the body
/// that creates a Postgres private endpoint service.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct PostgresPrivateEndpointPostRequest {
/// AWS region IDs, other than the service region, from which VPC endpoints
/// can connect, such as `us-west-2`. Requires cross-region private
/// endpoints to be enabled for the organization.
#[serde(rename = "supportedRegions", skip_serializing_if = "Option::is_none")]
pub supported_regions: Option<Vec<String>>,
}

/// `PostgresPrivateEndpointPatchRequest` from the ClickHouse Cloud API.
///
/// Set at least one field. Each one set replaces the existing list in full, so
/// include every entry to keep; `None` leaves that list unchanged.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct PostgresPrivateEndpointPatchRequest {
/// Every VPC endpoint approved to connect, at most 50, each ID once.
/// Endpoints not listed can no longer connect.
#[serde(
rename = "allowedVpcEndpoints",
skip_serializing_if = "Option::is_none"
)]
pub allowed_vpc_endpoints: Option<Vec<PostgresPrivateEndpointVpcEndpoint>>,
/// Every supported region, other than the service region.
#[serde(rename = "supportedRegions", skip_serializing_if = "Option::is_none")]
pub supported_regions: Option<Vec<String>>,
}
Loading
Loading