1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use actix_web::{web, HttpResponse, Responder};
use serde::{Deserialize, Serialize};

/// <https://github.com/openservicebrokerapi/servicebroker/blob/v2.16/spec.md#request-1>
#[derive(Deserialize, Debug)]
#[allow(unused)]
pub struct LastOperationParams {
    pub service_id: Option<String>,
    pub plan_id: Option<String>,
    pub operation: Option<String>,
}

/// <https://github.com/openservicebrokerapi/servicebroker/blob/v2.16/spec.md#response-1>
#[derive(Serialize, Default, Debug)]
pub struct ServiceInstanceLastOp {
    pub state: LastOperationState,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub instance_usable: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub update_repeatable: Option<bool>,
}

#[derive(Serialize, Debug)]
#[serde(rename_all = "lowercase")]
#[allow(unused)]
pub enum LastOperationState {
    #[serde(rename(serialize = "in progress"))]
    InProgress,
    Succeeded,
    Failed,
}

impl Default for LastOperationState {
    fn default() -> Self {
        LastOperationState::InProgress
    }
}

pub async fn get_service_instance_last_operation(
    _instance_id: web::Path<String>,
    web::Query(params): web::Query<LastOperationParams>,
) -> impl Responder {
    log::info!("params {:?}", params);

    let mut response = ServiceInstanceLastOp::default();
    response.state = LastOperationState::Succeeded;

    HttpResponse::Ok().json(response)
}

/// <https://github.com/openservicebrokerapi/servicebroker/blob/v2.16/spec.md#response-2>
#[derive(Serialize, Default, Debug)]
struct ServiceBindingLastOp {
    pub state: LastOperationState,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
}

pub async fn get_service_binding_state(
    web::Path((_instance_id, _binding_id)): web::Path<(String, String)>,
    web::Query(params): web::Query<LastOperationParams>,
) -> impl Responder {
    log::info!("params {:?}", params);

    let mut response = ServiceBindingLastOp::default();
    response.state = LastOperationState::Succeeded;

    HttpResponse::Ok().json(response)
}