1use std::collections::HashMap;
2
3use actix_web::{web, HttpResponse, Responder};
4use serde::{Deserialize, Serialize};
5use serde_json::json;
6
7#[allow(unused)]
8pub enum BindingType {
9 Credentials,
10 LogDrain,
11 RouteServices,
12 VolumeServices,
13}
14
15#[derive(Deserialize, Debug)]
17#[allow(unused)]
18pub struct ProvisionParams {
19 pub accepts_incomplete: Option<bool>,
20}
21
22#[derive(Deserialize, Debug)]
24#[allow(unused)]
25pub struct BindingRequestBody {
26 pub service_id: String,
27 pub plan_id: String,
28 pub context: Option<HashMap<String, String>>,
29 pub bind_resource: Option<BindResource>,
30 pub parameters: Option<HashMap<String, String>>,
31}
32
33#[derive(Deserialize, Debug)]
35#[allow(unused)]
36pub struct BindResource {
37 pub app_guid: Option<String>,
38 pub route: Option<String>,
39}
40
41#[derive(Serialize, Default, Debug)]
43#[allow(unused)]
44pub struct Binding {
45 #[serde(skip_serializing_if = "Option::is_none")]
46 pub metadata: Option<BindingMetadata>,
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub credentials: Option<HashMap<String, String>>,
49 #[serde(skip_serializing_if = "Option::is_none")]
50 pub syslog_drain_url: Option<String>,
51 #[serde(skip_serializing_if = "Option::is_none")]
52 pub route_service_url: Option<String>,
53 #[serde(skip_serializing_if = "Option::is_none")]
54 pub volume_mounts: Option<VolumeMount>,
55 #[serde(skip_serializing_if = "Option::is_none")]
56 pub endpoints: Option<Vec<Endpoint>>,
57}
58
59#[derive(Serialize, Default, Debug)]
60#[allow(unused)]
61pub struct BindingMetadata {
62 pub expires_at: String,
63}
64
65#[derive(Serialize, Debug)]
66#[allow(unused)]
67pub struct VolumeMount {
68 pub driver: String,
69 pub container_dir: String,
70 pub mode: VolumeMode,
71 pub device_type: DeviceType,
72 pub device: Device,
73}
74
75#[derive(Serialize, Debug)]
76#[serde(rename_all = "lowercase")]
77#[allow(unused)]
78pub enum VolumeMode {
79 R,
80 RW,
81}
82
83#[derive(Serialize, Debug)]
84#[serde(rename_all = "snake_case")]
85#[allow(unused)]
86pub enum DeviceType {
87 Shared,
88}
89
90#[derive(Serialize, Default, Debug)]
91#[allow(unused)]
92pub struct Device {
93 pub volume_id: String,
94 pub mount_config: Option<HashMap<String, String>>,
95}
96
97#[derive(Serialize, Default, Debug)]
98#[allow(unused)]
99pub struct Endpoint {
100 pub host: String,
101 pub ports: Vec<String>,
102 pub protocol: Option<Protocol>,
103}
104
105#[derive(Serialize, Debug)]
106#[serde(rename_all = "lowercase")]
107#[allow(unused)]
108pub enum Protocol {
109 TCP,
110 UDP,
111 All,
112}
113
114impl Default for Protocol {
115 fn default() -> Self {
116 Protocol::TCP
117 }
118}
119
120pub async fn put_binding(
121 web::Path((_instance_id, _binding_id)): web::Path<(String, String)>,
122 web::Query(params): web::Query<ProvisionParams>,
123 web::Json(body): web::Json<BindingRequestBody>,
124) -> impl Responder {
125 log::info!("params {:?}, body:\n{:#?}", params, body);
126
127 HttpResponse::Created().json(Binding::default())
128}
129
130#[derive(Deserialize, Debug)]
132#[allow(unused)]
133pub struct BindingFetchParams {
134 pub service: Option<String>,
135 pub plan_id: Option<String>,
136}
137
138pub async fn get_binding(
139 web::Path((_instance_id, _binding_id)): web::Path<(String, String)>,
140 web::Query(params): web::Query<BindingFetchParams>,
141) -> impl Responder {
142 log::info!("params {:?}", params);
143
144 HttpResponse::Ok().json(Binding::default())
145}
146
147pub async fn delete_binding(
148 web::Path((_instance_id, _binding_id)): web::Path<(String, String)>,
149 web::Query(params): web::Query<BindingFetchParams>,
150) -> impl Responder {
151 log::info!("params {:?}", params);
152
153 HttpResponse::Ok().json(json!({}))
154}