use super::{App, AppFeature, AppWebhook, SNI, SSL};
use crate::framework::endpoint::{HerokuEndpoint, Method};
pub struct AppUpdate<'a> {
pub app_id: &'a str,
pub params: AppUpdateParams<'a>,
}
#[cfg(feature = "builder")]
impl<'a> AppUpdate<'a> {
pub fn new(app_id: &'a str) -> AppUpdate {
AppUpdate {
app_id: app_id,
params: AppUpdateParams {
build_stack: None,
maintenance: None,
name: None,
},
}
}
pub fn build_stack(&mut self, build_stack: &'a str) -> &mut Self {
self.params.build_stack = Some(build_stack);
self
}
pub fn maintenance(&mut self, maintenance: bool) -> &mut Self {
self.params.maintenance = Some(maintenance);
self
}
pub fn name(&mut self, name: &'a str) -> &mut Self {
self.params.name = Some(name);
self
}
pub fn build(&self) -> AppUpdate<'a> {
AppUpdate {
app_id: self.app_id,
params: AppUpdateParams {
build_stack: self.params.build_stack,
maintenance: self.params.maintenance,
name: self.params.name,
},
}
}
}
#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug)]
pub struct AppUpdateParams<'a> {
pub build_stack: Option<&'a str>,
pub maintenance: Option<bool>,
pub name: Option<&'a str>,
}
impl<'a> HerokuEndpoint<App, (), AppUpdateParams<'a>> for AppUpdate<'a> {
fn method(&self) -> Method {
Method::Patch
}
fn path(&self) -> String {
format!("apps/{}", self.app_id)
}
fn body(&self) -> Option<AppUpdateParams<'a>> {
Some(self.params.clone())
}
}
pub struct AppRefreshAcm<'a> {
pub app_id: &'a str,
}
#[cfg(feature = "builder")]
impl<'a> AppRefreshAcm<'a> {
pub fn new(app_id: &'a str) -> AppRefreshAcm<'a> {
AppRefreshAcm { app_id }
}
}
impl<'a> HerokuEndpoint<App> for AppRefreshAcm<'a> {
fn method(&self) -> Method {
Method::Patch
}
fn path(&self) -> String {
format!("apps/{}/acm", self.app_id)
}
}
pub struct AppFeatureUpdate<'a> {
pub app_id: &'a str,
pub feature_id: &'a str,
pub params: AppFeatureUpdateParams,
}
#[cfg(feature = "builder")]
impl<'a> AppFeatureUpdate<'a> {
pub fn new(app_id: &'a str, feature_id: &'a str, enabled: bool) -> AppFeatureUpdate<'a> {
AppFeatureUpdate {
app_id,
feature_id,
params: AppFeatureUpdateParams { enabled },
}
}
}
#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug)]
pub struct AppFeatureUpdateParams {
pub enabled: bool,
}
impl<'a> HerokuEndpoint<AppFeature, (), AppFeatureUpdateParams> for AppFeatureUpdate<'a> {
fn method(&self) -> Method {
Method::Patch
}
fn path(&self) -> String {
format!("apps/{}/features/{}", self.app_id, self.feature_id)
}
fn body(&self) -> Option<AppFeatureUpdateParams> {
Some(self.params.clone())
}
}
pub struct AppWebhookUpdate<'a> {
pub app_id: &'a str,
pub webhook_id: &'a str,
pub params: AppWebhookUpdateParams<'a>,
}
#[cfg(feature = "builder")]
impl<'a> AppWebhookUpdate<'a> {
pub fn new(app_id: &'a str, webhook_id: &'a str) -> AppWebhookUpdate<'a> {
AppWebhookUpdate {
app_id,
webhook_id,
params: AppWebhookUpdateParams {
authorization: None,
include: None,
level: None,
secret: None,
url: None,
},
}
}
pub fn authorization(&mut self, authorization: &'a str) -> &mut Self {
self.params.authorization = Some(authorization);
self
}
pub fn include(&mut self, include: Vec<&'a str>) -> &mut Self {
self.params.include = Some(include);
self
}
pub fn level(&mut self, level: &'a str) -> &mut Self {
self.params.level = Some(level);
self
}
pub fn secret(&mut self, secret: &'a str) -> &mut Self {
self.params.secret = Some(secret);
self
}
pub fn url(&mut self, url: &'a str) -> &mut Self {
self.params.url = Some(url);
self
}
pub fn build(&self) -> AppWebhookUpdate<'a> {
AppWebhookUpdate {
app_id: self.app_id,
webhook_id: self.webhook_id,
params: AppWebhookUpdateParams {
authorization: self.params.authorization,
include: self.params.include.clone(),
level: self.params.level,
secret: self.params.secret,
url: self.params.url,
},
}
}
}
#[derive(Serialize, Clone, Debug)]
pub struct AppWebhookUpdateParams<'a> {
pub authorization: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub include: Option<Vec<&'a str>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub level: Option<&'a str>,
pub secret: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<&'a str>,
}
impl<'a> HerokuEndpoint<AppWebhook, (), AppWebhookUpdateParams<'a>> for AppWebhookUpdate<'a> {
fn method(&self) -> Method {
Method::Patch
}
fn path(&self) -> String {
format!("apps/{}/webhooks/{}", self.app_id, self.webhook_id)
}
fn body(&self) -> Option<AppWebhookUpdateParams<'a>> {
Some(self.params.clone())
}
}
pub struct SNIUpdate<'a> {
pub app_id: &'a str,
pub sni_id: &'a str,
pub params: SNIUpdateParams<'a>,
}
#[cfg(feature = "builder")]
impl<'a> SNIUpdate<'a> {
pub fn new(
app_id: &'a str,
sni_id: &'a str,
certificate_chain: &'a str,
private_key: &'a str,
) -> SNIUpdate<'a> {
SNIUpdate {
app_id,
sni_id,
params: SNIUpdateParams {
certificate_chain,
private_key,
},
}
}
}
#[derive(Serialize, Clone, Debug)]
pub struct SNIUpdateParams<'a> {
pub certificate_chain: &'a str,
pub private_key: &'a str,
}
impl<'a> HerokuEndpoint<SNI, (), SNIUpdateParams<'a>> for SNIUpdate<'a> {
fn method(&self) -> Method {
Method::Patch
}
fn path(&self) -> String {
format!("apps/{}/sni-endpoints/{}", self.app_id, self.sni_id)
}
fn body(&self) -> Option<SNIUpdateParams<'a>> {
Some(self.params.clone())
}
}
pub struct SSLUpdate<'a> {
pub app_id: &'a str,
pub ssl_id: &'a str,
pub params: SSLUpdateParams<'a>,
}
#[cfg(feature = "builder")]
impl<'a> SSLUpdate<'a> {
pub fn new(app_id: &'a str, ssl_id: &'a str) -> SSLUpdate<'a> {
SSLUpdate {
app_id,
ssl_id,
params: SSLUpdateParams {
certificate_chain: None,
private_key: None,
preprocess: None,
},
}
}
pub fn certificate_chain(&mut self, certificate_chain: &'a str) -> &mut Self {
self.params.certificate_chain = Some(certificate_chain);
self
}
pub fn private_key(&mut self, private_key: &'a str) -> &mut Self {
self.params.private_key = Some(private_key);
self
}
pub fn preprocess(&mut self, preprocess: bool) -> &mut Self {
self.params.preprocess = Some(preprocess);
self
}
pub fn build(&self) -> SSLUpdate<'a> {
SSLUpdate {
app_id: self.app_id,
ssl_id: self.ssl_id,
params: SSLUpdateParams {
certificate_chain: self.params.certificate_chain,
private_key: self.params.private_key,
preprocess: self.params.preprocess,
},
}
}
}
#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug)]
pub struct SSLUpdateParams<'a> {
pub certificate_chain: Option<&'a str>,
pub private_key: Option<&'a str>,
pub preprocess: Option<bool>,
}
impl<'a> HerokuEndpoint<SSL, (), SSLUpdateParams<'a>> for SSLUpdate<'a> {
fn method(&self) -> Method {
Method::Patch
}
fn path(&self) -> String {
format!("apps/{}/ssl-endpoints/{}", self.app_id, self.ssl_id)
}
fn body(&self) -> Option<SSLUpdateParams<'a>> {
Some(self.params.clone())
}
}