use std::collections::HashMap;
use std::cell::RefCell;
use std::default::Default;
use std::collections::BTreeMap;
use serde_json as json;
use std::io;
use std::fs;
use std::mem;
use std::thread::sleep;
use crate::client;
#[derive(PartialEq, Eq, Hash)]
pub enum Scope {
AppengineAdmin,
CloudPlatform,
CloudPlatformReadOnly,
Compute,
DevstorageReadWrite,
NdevCloudman,
NdevCloudmanReadonly,
}
impl AsRef<str> for Scope {
fn as_ref(&self) -> &str {
match *self {
Scope::AppengineAdmin => "https://www.googleapis.com/auth/appengine.admin",
Scope::CloudPlatform => "https://www.googleapis.com/auth/cloud-platform",
Scope::CloudPlatformReadOnly => "https://www.googleapis.com/auth/cloud-platform.read-only",
Scope::Compute => "https://www.googleapis.com/auth/compute",
Scope::DevstorageReadWrite => "https://www.googleapis.com/auth/devstorage.read_write",
Scope::NdevCloudman => "https://www.googleapis.com/auth/ndev.cloudman",
Scope::NdevCloudmanReadonly => "https://www.googleapis.com/auth/ndev.cloudman.readonly",
}
}
}
impl Default for Scope {
fn default() -> Scope {
Scope::NdevCloudmanReadonly
}
}
#[derive(Clone)]
pub struct Manager<> {
client: hyper::Client<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>, hyper::body::Body>,
auth: oauth2::authenticator::Authenticator<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>>,
_user_agent: String,
_base_url: String,
_root_url: String,
}
impl<'a, > client::Hub for Manager<> {}
impl<'a, > Manager<> {
pub fn new(client: hyper::Client<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>, hyper::body::Body>, authenticator: oauth2::authenticator::Authenticator<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>>) -> Manager<> {
Manager {
client,
auth: authenticator,
_user_agent: "google-api-rust-client/2.0.8".to_string(),
_base_url: "https://www.googleapis.com/manager/v1beta2/projects/".to_string(),
_root_url: "https://www.googleapis.com/".to_string(),
}
}
pub fn deployments(&'a self) -> DeploymentMethods<'a> {
DeploymentMethods { hub: &self }
}
pub fn templates(&'a self) -> TemplateMethods<'a> {
TemplateMethods { hub: &self }
}
pub fn user_agent(&mut self, agent_name: String) -> String {
mem::replace(&mut self._user_agent, agent_name)
}
pub fn base_url(&mut self, new_base_url: String) -> String {
mem::replace(&mut self._base_url, new_base_url)
}
pub fn root_url(&mut self, new_root_url: String) -> String {
mem::replace(&mut self._root_url, new_root_url)
}
}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct AccessConfig {
pub name: Option<String>,
#[serde(rename="natIp")]
pub nat_ip: Option<String>,
#[serde(rename="type")]
pub type_: Option<String>,
}
impl client::Part for AccessConfig {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Action {
pub commands: Option<Vec<String>>,
#[serde(rename="timeoutMs")]
pub timeout_ms: Option<i32>,
}
impl client::Part for Action {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct AllowedRule {
#[serde(rename="IPProtocol")]
pub ip_protocol: Option<String>,
pub ports: Option<Vec<String>>,
}
impl client::Part for AllowedRule {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct AutoscalingModule {
#[serde(rename="coolDownPeriodSec")]
pub cool_down_period_sec: Option<i32>,
pub description: Option<String>,
#[serde(rename="maxNumReplicas")]
pub max_num_replicas: Option<i32>,
#[serde(rename="minNumReplicas")]
pub min_num_replicas: Option<i32>,
#[serde(rename="signalType")]
pub signal_type: Option<String>,
#[serde(rename="targetModule")]
pub target_module: Option<String>,
#[serde(rename="targetUtilization")]
pub target_utilization: Option<f64>,
}
impl client::Part for AutoscalingModule {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct AutoscalingModuleStatus {
#[serde(rename="autoscalingConfigUrl")]
pub autoscaling_config_url: Option<String>,
}
impl client::Part for AutoscalingModuleStatus {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct DeployState {
pub details: Option<String>,
pub status: Option<String>,
}
impl client::Part for DeployState {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Deployment {
#[serde(rename="creationDate")]
pub creation_date: Option<String>,
pub description: Option<String>,
pub modules: Option<HashMap<String, ModuleStatus>>,
pub name: Option<String>,
pub overrides: Option<Vec<ParamOverride>>,
pub state: Option<DeployState>,
#[serde(rename="templateName")]
pub template_name: Option<String>,
}
impl client::RequestValue for Deployment {}
impl client::Resource for Deployment {}
impl client::ResponseResult for Deployment {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct DeploymentsListResponse {
#[serde(rename="nextPageToken")]
pub next_page_token: Option<String>,
pub resources: Option<Vec<Deployment>>,
}
impl client::ResponseResult for DeploymentsListResponse {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct DiskAttachment {
#[serde(rename="deviceName")]
pub device_name: Option<String>,
pub index: Option<u32>,
}
impl client::Part for DiskAttachment {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct EnvVariable {
pub hidden: Option<bool>,
pub value: Option<String>,
}
impl client::Part for EnvVariable {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct ExistingDisk {
pub attachment: Option<DiskAttachment>,
pub source: Option<String>,
}
impl client::Part for ExistingDisk {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct FirewallModule {
pub allowed: Option<Vec<AllowedRule>>,
pub description: Option<String>,
pub network: Option<String>,
#[serde(rename="sourceRanges")]
pub source_ranges: Option<Vec<String>>,
#[serde(rename="sourceTags")]
pub source_tags: Option<Vec<String>>,
#[serde(rename="targetTags")]
pub target_tags: Option<Vec<String>>,
}
impl client::Part for FirewallModule {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct FirewallModuleStatus {
#[serde(rename="firewallUrl")]
pub firewall_url: Option<String>,
}
impl client::Part for FirewallModuleStatus {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct HealthCheckModule {
#[serde(rename="checkIntervalSec")]
pub check_interval_sec: Option<i32>,
pub description: Option<String>,
#[serde(rename="healthyThreshold")]
pub healthy_threshold: Option<i32>,
pub host: Option<String>,
pub path: Option<String>,
pub port: Option<i32>,
#[serde(rename="timeoutSec")]
pub timeout_sec: Option<i32>,
#[serde(rename="unhealthyThreshold")]
pub unhealthy_threshold: Option<i32>,
}
impl client::Part for HealthCheckModule {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct HealthCheckModuleStatus {
#[serde(rename="healthCheckUrl")]
pub health_check_url: Option<String>,
}
impl client::Part for HealthCheckModuleStatus {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct LbModule {
pub description: Option<String>,
#[serde(rename="healthChecks")]
pub health_checks: Option<Vec<String>>,
#[serde(rename="ipAddress")]
pub ip_address: Option<String>,
#[serde(rename="ipProtocol")]
pub ip_protocol: Option<String>,
#[serde(rename="portRange")]
pub port_range: Option<String>,
#[serde(rename="sessionAffinity")]
pub session_affinity: Option<String>,
#[serde(rename="targetModules")]
pub target_modules: Option<Vec<String>>,
}
impl client::Part for LbModule {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct LbModuleStatus {
#[serde(rename="forwardingRuleUrl")]
pub forwarding_rule_url: Option<String>,
#[serde(rename="targetPoolUrl")]
pub target_pool_url: Option<String>,
}
impl client::Part for LbModuleStatus {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Metadata {
#[serde(rename="fingerPrint")]
pub finger_print: Option<String>,
pub items: Option<Vec<MetadataItem>>,
}
impl client::Part for Metadata {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct MetadataItem {
pub key: Option<String>,
pub value: Option<String>,
}
impl client::Part for MetadataItem {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Module {
#[serde(rename="autoscalingModule")]
pub autoscaling_module: Option<AutoscalingModule>,
#[serde(rename="firewallModule")]
pub firewall_module: Option<FirewallModule>,
#[serde(rename="healthCheckModule")]
pub health_check_module: Option<HealthCheckModule>,
#[serde(rename="lbModule")]
pub lb_module: Option<LbModule>,
#[serde(rename="networkModule")]
pub network_module: Option<NetworkModule>,
#[serde(rename="replicaPoolModule")]
pub replica_pool_module: Option<ReplicaPoolModule>,
#[serde(rename="type")]
pub type_: Option<String>,
}
impl client::Part for Module {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct ModuleStatus {
#[serde(rename="autoscalingModuleStatus")]
pub autoscaling_module_status: Option<AutoscalingModuleStatus>,
#[serde(rename="firewallModuleStatus")]
pub firewall_module_status: Option<FirewallModuleStatus>,
#[serde(rename="healthCheckModuleStatus")]
pub health_check_module_status: Option<HealthCheckModuleStatus>,
#[serde(rename="lbModuleStatus")]
pub lb_module_status: Option<LbModuleStatus>,
#[serde(rename="networkModuleStatus")]
pub network_module_status: Option<NetworkModuleStatus>,
#[serde(rename="replicaPoolModuleStatus")]
pub replica_pool_module_status: Option<ReplicaPoolModuleStatus>,
pub state: Option<DeployState>,
#[serde(rename="type")]
pub type_: Option<String>,
}
impl client::Part for ModuleStatus {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct NetworkInterface {
#[serde(rename="accessConfigs")]
pub access_configs: Option<Vec<AccessConfig>>,
pub name: Option<String>,
pub network: Option<String>,
#[serde(rename="networkIp")]
pub network_ip: Option<String>,
}
impl client::Part for NetworkInterface {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct NetworkModule {
#[serde(rename="IPv4Range")]
pub i_pv4_range: Option<String>,
pub description: Option<String>,
#[serde(rename="gatewayIPv4")]
pub gateway_i_pv4: Option<String>,
}
impl client::Part for NetworkModule {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct NetworkModuleStatus {
#[serde(rename="networkUrl")]
pub network_url: Option<String>,
}
impl client::Part for NetworkModuleStatus {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct NewDisk {
pub attachment: Option<DiskAttachment>,
#[serde(rename="autoDelete")]
pub auto_delete: Option<bool>,
pub boot: Option<bool>,
#[serde(rename="initializeParams")]
pub initialize_params: Option<NewDiskInitializeParams>,
}
impl client::Part for NewDisk {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct NewDiskInitializeParams {
#[serde(rename="diskSizeGb")]
pub disk_size_gb: Option<String>,
#[serde(rename="diskType")]
pub disk_type: Option<String>,
#[serde(rename="sourceImage")]
pub source_image: Option<String>,
}
impl client::Part for NewDiskInitializeParams {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct ParamOverride {
pub path: Option<String>,
pub value: Option<String>,
}
impl client::Part for ParamOverride {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct ReplicaPoolModule {
#[serde(rename="envVariables")]
pub env_variables: Option<HashMap<String, EnvVariable>>,
#[serde(rename="healthChecks")]
pub health_checks: Option<Vec<String>>,
#[serde(rename="numReplicas")]
pub num_replicas: Option<i32>,
#[serde(rename="replicaPoolParams")]
pub replica_pool_params: Option<ReplicaPoolParams>,
#[serde(rename="resourceView")]
pub resource_view: Option<String>,
}
impl client::Part for ReplicaPoolModule {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct ReplicaPoolModuleStatus {
#[serde(rename="replicaPoolUrl")]
pub replica_pool_url: Option<String>,
#[serde(rename="resourceViewUrl")]
pub resource_view_url: Option<String>,
}
impl client::Part for ReplicaPoolModuleStatus {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct ReplicaPoolParams {
pub v1beta1: Option<ReplicaPoolParamsV1Beta1>,
}
impl client::Part for ReplicaPoolParams {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct ReplicaPoolParamsV1Beta1 {
#[serde(rename="autoRestart")]
pub auto_restart: Option<bool>,
#[serde(rename="baseInstanceName")]
pub base_instance_name: Option<String>,
#[serde(rename="canIpForward")]
pub can_ip_forward: Option<bool>,
pub description: Option<String>,
#[serde(rename="disksToAttach")]
pub disks_to_attach: Option<Vec<ExistingDisk>>,
#[serde(rename="disksToCreate")]
pub disks_to_create: Option<Vec<NewDisk>>,
#[serde(rename="initAction")]
pub init_action: Option<String>,
#[serde(rename="machineType")]
pub machine_type: Option<String>,
pub metadata: Option<Metadata>,
#[serde(rename="networkInterfaces")]
pub network_interfaces: Option<Vec<NetworkInterface>>,
#[serde(rename="onHostMaintenance")]
pub on_host_maintenance: Option<String>,
#[serde(rename="serviceAccounts")]
pub service_accounts: Option<Vec<ServiceAccount>>,
pub tags: Option<Tag>,
pub zone: Option<String>,
}
impl client::Part for ReplicaPoolParamsV1Beta1 {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct ServiceAccount {
pub email: Option<String>,
pub scopes: Option<Vec<String>>,
}
impl client::Part for ServiceAccount {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Tag {
#[serde(rename="fingerPrint")]
pub finger_print: Option<String>,
pub items: Option<Vec<String>>,
}
impl client::Part for Tag {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Template {
pub actions: Option<HashMap<String, Action>>,
pub description: Option<String>,
pub modules: Option<HashMap<String, Module>>,
pub name: Option<String>,
}
impl client::RequestValue for Template {}
impl client::Resource for Template {}
impl client::ResponseResult for Template {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct TemplatesListResponse {
#[serde(rename="nextPageToken")]
pub next_page_token: Option<String>,
pub resources: Option<Vec<Template>>,
}
impl client::ResponseResult for TemplatesListResponse {}
pub struct DeploymentMethods<'a>
where {
hub: &'a Manager<>,
}
impl<'a> client::MethodsBuilder for DeploymentMethods<'a> {}
impl<'a> DeploymentMethods<'a> {
pub fn delete(&self, project_id: &str, region: &str, deployment_name: &str) -> DeploymentDeleteCall<'a> {
DeploymentDeleteCall {
hub: self.hub,
_project_id: project_id.to_string(),
_region: region.to_string(),
_deployment_name: deployment_name.to_string(),
_delegate: Default::default(),
_additional_params: Default::default(),
_scopes: Default::default(),
}
}
pub fn get(&self, project_id: &str, region: &str, deployment_name: &str) -> DeploymentGetCall<'a> {
DeploymentGetCall {
hub: self.hub,
_project_id: project_id.to_string(),
_region: region.to_string(),
_deployment_name: deployment_name.to_string(),
_delegate: Default::default(),
_additional_params: Default::default(),
_scopes: Default::default(),
}
}
pub fn insert(&self, request: Deployment, project_id: &str, region: &str) -> DeploymentInsertCall<'a> {
DeploymentInsertCall {
hub: self.hub,
_request: request,
_project_id: project_id.to_string(),
_region: region.to_string(),
_delegate: Default::default(),
_additional_params: Default::default(),
_scopes: Default::default(),
}
}
pub fn list(&self, project_id: &str, region: &str) -> DeploymentListCall<'a> {
DeploymentListCall {
hub: self.hub,
_project_id: project_id.to_string(),
_region: region.to_string(),
_page_token: Default::default(),
_max_results: Default::default(),
_delegate: Default::default(),
_additional_params: Default::default(),
_scopes: Default::default(),
}
}
}
pub struct TemplateMethods<'a>
where {
hub: &'a Manager<>,
}
impl<'a> client::MethodsBuilder for TemplateMethods<'a> {}
impl<'a> TemplateMethods<'a> {
pub fn delete(&self, project_id: &str, template_name: &str) -> TemplateDeleteCall<'a> {
TemplateDeleteCall {
hub: self.hub,
_project_id: project_id.to_string(),
_template_name: template_name.to_string(),
_delegate: Default::default(),
_additional_params: Default::default(),
_scopes: Default::default(),
}
}
pub fn get(&self, project_id: &str, template_name: &str) -> TemplateGetCall<'a> {
TemplateGetCall {
hub: self.hub,
_project_id: project_id.to_string(),
_template_name: template_name.to_string(),
_delegate: Default::default(),
_additional_params: Default::default(),
_scopes: Default::default(),
}
}
pub fn insert(&self, request: Template, project_id: &str) -> TemplateInsertCall<'a> {
TemplateInsertCall {
hub: self.hub,
_request: request,
_project_id: project_id.to_string(),
_delegate: Default::default(),
_additional_params: Default::default(),
_scopes: Default::default(),
}
}
pub fn list(&self, project_id: &str) -> TemplateListCall<'a> {
TemplateListCall {
hub: self.hub,
_project_id: project_id.to_string(),
_page_token: Default::default(),
_max_results: Default::default(),
_delegate: Default::default(),
_additional_params: Default::default(),
_scopes: Default::default(),
}
}
}
pub struct DeploymentDeleteCall<'a>
where {
hub: &'a Manager<>,
_project_id: String,
_region: String,
_deployment_name: String,
_delegate: Option<&'a mut dyn client::Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a> client::CallBuilder for DeploymentDeleteCall<'a> {}
impl<'a> DeploymentDeleteCall<'a> {
pub async fn doit(mut self) -> client::Result<hyper::Response<hyper::body::Body>> {
use std::io::{Read, Seek};
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
use client::ToParts;
let mut dd = client::DefaultDelegate;
let mut dlg: &mut dyn client::Delegate = match self._delegate {
Some(d) => d,
None => &mut dd
};
dlg.begin(client::MethodInfo { id: "manager.deployments.delete",
http_method: hyper::Method::DELETE });
let mut params: Vec<(&str, String)> = Vec::with_capacity(4 + self._additional_params.len());
params.push(("projectId", self._project_id.to_string()));
params.push(("region", self._region.to_string()));
params.push(("deploymentName", self._deployment_name.to_string()));
for &field in ["projectId", "region", "deploymentName"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Err(client::Error::FieldClash(field));
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
let mut url = self.hub._base_url.clone() + "{projectId}/regions/{region}/deployments/{deploymentName}";
if self._scopes.len() == 0 {
self._scopes.insert(Scope::CloudPlatform.as_ref().to_string(), ());
}
for &(find_this, param_name) in [("{projectId}", "projectId"), ("{region}", "region"), ("{deploymentName}", "deploymentName")].iter() {
let mut replace_with: Option<&str> = None;
for &(name, ref value) in params.iter() {
if name == param_name {
replace_with = Some(value);
break;
}
}
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
}
{
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(3);
for param_name in ["deploymentName", "region", "projectId"].iter() {
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
indices_for_removal.push(index);
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
let url = url::Url::parse_with_params(&url, params).unwrap();
loop {
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
Ok(token) => token.clone(),
Err(err) => {
match dlg.token(&err) {
Some(token) => token,
None => {
dlg.finished(false);
return Err(client::Error::MissingToken(err))
}
}
}
};
let mut req_result = {
let client = &self.hub.client;
dlg.pre_request();
let mut req_builder = hyper::Request::builder().method(hyper::Method::DELETE).uri(url.clone().into_string())
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
let request = req_builder
.body(hyper::body::Body::empty());
client.request(request.unwrap()).await
};
match req_result {
Err(err) => {
if let client::Retry::After(d) = dlg.http_error(&err) {
sleep(d);
continue;
}
dlg.finished(false);
return Err(client::Error::HttpError(err))
}
Ok(mut res) => {
if !res.status().is_success() {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
let json_server_error = json::from_str::<client::JsonServerError>(&res_body_string).ok();
let server_error = json::from_str::<client::ServerError>(&res_body_string)
.or_else(|_| json::from_str::<client::ErrorResponse>(&res_body_string).map(|r| r.error))
.ok();
if let client::Retry::After(d) = dlg.http_failure(&res,
json_server_error,
server_error) {
sleep(d);
continue;
}
dlg.finished(false);
return match json::from_str::<client::ErrorResponse>(&res_body_string){
Err(_) => Err(client::Error::Failure(res)),
Ok(serr) => Err(client::Error::BadRequest(serr))
}
}
let result_value = res;
dlg.finished(true);
return Ok(result_value)
}
}
}
}
pub fn project_id(mut self, new_value: &str) -> DeploymentDeleteCall<'a> {
self._project_id = new_value.to_string();
self
}
pub fn region(mut self, new_value: &str) -> DeploymentDeleteCall<'a> {
self._region = new_value.to_string();
self
}
pub fn deployment_name(mut self, new_value: &str) -> DeploymentDeleteCall<'a> {
self._deployment_name = new_value.to_string();
self
}
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> DeploymentDeleteCall<'a> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> DeploymentDeleteCall<'a>
where T: AsRef<str> {
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
pub fn add_scope<T, S>(mut self, scope: T) -> DeploymentDeleteCall<'a>
where T: Into<Option<S>>,
S: AsRef<str> {
match scope.into() {
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
None => None,
};
self
}
}
pub struct DeploymentGetCall<'a>
where {
hub: &'a Manager<>,
_project_id: String,
_region: String,
_deployment_name: String,
_delegate: Option<&'a mut dyn client::Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a> client::CallBuilder for DeploymentGetCall<'a> {}
impl<'a> DeploymentGetCall<'a> {
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, Deployment)> {
use std::io::{Read, Seek};
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
use client::ToParts;
let mut dd = client::DefaultDelegate;
let mut dlg: &mut dyn client::Delegate = match self._delegate {
Some(d) => d,
None => &mut dd
};
dlg.begin(client::MethodInfo { id: "manager.deployments.get",
http_method: hyper::Method::GET });
let mut params: Vec<(&str, String)> = Vec::with_capacity(5 + self._additional_params.len());
params.push(("projectId", self._project_id.to_string()));
params.push(("region", self._region.to_string()));
params.push(("deploymentName", self._deployment_name.to_string()));
for &field in ["alt", "projectId", "region", "deploymentName"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Err(client::Error::FieldClash(field));
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
params.push(("alt", "json".to_string()));
let mut url = self.hub._base_url.clone() + "{projectId}/regions/{region}/deployments/{deploymentName}";
if self._scopes.len() == 0 {
self._scopes.insert(Scope::NdevCloudmanReadonly.as_ref().to_string(), ());
}
for &(find_this, param_name) in [("{projectId}", "projectId"), ("{region}", "region"), ("{deploymentName}", "deploymentName")].iter() {
let mut replace_with: Option<&str> = None;
for &(name, ref value) in params.iter() {
if name == param_name {
replace_with = Some(value);
break;
}
}
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
}
{
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(3);
for param_name in ["deploymentName", "region", "projectId"].iter() {
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
indices_for_removal.push(index);
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
let url = url::Url::parse_with_params(&url, params).unwrap();
loop {
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
Ok(token) => token.clone(),
Err(err) => {
match dlg.token(&err) {
Some(token) => token,
None => {
dlg.finished(false);
return Err(client::Error::MissingToken(err))
}
}
}
};
let mut req_result = {
let client = &self.hub.client;
dlg.pre_request();
let mut req_builder = hyper::Request::builder().method(hyper::Method::GET).uri(url.clone().into_string())
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
let request = req_builder
.body(hyper::body::Body::empty());
client.request(request.unwrap()).await
};
match req_result {
Err(err) => {
if let client::Retry::After(d) = dlg.http_error(&err) {
sleep(d);
continue;
}
dlg.finished(false);
return Err(client::Error::HttpError(err))
}
Ok(mut res) => {
if !res.status().is_success() {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
let json_server_error = json::from_str::<client::JsonServerError>(&res_body_string).ok();
let server_error = json::from_str::<client::ServerError>(&res_body_string)
.or_else(|_| json::from_str::<client::ErrorResponse>(&res_body_string).map(|r| r.error))
.ok();
if let client::Retry::After(d) = dlg.http_failure(&res,
json_server_error,
server_error) {
sleep(d);
continue;
}
dlg.finished(false);
return match json::from_str::<client::ErrorResponse>(&res_body_string){
Err(_) => Err(client::Error::Failure(res)),
Ok(serr) => Err(client::Error::BadRequest(serr))
}
}
let result_value = {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
match json::from_str(&res_body_string) {
Ok(decoded) => (res, decoded),
Err(err) => {
dlg.response_json_decode_error(&res_body_string, &err);
return Err(client::Error::JsonDecodeError(res_body_string, err));
}
}
};
dlg.finished(true);
return Ok(result_value)
}
}
}
}
pub fn project_id(mut self, new_value: &str) -> DeploymentGetCall<'a> {
self._project_id = new_value.to_string();
self
}
pub fn region(mut self, new_value: &str) -> DeploymentGetCall<'a> {
self._region = new_value.to_string();
self
}
pub fn deployment_name(mut self, new_value: &str) -> DeploymentGetCall<'a> {
self._deployment_name = new_value.to_string();
self
}
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> DeploymentGetCall<'a> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> DeploymentGetCall<'a>
where T: AsRef<str> {
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
pub fn add_scope<T, S>(mut self, scope: T) -> DeploymentGetCall<'a>
where T: Into<Option<S>>,
S: AsRef<str> {
match scope.into() {
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
None => None,
};
self
}
}
pub struct DeploymentInsertCall<'a>
where {
hub: &'a Manager<>,
_request: Deployment,
_project_id: String,
_region: String,
_delegate: Option<&'a mut dyn client::Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a> client::CallBuilder for DeploymentInsertCall<'a> {}
impl<'a> DeploymentInsertCall<'a> {
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, Deployment)> {
use std::io::{Read, Seek};
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
use client::ToParts;
let mut dd = client::DefaultDelegate;
let mut dlg: &mut dyn client::Delegate = match self._delegate {
Some(d) => d,
None => &mut dd
};
dlg.begin(client::MethodInfo { id: "manager.deployments.insert",
http_method: hyper::Method::POST });
let mut params: Vec<(&str, String)> = Vec::with_capacity(5 + self._additional_params.len());
params.push(("projectId", self._project_id.to_string()));
params.push(("region", self._region.to_string()));
for &field in ["alt", "projectId", "region"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Err(client::Error::FieldClash(field));
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
params.push(("alt", "json".to_string()));
let mut url = self.hub._base_url.clone() + "{projectId}/regions/{region}/deployments";
if self._scopes.len() == 0 {
self._scopes.insert(Scope::AppengineAdmin.as_ref().to_string(), ());
}
for &(find_this, param_name) in [("{projectId}", "projectId"), ("{region}", "region")].iter() {
let mut replace_with: Option<&str> = None;
for &(name, ref value) in params.iter() {
if name == param_name {
replace_with = Some(value);
break;
}
}
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
}
{
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(2);
for param_name in ["region", "projectId"].iter() {
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
indices_for_removal.push(index);
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
let url = url::Url::parse_with_params(&url, params).unwrap();
let mut json_mime_type: mime::Mime = "application/json".parse().unwrap();
let mut request_value_reader =
{
let mut value = json::value::to_value(&self._request).expect("serde to work");
client::remove_json_null_values(&mut value);
let mut dst = io::Cursor::new(Vec::with_capacity(128));
json::to_writer(&mut dst, &value).unwrap();
dst
};
let request_size = request_value_reader.seek(io::SeekFrom::End(0)).unwrap();
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
loop {
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
Ok(token) => token.clone(),
Err(err) => {
match dlg.token(&err) {
Some(token) => token,
None => {
dlg.finished(false);
return Err(client::Error::MissingToken(err))
}
}
}
};
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
let mut req_result = {
let client = &self.hub.client;
dlg.pre_request();
let mut req_builder = hyper::Request::builder().method(hyper::Method::POST).uri(url.clone().into_string())
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
let request = req_builder
.header(CONTENT_TYPE, format!("{}", json_mime_type.to_string()))
.header(CONTENT_LENGTH, request_size as u64)
.body(hyper::body::Body::from(request_value_reader.get_ref().clone()));
client.request(request.unwrap()).await
};
match req_result {
Err(err) => {
if let client::Retry::After(d) = dlg.http_error(&err) {
sleep(d);
continue;
}
dlg.finished(false);
return Err(client::Error::HttpError(err))
}
Ok(mut res) => {
if !res.status().is_success() {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
let json_server_error = json::from_str::<client::JsonServerError>(&res_body_string).ok();
let server_error = json::from_str::<client::ServerError>(&res_body_string)
.or_else(|_| json::from_str::<client::ErrorResponse>(&res_body_string).map(|r| r.error))
.ok();
if let client::Retry::After(d) = dlg.http_failure(&res,
json_server_error,
server_error) {
sleep(d);
continue;
}
dlg.finished(false);
return match json::from_str::<client::ErrorResponse>(&res_body_string){
Err(_) => Err(client::Error::Failure(res)),
Ok(serr) => Err(client::Error::BadRequest(serr))
}
}
let result_value = {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
match json::from_str(&res_body_string) {
Ok(decoded) => (res, decoded),
Err(err) => {
dlg.response_json_decode_error(&res_body_string, &err);
return Err(client::Error::JsonDecodeError(res_body_string, err));
}
}
};
dlg.finished(true);
return Ok(result_value)
}
}
}
}
pub fn request(mut self, new_value: Deployment) -> DeploymentInsertCall<'a> {
self._request = new_value;
self
}
pub fn project_id(mut self, new_value: &str) -> DeploymentInsertCall<'a> {
self._project_id = new_value.to_string();
self
}
pub fn region(mut self, new_value: &str) -> DeploymentInsertCall<'a> {
self._region = new_value.to_string();
self
}
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> DeploymentInsertCall<'a> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> DeploymentInsertCall<'a>
where T: AsRef<str> {
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
pub fn add_scope<T, S>(mut self, scope: T) -> DeploymentInsertCall<'a>
where T: Into<Option<S>>,
S: AsRef<str> {
match scope.into() {
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
None => None,
};
self
}
}
pub struct DeploymentListCall<'a>
where {
hub: &'a Manager<>,
_project_id: String,
_region: String,
_page_token: Option<String>,
_max_results: Option<i32>,
_delegate: Option<&'a mut dyn client::Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a> client::CallBuilder for DeploymentListCall<'a> {}
impl<'a> DeploymentListCall<'a> {
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, DeploymentsListResponse)> {
use std::io::{Read, Seek};
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
use client::ToParts;
let mut dd = client::DefaultDelegate;
let mut dlg: &mut dyn client::Delegate = match self._delegate {
Some(d) => d,
None => &mut dd
};
dlg.begin(client::MethodInfo { id: "manager.deployments.list",
http_method: hyper::Method::GET });
let mut params: Vec<(&str, String)> = Vec::with_capacity(6 + self._additional_params.len());
params.push(("projectId", self._project_id.to_string()));
params.push(("region", self._region.to_string()));
if let Some(value) = self._page_token {
params.push(("pageToken", value.to_string()));
}
if let Some(value) = self._max_results {
params.push(("maxResults", value.to_string()));
}
for &field in ["alt", "projectId", "region", "pageToken", "maxResults"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Err(client::Error::FieldClash(field));
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
params.push(("alt", "json".to_string()));
let mut url = self.hub._base_url.clone() + "{projectId}/regions/{region}/deployments";
if self._scopes.len() == 0 {
self._scopes.insert(Scope::NdevCloudmanReadonly.as_ref().to_string(), ());
}
for &(find_this, param_name) in [("{projectId}", "projectId"), ("{region}", "region")].iter() {
let mut replace_with: Option<&str> = None;
for &(name, ref value) in params.iter() {
if name == param_name {
replace_with = Some(value);
break;
}
}
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
}
{
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(2);
for param_name in ["region", "projectId"].iter() {
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
indices_for_removal.push(index);
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
let url = url::Url::parse_with_params(&url, params).unwrap();
loop {
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
Ok(token) => token.clone(),
Err(err) => {
match dlg.token(&err) {
Some(token) => token,
None => {
dlg.finished(false);
return Err(client::Error::MissingToken(err))
}
}
}
};
let mut req_result = {
let client = &self.hub.client;
dlg.pre_request();
let mut req_builder = hyper::Request::builder().method(hyper::Method::GET).uri(url.clone().into_string())
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
let request = req_builder
.body(hyper::body::Body::empty());
client.request(request.unwrap()).await
};
match req_result {
Err(err) => {
if let client::Retry::After(d) = dlg.http_error(&err) {
sleep(d);
continue;
}
dlg.finished(false);
return Err(client::Error::HttpError(err))
}
Ok(mut res) => {
if !res.status().is_success() {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
let json_server_error = json::from_str::<client::JsonServerError>(&res_body_string).ok();
let server_error = json::from_str::<client::ServerError>(&res_body_string)
.or_else(|_| json::from_str::<client::ErrorResponse>(&res_body_string).map(|r| r.error))
.ok();
if let client::Retry::After(d) = dlg.http_failure(&res,
json_server_error,
server_error) {
sleep(d);
continue;
}
dlg.finished(false);
return match json::from_str::<client::ErrorResponse>(&res_body_string){
Err(_) => Err(client::Error::Failure(res)),
Ok(serr) => Err(client::Error::BadRequest(serr))
}
}
let result_value = {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
match json::from_str(&res_body_string) {
Ok(decoded) => (res, decoded),
Err(err) => {
dlg.response_json_decode_error(&res_body_string, &err);
return Err(client::Error::JsonDecodeError(res_body_string, err));
}
}
};
dlg.finished(true);
return Ok(result_value)
}
}
}
}
pub fn project_id(mut self, new_value: &str) -> DeploymentListCall<'a> {
self._project_id = new_value.to_string();
self
}
pub fn region(mut self, new_value: &str) -> DeploymentListCall<'a> {
self._region = new_value.to_string();
self
}
pub fn page_token(mut self, new_value: &str) -> DeploymentListCall<'a> {
self._page_token = Some(new_value.to_string());
self
}
pub fn max_results(mut self, new_value: i32) -> DeploymentListCall<'a> {
self._max_results = Some(new_value);
self
}
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> DeploymentListCall<'a> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> DeploymentListCall<'a>
where T: AsRef<str> {
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
pub fn add_scope<T, S>(mut self, scope: T) -> DeploymentListCall<'a>
where T: Into<Option<S>>,
S: AsRef<str> {
match scope.into() {
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
None => None,
};
self
}
}
pub struct TemplateDeleteCall<'a>
where {
hub: &'a Manager<>,
_project_id: String,
_template_name: String,
_delegate: Option<&'a mut dyn client::Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a> client::CallBuilder for TemplateDeleteCall<'a> {}
impl<'a> TemplateDeleteCall<'a> {
pub async fn doit(mut self) -> client::Result<hyper::Response<hyper::body::Body>> {
use std::io::{Read, Seek};
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
use client::ToParts;
let mut dd = client::DefaultDelegate;
let mut dlg: &mut dyn client::Delegate = match self._delegate {
Some(d) => d,
None => &mut dd
};
dlg.begin(client::MethodInfo { id: "manager.templates.delete",
http_method: hyper::Method::DELETE });
let mut params: Vec<(&str, String)> = Vec::with_capacity(3 + self._additional_params.len());
params.push(("projectId", self._project_id.to_string()));
params.push(("templateName", self._template_name.to_string()));
for &field in ["projectId", "templateName"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Err(client::Error::FieldClash(field));
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
let mut url = self.hub._base_url.clone() + "{projectId}/templates/{templateName}";
if self._scopes.len() == 0 {
self._scopes.insert(Scope::CloudPlatform.as_ref().to_string(), ());
}
for &(find_this, param_name) in [("{projectId}", "projectId"), ("{templateName}", "templateName")].iter() {
let mut replace_with: Option<&str> = None;
for &(name, ref value) in params.iter() {
if name == param_name {
replace_with = Some(value);
break;
}
}
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
}
{
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(2);
for param_name in ["templateName", "projectId"].iter() {
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
indices_for_removal.push(index);
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
let url = url::Url::parse_with_params(&url, params).unwrap();
loop {
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
Ok(token) => token.clone(),
Err(err) => {
match dlg.token(&err) {
Some(token) => token,
None => {
dlg.finished(false);
return Err(client::Error::MissingToken(err))
}
}
}
};
let mut req_result = {
let client = &self.hub.client;
dlg.pre_request();
let mut req_builder = hyper::Request::builder().method(hyper::Method::DELETE).uri(url.clone().into_string())
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
let request = req_builder
.body(hyper::body::Body::empty());
client.request(request.unwrap()).await
};
match req_result {
Err(err) => {
if let client::Retry::After(d) = dlg.http_error(&err) {
sleep(d);
continue;
}
dlg.finished(false);
return Err(client::Error::HttpError(err))
}
Ok(mut res) => {
if !res.status().is_success() {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
let json_server_error = json::from_str::<client::JsonServerError>(&res_body_string).ok();
let server_error = json::from_str::<client::ServerError>(&res_body_string)
.or_else(|_| json::from_str::<client::ErrorResponse>(&res_body_string).map(|r| r.error))
.ok();
if let client::Retry::After(d) = dlg.http_failure(&res,
json_server_error,
server_error) {
sleep(d);
continue;
}
dlg.finished(false);
return match json::from_str::<client::ErrorResponse>(&res_body_string){
Err(_) => Err(client::Error::Failure(res)),
Ok(serr) => Err(client::Error::BadRequest(serr))
}
}
let result_value = res;
dlg.finished(true);
return Ok(result_value)
}
}
}
}
pub fn project_id(mut self, new_value: &str) -> TemplateDeleteCall<'a> {
self._project_id = new_value.to_string();
self
}
pub fn template_name(mut self, new_value: &str) -> TemplateDeleteCall<'a> {
self._template_name = new_value.to_string();
self
}
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> TemplateDeleteCall<'a> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> TemplateDeleteCall<'a>
where T: AsRef<str> {
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
pub fn add_scope<T, S>(mut self, scope: T) -> TemplateDeleteCall<'a>
where T: Into<Option<S>>,
S: AsRef<str> {
match scope.into() {
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
None => None,
};
self
}
}
pub struct TemplateGetCall<'a>
where {
hub: &'a Manager<>,
_project_id: String,
_template_name: String,
_delegate: Option<&'a mut dyn client::Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a> client::CallBuilder for TemplateGetCall<'a> {}
impl<'a> TemplateGetCall<'a> {
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, Template)> {
use std::io::{Read, Seek};
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
use client::ToParts;
let mut dd = client::DefaultDelegate;
let mut dlg: &mut dyn client::Delegate = match self._delegate {
Some(d) => d,
None => &mut dd
};
dlg.begin(client::MethodInfo { id: "manager.templates.get",
http_method: hyper::Method::GET });
let mut params: Vec<(&str, String)> = Vec::with_capacity(4 + self._additional_params.len());
params.push(("projectId", self._project_id.to_string()));
params.push(("templateName", self._template_name.to_string()));
for &field in ["alt", "projectId", "templateName"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Err(client::Error::FieldClash(field));
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
params.push(("alt", "json".to_string()));
let mut url = self.hub._base_url.clone() + "{projectId}/templates/{templateName}";
if self._scopes.len() == 0 {
self._scopes.insert(Scope::NdevCloudmanReadonly.as_ref().to_string(), ());
}
for &(find_this, param_name) in [("{projectId}", "projectId"), ("{templateName}", "templateName")].iter() {
let mut replace_with: Option<&str> = None;
for &(name, ref value) in params.iter() {
if name == param_name {
replace_with = Some(value);
break;
}
}
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
}
{
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(2);
for param_name in ["templateName", "projectId"].iter() {
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
indices_for_removal.push(index);
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
let url = url::Url::parse_with_params(&url, params).unwrap();
loop {
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
Ok(token) => token.clone(),
Err(err) => {
match dlg.token(&err) {
Some(token) => token,
None => {
dlg.finished(false);
return Err(client::Error::MissingToken(err))
}
}
}
};
let mut req_result = {
let client = &self.hub.client;
dlg.pre_request();
let mut req_builder = hyper::Request::builder().method(hyper::Method::GET).uri(url.clone().into_string())
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
let request = req_builder
.body(hyper::body::Body::empty());
client.request(request.unwrap()).await
};
match req_result {
Err(err) => {
if let client::Retry::After(d) = dlg.http_error(&err) {
sleep(d);
continue;
}
dlg.finished(false);
return Err(client::Error::HttpError(err))
}
Ok(mut res) => {
if !res.status().is_success() {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
let json_server_error = json::from_str::<client::JsonServerError>(&res_body_string).ok();
let server_error = json::from_str::<client::ServerError>(&res_body_string)
.or_else(|_| json::from_str::<client::ErrorResponse>(&res_body_string).map(|r| r.error))
.ok();
if let client::Retry::After(d) = dlg.http_failure(&res,
json_server_error,
server_error) {
sleep(d);
continue;
}
dlg.finished(false);
return match json::from_str::<client::ErrorResponse>(&res_body_string){
Err(_) => Err(client::Error::Failure(res)),
Ok(serr) => Err(client::Error::BadRequest(serr))
}
}
let result_value = {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
match json::from_str(&res_body_string) {
Ok(decoded) => (res, decoded),
Err(err) => {
dlg.response_json_decode_error(&res_body_string, &err);
return Err(client::Error::JsonDecodeError(res_body_string, err));
}
}
};
dlg.finished(true);
return Ok(result_value)
}
}
}
}
pub fn project_id(mut self, new_value: &str) -> TemplateGetCall<'a> {
self._project_id = new_value.to_string();
self
}
pub fn template_name(mut self, new_value: &str) -> TemplateGetCall<'a> {
self._template_name = new_value.to_string();
self
}
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> TemplateGetCall<'a> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> TemplateGetCall<'a>
where T: AsRef<str> {
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
pub fn add_scope<T, S>(mut self, scope: T) -> TemplateGetCall<'a>
where T: Into<Option<S>>,
S: AsRef<str> {
match scope.into() {
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
None => None,
};
self
}
}
pub struct TemplateInsertCall<'a>
where {
hub: &'a Manager<>,
_request: Template,
_project_id: String,
_delegate: Option<&'a mut dyn client::Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a> client::CallBuilder for TemplateInsertCall<'a> {}
impl<'a> TemplateInsertCall<'a> {
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, Template)> {
use std::io::{Read, Seek};
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
use client::ToParts;
let mut dd = client::DefaultDelegate;
let mut dlg: &mut dyn client::Delegate = match self._delegate {
Some(d) => d,
None => &mut dd
};
dlg.begin(client::MethodInfo { id: "manager.templates.insert",
http_method: hyper::Method::POST });
let mut params: Vec<(&str, String)> = Vec::with_capacity(4 + self._additional_params.len());
params.push(("projectId", self._project_id.to_string()));
for &field in ["alt", "projectId"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Err(client::Error::FieldClash(field));
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
params.push(("alt", "json".to_string()));
let mut url = self.hub._base_url.clone() + "{projectId}/templates";
if self._scopes.len() == 0 {
self._scopes.insert(Scope::CloudPlatform.as_ref().to_string(), ());
}
for &(find_this, param_name) in [("{projectId}", "projectId")].iter() {
let mut replace_with: Option<&str> = None;
for &(name, ref value) in params.iter() {
if name == param_name {
replace_with = Some(value);
break;
}
}
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
}
{
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
for param_name in ["projectId"].iter() {
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
indices_for_removal.push(index);
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
let url = url::Url::parse_with_params(&url, params).unwrap();
let mut json_mime_type: mime::Mime = "application/json".parse().unwrap();
let mut request_value_reader =
{
let mut value = json::value::to_value(&self._request).expect("serde to work");
client::remove_json_null_values(&mut value);
let mut dst = io::Cursor::new(Vec::with_capacity(128));
json::to_writer(&mut dst, &value).unwrap();
dst
};
let request_size = request_value_reader.seek(io::SeekFrom::End(0)).unwrap();
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
loop {
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
Ok(token) => token.clone(),
Err(err) => {
match dlg.token(&err) {
Some(token) => token,
None => {
dlg.finished(false);
return Err(client::Error::MissingToken(err))
}
}
}
};
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
let mut req_result = {
let client = &self.hub.client;
dlg.pre_request();
let mut req_builder = hyper::Request::builder().method(hyper::Method::POST).uri(url.clone().into_string())
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
let request = req_builder
.header(CONTENT_TYPE, format!("{}", json_mime_type.to_string()))
.header(CONTENT_LENGTH, request_size as u64)
.body(hyper::body::Body::from(request_value_reader.get_ref().clone()));
client.request(request.unwrap()).await
};
match req_result {
Err(err) => {
if let client::Retry::After(d) = dlg.http_error(&err) {
sleep(d);
continue;
}
dlg.finished(false);
return Err(client::Error::HttpError(err))
}
Ok(mut res) => {
if !res.status().is_success() {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
let json_server_error = json::from_str::<client::JsonServerError>(&res_body_string).ok();
let server_error = json::from_str::<client::ServerError>(&res_body_string)
.or_else(|_| json::from_str::<client::ErrorResponse>(&res_body_string).map(|r| r.error))
.ok();
if let client::Retry::After(d) = dlg.http_failure(&res,
json_server_error,
server_error) {
sleep(d);
continue;
}
dlg.finished(false);
return match json::from_str::<client::ErrorResponse>(&res_body_string){
Err(_) => Err(client::Error::Failure(res)),
Ok(serr) => Err(client::Error::BadRequest(serr))
}
}
let result_value = {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
match json::from_str(&res_body_string) {
Ok(decoded) => (res, decoded),
Err(err) => {
dlg.response_json_decode_error(&res_body_string, &err);
return Err(client::Error::JsonDecodeError(res_body_string, err));
}
}
};
dlg.finished(true);
return Ok(result_value)
}
}
}
}
pub fn request(mut self, new_value: Template) -> TemplateInsertCall<'a> {
self._request = new_value;
self
}
pub fn project_id(mut self, new_value: &str) -> TemplateInsertCall<'a> {
self._project_id = new_value.to_string();
self
}
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> TemplateInsertCall<'a> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> TemplateInsertCall<'a>
where T: AsRef<str> {
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
pub fn add_scope<T, S>(mut self, scope: T) -> TemplateInsertCall<'a>
where T: Into<Option<S>>,
S: AsRef<str> {
match scope.into() {
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
None => None,
};
self
}
}
pub struct TemplateListCall<'a>
where {
hub: &'a Manager<>,
_project_id: String,
_page_token: Option<String>,
_max_results: Option<i32>,
_delegate: Option<&'a mut dyn client::Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a> client::CallBuilder for TemplateListCall<'a> {}
impl<'a> TemplateListCall<'a> {
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, TemplatesListResponse)> {
use std::io::{Read, Seek};
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
use client::ToParts;
let mut dd = client::DefaultDelegate;
let mut dlg: &mut dyn client::Delegate = match self._delegate {
Some(d) => d,
None => &mut dd
};
dlg.begin(client::MethodInfo { id: "manager.templates.list",
http_method: hyper::Method::GET });
let mut params: Vec<(&str, String)> = Vec::with_capacity(5 + self._additional_params.len());
params.push(("projectId", self._project_id.to_string()));
if let Some(value) = self._page_token {
params.push(("pageToken", value.to_string()));
}
if let Some(value) = self._max_results {
params.push(("maxResults", value.to_string()));
}
for &field in ["alt", "projectId", "pageToken", "maxResults"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Err(client::Error::FieldClash(field));
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
params.push(("alt", "json".to_string()));
let mut url = self.hub._base_url.clone() + "{projectId}/templates";
if self._scopes.len() == 0 {
self._scopes.insert(Scope::NdevCloudmanReadonly.as_ref().to_string(), ());
}
for &(find_this, param_name) in [("{projectId}", "projectId")].iter() {
let mut replace_with: Option<&str> = None;
for &(name, ref value) in params.iter() {
if name == param_name {
replace_with = Some(value);
break;
}
}
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
}
{
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
for param_name in ["projectId"].iter() {
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
indices_for_removal.push(index);
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
let url = url::Url::parse_with_params(&url, params).unwrap();
loop {
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
Ok(token) => token.clone(),
Err(err) => {
match dlg.token(&err) {
Some(token) => token,
None => {
dlg.finished(false);
return Err(client::Error::MissingToken(err))
}
}
}
};
let mut req_result = {
let client = &self.hub.client;
dlg.pre_request();
let mut req_builder = hyper::Request::builder().method(hyper::Method::GET).uri(url.clone().into_string())
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
let request = req_builder
.body(hyper::body::Body::empty());
client.request(request.unwrap()).await
};
match req_result {
Err(err) => {
if let client::Retry::After(d) = dlg.http_error(&err) {
sleep(d);
continue;
}
dlg.finished(false);
return Err(client::Error::HttpError(err))
}
Ok(mut res) => {
if !res.status().is_success() {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
let json_server_error = json::from_str::<client::JsonServerError>(&res_body_string).ok();
let server_error = json::from_str::<client::ServerError>(&res_body_string)
.or_else(|_| json::from_str::<client::ErrorResponse>(&res_body_string).map(|r| r.error))
.ok();
if let client::Retry::After(d) = dlg.http_failure(&res,
json_server_error,
server_error) {
sleep(d);
continue;
}
dlg.finished(false);
return match json::from_str::<client::ErrorResponse>(&res_body_string){
Err(_) => Err(client::Error::Failure(res)),
Ok(serr) => Err(client::Error::BadRequest(serr))
}
}
let result_value = {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
match json::from_str(&res_body_string) {
Ok(decoded) => (res, decoded),
Err(err) => {
dlg.response_json_decode_error(&res_body_string, &err);
return Err(client::Error::JsonDecodeError(res_body_string, err));
}
}
};
dlg.finished(true);
return Ok(result_value)
}
}
}
}
pub fn project_id(mut self, new_value: &str) -> TemplateListCall<'a> {
self._project_id = new_value.to_string();
self
}
pub fn page_token(mut self, new_value: &str) -> TemplateListCall<'a> {
self._page_token = Some(new_value.to_string());
self
}
pub fn max_results(mut self, new_value: i32) -> TemplateListCall<'a> {
self._max_results = Some(new_value);
self
}
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> TemplateListCall<'a> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> TemplateListCall<'a>
where T: AsRef<str> {
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
pub fn add_scope<T, S>(mut self, scope: T) -> TemplateListCall<'a>
where T: Into<Option<S>>,
S: AsRef<str> {
match scope.into() {
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
None => None,
};
self
}
}