Skip to content

Commit a4c8f44

Browse files
committed
Add ServiceControl V1 API
Signed-off-by: Igor Pashev <pashev.igor@gmail.com>
1 parent 2fc3a0b commit a4c8f44

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+5104
-5
lines changed

gcloud-protos-generator/openapi/google/servicecontrol-v1/openapi.yaml

Lines changed: 1605 additions & 0 deletions
Large diffs are not rendered by default.

gcloud-sdk/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,12 @@ maps-fleetengine-v1 = []
425425

426426
# REST features
427427
google-rest-bigquery-v2 = ["rest"]
428+
google-rest-compute-v1 = ["rest"]
429+
google-rest-dns-v1 = ["rest"]
428430
google-rest-lustre-v1alpha = ["rest"]
429-
google-rest-storage-v1 = ["rest"]
430431
google-rest-sqladmin-v1 = ["rest"]
431-
google-rest-dns-v1 = ["rest"]
432-
google-rest-compute-v1 = ["rest"]
432+
google-rest-storage-v1 = ["rest"]
433+
google-rest-servicecontrol-v1 = ["rest"]
433434

434435
[dependencies]
435436
tonic = { version = "0.12", features = ["tls"] }

gcloud-sdk/src/rest_apis/google_rest_apis/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ pub mod bigquery_v2;
44
#[cfg(any(feature = "google-rest-compute-v1"))]
55
pub mod compute_v1;
66

7+
#[cfg(any(feature = "google-rest-dns-v1"))]
8+
pub mod dns_v1;
9+
710
#[cfg(any(feature = "google-rest-lustre-v1alpha"))]
811
pub mod lustre_v1alpha;
912

10-
#[cfg(any(feature = "google-rest-dns-v1"))]
11-
pub mod dns_v1;
13+
#[cfg(any(feature = "google-rest-servicecontrol-v1"))]
14+
pub mod servicecontrol_v1;
1215

1316
#[cfg(any(feature = "google-rest-sqladmin-v1"))]
1417
pub mod sqladmin_v1;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use serde::{Deserialize, Serialize}; /*
2+
* Service Control API
3+
*
4+
* Provides admission control and telemetry reporting for services integrated with Service Infrastructure.
5+
*
6+
* The version of the OpenAPI document: v1
7+
*
8+
* Generated by: https://openapi-generator.tech
9+
*/
10+
11+
#[derive(Debug, Clone)]
12+
pub struct Configuration {
13+
pub base_path: String,
14+
pub user_agent: Option<String>,
15+
pub client: reqwest::Client,
16+
pub basic_auth: Option<BasicAuth>,
17+
pub oauth_access_token: Option<String>,
18+
pub bearer_access_token: Option<String>,
19+
pub api_key: Option<ApiKey>,
20+
// TODO: take an oauth2 token source, similar to the go one
21+
}
22+
23+
pub type BasicAuth = (String, Option<String>);
24+
25+
#[derive(Debug, Clone)]
26+
pub struct ApiKey {
27+
pub prefix: Option<String>,
28+
pub key: String,
29+
}
30+
31+
impl Configuration {
32+
pub fn new() -> Configuration {
33+
Configuration::default()
34+
}
35+
}
36+
37+
impl Default for Configuration {
38+
fn default() -> Self {
39+
Configuration {
40+
base_path: "https://servicecontrol.googleapis.com".to_owned(),
41+
user_agent: Some("OpenAPI-Generator/v1/rust".to_owned()),
42+
client: reqwest::Client::new(),
43+
basic_auth: None,
44+
oauth_access_token: None,
45+
bearer_access_token: None,
46+
api_key: None,
47+
}
48+
}
49+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
use serde::{Deserialize, Serialize};
2+
use std::error;
3+
use std::fmt;
4+
5+
#[derive(Debug, Clone)]
6+
pub struct ResponseContent<T> {
7+
pub status: reqwest::StatusCode,
8+
pub content: String,
9+
pub entity: Option<T>,
10+
}
11+
12+
#[derive(Debug)]
13+
pub enum Error<T> {
14+
Reqwest(reqwest::Error),
15+
Serde(serde_json::Error),
16+
Io(std::io::Error),
17+
ResponseError(ResponseContent<T>),
18+
}
19+
20+
impl<T> fmt::Display for Error<T> {
21+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22+
let (module, e) = match self {
23+
Error::Reqwest(e) => ("reqwest", e.to_string()),
24+
Error::Serde(e) => ("serde", e.to_string()),
25+
Error::Io(e) => ("IO", e.to_string()),
26+
Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
27+
};
28+
write!(f, "error in {}: {}", module, e)
29+
}
30+
}
31+
32+
impl<T: fmt::Debug> error::Error for Error<T> {
33+
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
34+
Some(match self {
35+
Error::Reqwest(e) => e,
36+
Error::Serde(e) => e,
37+
Error::Io(e) => e,
38+
Error::ResponseError(_) => return None,
39+
})
40+
}
41+
}
42+
43+
impl<T> From<reqwest::Error> for Error<T> {
44+
fn from(e: reqwest::Error) -> Self {
45+
Error::Reqwest(e)
46+
}
47+
}
48+
49+
impl<T> From<serde_json::Error> for Error<T> {
50+
fn from(e: serde_json::Error) -> Self {
51+
Error::Serde(e)
52+
}
53+
}
54+
55+
impl<T> From<std::io::Error> for Error<T> {
56+
fn from(e: std::io::Error) -> Self {
57+
Error::Io(e)
58+
}
59+
}
60+
61+
pub fn urlencode<T: AsRef<str>>(s: T) -> String {
62+
::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
63+
}
64+
65+
pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> {
66+
if let serde_json::Value::Object(object) = value {
67+
let mut params = vec![];
68+
69+
for (key, value) in object {
70+
match value {
71+
serde_json::Value::Object(_) => params.append(&mut parse_deep_object(
72+
&format!("{}[{}]", prefix, key),
73+
value,
74+
)),
75+
serde_json::Value::Array(array) => {
76+
for (i, value) in array.iter().enumerate() {
77+
params.append(&mut parse_deep_object(
78+
&format!("{}[{}][{}]", prefix, key, i),
79+
value,
80+
));
81+
}
82+
}
83+
serde_json::Value::String(s) => {
84+
params.push((format!("{}[{}]", prefix, key), s.clone()))
85+
}
86+
_ => params.push((format!("{}[{}]", prefix, key), value.to_string())),
87+
}
88+
}
89+
90+
return params;
91+
}
92+
93+
unimplemented!("Only objects are supported with style=deepObject")
94+
}
95+
96+
pub mod services_api;
97+
98+
pub mod configuration;

0 commit comments

Comments
 (0)