Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for s3 bucket in provisioner (#668) #917

Closed
wants to merge 4 commits into from
Closed
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
22 changes: 22 additions & 0 deletions proto/provisioner.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package provisioner;
service Provisioner {
rpc ProvisionDatabase(DatabaseRequest) returns (DatabaseResponse);
rpc DeleteDatabase(DatabaseRequest) returns (DatabaseDeletionResponse);
rpc ProvisionStorage(StorageRequest) returns (StorageResponse);
rpc DeleteStorage(StorageRequest) returns (StorageDeletionResponse);
}

message DatabaseRequest {
Expand Down Expand Up @@ -42,3 +44,23 @@ message DatabaseResponse {
}

message DatabaseDeletionResponse {}

message StorageRequest {
string project_name = 1;

oneof storage_type {
Bucket Bucket = 10;
};
}

message Bucket {}

message StorageResponse {
string bucket_name = 1;
string username = 2;
string access_key = 3;
string secret_key = 4;
}


message StorageDeletionResponse {}
161 changes: 161 additions & 0 deletions proto/src/generated/provisioner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,41 @@ pub struct DatabaseResponse {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DatabaseDeletionResponse {}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct StorageRequest {
#[prost(string, tag = "1")]
pub project_name: ::prost::alloc::string::String,
#[prost(oneof = "storage_request::StorageType", tags = "10")]
pub storage_type: ::core::option::Option<storage_request::StorageType>,
}
/// Nested message and enum types in `StorageRequest`.
pub mod storage_request {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum StorageType {
#[prost(message, tag = "10")]
Bucket(super::Bucket),
}
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Bucket {}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct StorageResponse {
#[prost(string, tag = "1")]
pub bucket_name: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub username: ::prost::alloc::string::String,
#[prost(string, tag = "3")]
pub access_key: ::prost::alloc::string::String,
#[prost(string, tag = "4")]
pub secret_key: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct StorageDeletionResponse {}
/// Generated client implementations.
pub mod provisioner_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
Expand Down Expand Up @@ -184,6 +219,44 @@ pub mod provisioner_client {
);
self.inner.unary(request.into_request(), path, codec).await
}
pub async fn provision_storage(
&mut self,
request: impl tonic::IntoRequest<super::StorageRequest>,
) -> Result<tonic::Response<super::StorageResponse>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/provisioner.Provisioner/ProvisionStorage",
);
self.inner.unary(request.into_request(), path, codec).await
}
pub async fn delete_storage(
&mut self,
request: impl tonic::IntoRequest<super::StorageRequest>,
) -> Result<tonic::Response<super::StorageDeletionResponse>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/provisioner.Provisioner/DeleteStorage",
);
self.inner.unary(request.into_request(), path, codec).await
}
}
}
/// Generated server implementations.
Expand All @@ -201,6 +274,14 @@ pub mod provisioner_server {
&self,
request: tonic::Request<super::DatabaseRequest>,
) -> Result<tonic::Response<super::DatabaseDeletionResponse>, tonic::Status>;
async fn provision_storage(
&self,
request: tonic::Request<super::StorageRequest>,
) -> Result<tonic::Response<super::StorageResponse>, tonic::Status>;
async fn delete_storage(
&self,
request: tonic::Request<super::StorageRequest>,
) -> Result<tonic::Response<super::StorageDeletionResponse>, tonic::Status>;
}
#[derive(Debug)]
pub struct ProvisionerServer<T: Provisioner> {
Expand Down Expand Up @@ -341,6 +422,86 @@ pub mod provisioner_server {
};
Box::pin(fut)
}
"/provisioner.Provisioner/ProvisionStorage" => {
#[allow(non_camel_case_types)]
struct ProvisionStorageSvc<T: Provisioner>(pub Arc<T>);
impl<
T: Provisioner,
> tonic::server::UnaryService<super::StorageRequest>
for ProvisionStorageSvc<T> {
type Response = super::StorageResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::StorageRequest>,
) -> Self::Future {
let inner = self.0.clone();
let fut = async move {
(*inner).provision_storage(request).await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = ProvisionStorageSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/provisioner.Provisioner/DeleteStorage" => {
#[allow(non_camel_case_types)]
struct DeleteStorageSvc<T: Provisioner>(pub Arc<T>);
impl<
T: Provisioner,
> tonic::server::UnaryService<super::StorageRequest>
for DeleteStorageSvc<T> {
type Response = super::StorageDeletionResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::StorageRequest>,
) -> Self::Future {
let inner = self.0.clone();
let fut = async move {
(*inner).delete_storage(request).await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = DeleteStorageSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
_ => {
Box::pin(async move {
Ok(
Expand Down
4 changes: 4 additions & 0 deletions provisioner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ description = "Service responsible for provisioning and managing resources for s
publish = false

[dependencies]
aws-sdk-s3 = "0.27.0"
aws-config = "0.55.2"
aws-sdk-rds = "0.27.0"
clap = { workspace = true, features = ["env"] }
Expand All @@ -20,6 +21,9 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
tonic = { workspace = true }
tracing = { workspace = true, features = ["default"] }
tracing-subscriber = { workspace = true, features = ["default", "fmt"] }
aws-sdk-iam = "0.27.0"
uuid.workspace = true
serde_json.workspace = true

[dependencies.shuttle-common]
workspace = true
Expand Down
6 changes: 6 additions & 0 deletions provisioner/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ pub enum Error {
#[error("failed to drop role: {0}")]
DeleteRole(String),

#[error("failed to create user: {0}")]
CreateUser(String),

#[error("failed to create s3 bucket: {0}")]
CreateBucket(String),

#[error("failed to create DB: {0}")]
CreateDB(String),

Expand Down
Loading