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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
//Anything related to creating apps and it's properties goes here. use super::{App, AppSetup, AppWebhook, SNI, SSL}; use std::collections::HashMap; use crate::framework::endpoint::{HerokuEndpoint, Method}; /// App Create /// /// Create a new app. /// /// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#app-create) pub struct AppCreate { /// The parameters to pass to the Heroku API pub params: AppCreateParams, } impl AppCreate { /// Create a new Heroku app with parameters pub fn new(name: Option<String>, region: Option<String>, stack: Option<String>) -> AppCreate { AppCreate { params: AppCreateParams { name, region, stack, }, } } /// Create a new Heroku app without parameters pub fn create() -> AppCreate { AppCreate { params: AppCreateParams { name: None, region: None, stack: None, }, } } } /// Create a new app with parameters. /// /// All three paramemters are optional. /// /// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#app-create-optional-parameters) #[serde_with::skip_serializing_none] #[derive(Serialize, Clone, Debug)] pub struct AppCreateParams { /// name of app. pattern: ^[a-z][a-z0-9-]{1,28}[a-z0-9]$ pub name: Option<String>, /// unique identifier or name of region pub region: Option<String>, /// unique name or identifier of stack pub stack: Option<String>, } impl HerokuEndpoint<App, (), AppCreateParams> for AppCreate { fn method(&self) -> Method { Method::Post } fn path(&self) -> String { format!("apps") } fn body(&self) -> Option<AppCreateParams> { Some(self.params.clone()) } } /// App Enable ACM /// /// Enable ACM flag for an app /// /// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#app-enable-acm) pub struct AppEnableAcm { /// app_id can be the app id or name. pub app_id: String, } impl AppEnableAcm { pub fn new(app_id: String) -> AppEnableAcm { AppEnableAcm { app_id } } } impl HerokuEndpoint<App> for AppEnableAcm { fn method(&self) -> Method { Method::Post } fn path(&self) -> String { format!("apps/{}/acm", self.app_id) } } /// App Webhook Create /// /// Create an app webhook subscription. /// /// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#app-webhook-create) pub struct AppWebhookCreate { /// app_id can be the app name or the app id pub app_id: String, /// The parameters to pass to the Heroku API pub params: AppWebhookCreateParams, } impl AppWebhookCreate { /// Create a new webhook with optional parameters pub fn new( app_id: String, authorization: Option<String>, include: Vec<String>, level: String, secret: Option<String>, url: String, ) -> AppWebhookCreate { AppWebhookCreate { app_id, params: AppWebhookCreateParams { authorization, include, level, secret, url, }, } } /// Create a new webhook without optional parameters pub fn create( app_id: String, include: Vec<String>, level: String, url: String, ) -> AppWebhookCreate { AppWebhookCreate { app_id: app_id, params: AppWebhookCreateParams { authorization: None, include: include, level: level, secret: None, url: url, }, } } } /// Create a new app webhook with parameters. /// /// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#app-webhook-create-required-parameters) #[derive(Serialize, Clone, Debug)] pub struct AppWebhookCreateParams { /// A custom Authorization header that Heroku will include with all webhook notifications pub authorization: Option<String>, /// The entities that the subscription provides notifications for pub include: Vec<String>, /// One of: "notify" or "sync" /// If notify, Heroku makes a single, fire-and-forget delivery attempt. If sync, Heroku attempts multiple deliveries until the request is successful or a limit is reached pub level: String, /// A value that Heroku will use to sign all webhook notification requests (the signature is included in the request’s Heroku-Webhook-Hmac-SHA256 header) pub secret: Option<String>, /// The URL where the webhook’s notification requests are sent pub url: String, } impl HerokuEndpoint<AppWebhook, (), AppWebhookCreateParams> for AppWebhookCreate { fn method(&self) -> Method { Method::Post } fn path(&self) -> String { format!("apps/{}/webhooks", self.app_id) } fn body(&self) -> Option<AppWebhookCreateParams> { Some(self.params.clone()) } } /// App Setup Create /// /// Create a new app setup from a gzipped tar archive containing an app.json manifest file. /// /// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#app-setup-create) pub struct AppSetupCreate<'a> { /// The parameters to pass to the Heroku API pub params: AppSetupCreateParams<'a>, } impl<'a> AppSetupCreate<'a> { /// Create a new Heroku app with required and optional parameters // :| needs a better solution. Builder pattern? pub fn new( locked: Option<bool>, name: Option<&'a str>, organization: Option<&'a str>, personal: Option<bool>, region: Option<&'a str>, space: Option<&'a str>, stack: Option<&'a str>, checksum: Option<&'a str>, url: &'a str, version: Option<&'a str>, buildpacks_list: Option<Vec<&'a str>>, env: Option<HashMap<&'a str, &'a str>>, ) -> AppSetupCreate<'a> { let buildpacks: Option<Vec<Buildpack>> = match buildpacks_list { Some(buidpacks) => { let mut buildpacks: Vec<Buildpack> = Vec::new(); for var in buidpacks { buildpacks.push(Buildpack { url: var }); } Some(buildpacks) } None => None, }; AppSetupCreate { params: AppSetupCreateParams { app: Some(SetupApp { locked, name, organization, personal, region, space, stack, }), source_blob: SourceBlob { checksum, url, version, }, overrides: Some(Overrides { buildpacks, env }), }, } } /// Create a new setup app with required parameters only pub fn create( checksum: Option<&'a str>, url: &'a str, version: Option<&'a str>, ) -> AppSetupCreate<'a> { AppSetupCreate { params: AppSetupCreateParams { app: None, source_blob: SourceBlob { checksum, url, version, }, overrides: None, }, } } } /// Create a new setup app with parameters. /// /// All three papparamemters are optional. /// /// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#app-setup-create-required-parameters) #[serde_with::skip_serializing_none] #[derive(Serialize, Clone, Debug)] pub struct AppSetupCreateParams<'a> { pub app: Option<SetupApp<'a>>, pub source_blob: SourceBlob<'a>, pub overrides: Option<Overrides<'a>>, } #[serde_with::skip_serializing_none] #[derive(Serialize, Clone, Debug)] pub struct SetupApp<'a> { /// are other team members forbidden from joining this app. pub locked: Option<bool>, /// name of app /// pattern: ^[a-z][a-z0-9-]{1,28}[a-z0-9]$ pub name: Option<&'a str>, /// unique name of team pub organization: Option<&'a str>, /// force creation of the app in the user account even if a default team is set. pub personal: Option<bool>, /// name of region pub region: Option<&'a str>, /// unique name of space /// pattern: `^[a-z0-9](?:[a-z0-9] pub space: Option<&'a str>, /// unique name pub stack: Option<&'a str>, } #[derive(Serialize, Clone, Debug)] pub struct SourceBlob<'a> { /// an optional checksum of the gzipped tarball for verifying its integrity. [Nullable] pub checksum: Option<&'a str>, /// URL of gzipped tarball of source code containing app.json manifest file. pub url: &'a str, /// Version of the gzipped tarball. [Nullable] pub version: Option<&'a str>, } #[serde_with::skip_serializing_none] #[derive(Serialize, Clone, Debug)] pub struct Overrides<'a> { /// overrides the buildpacks specified in the app.json manifest file pub buildpacks: Option<Vec<Buildpack<'a>>>, /// overrides of the env specified in the app.json manifest file pub env: Option<HashMap<&'a str, &'a str>>, } #[serde_with::skip_serializing_none] #[derive(Serialize, Clone, Debug)] pub struct Buildpack<'a> { pub url: &'a str, } impl<'a> HerokuEndpoint<AppSetup, (), AppSetupCreateParams<'a>> for AppSetupCreate<'a> { fn method(&self) -> Method { Method::Post } fn path(&self) -> String { format!("app-setups") } fn body(&self) -> Option<AppSetupCreateParams<'a>> { Some(self.params.clone()) } } /// SNI Endpoint Create /// /// Create a new SNI endpoint. /// /// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#sni-endpoint-create) pub struct SNICreate<'a> { /// unique app identifier, either app id or app name pub app_id: &'a str, /// The parameters to pass to the Heroku API pub params: SNICreateParams<'a>, } impl<'a> SNICreate<'a> { /// Create a new Heroku app SNI with parameters pub fn new(app_id: &'a str, certificate_chain: &'a str, private_key: &'a str) -> SNICreate<'a> { SNICreate { app_id, params: SNICreateParams { certificate_chain, private_key, }, } } } /// Create a new app sni with parameters. /// /// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#sni-endpoint-create-required-parameters) #[derive(Serialize, Clone, Debug)] pub struct SNICreateParams<'a> { /// raw contents of the public certificate chain (eg: .crt or .pem file) pub certificate_chain: &'a str, /// contents of the private key (eg .key file) pub private_key: &'a str, } impl<'a> HerokuEndpoint<SNI, (), SNICreateParams<'a>> for SNICreate<'a> { fn method(&self) -> Method { Method::Post } fn path(&self) -> String { format!("apps/{}/sni-endpoints", self.app_id) } fn body(&self) -> Option<SNICreateParams<'a>> { Some(self.params.clone()) } } /// SSL Endpoint Create /// /// Create a new SSL endpoint. /// /// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#ssl-endpoint-create) pub struct SSLCreate<'a> { /// unique app identifier, either app id or app name pub app_id: &'a str, /// The parameters to pass to the Heroku API pub params: SSLCreateParams<'a>, } impl<'a> SSLCreate<'a> { /// Update Heroku app SSL with parameters pub fn new( app_id: &'a str, certificate_chain: &'a str, private_key: &'a str, preprocess: Option<bool>, ) -> SSLCreate<'a> { SSLCreate { app_id, params: SSLCreateParams { certificate_chain, private_key, preprocess, }, } } /// Create a new Heroku app SSL with required parameters only pub fn create( app_id: &'a str, certificate_chain: &'a str, private_key: &'a str, ) -> SSLCreate<'a> { SSLCreate { app_id, params: SSLCreateParams { certificate_chain: certificate_chain, private_key: private_key, preprocess: None, }, } } } /// Create a new app ssl endpoint with parameters. /// /// [See Heroku documentation for more information about this endpoint](hhttps://devcenter.heroku.com/articles/platform-api-reference#ssl-endpoint-create-required-parameters) #[serde_with::skip_serializing_none] #[derive(Serialize, Clone, Debug)] pub struct SSLCreateParams<'a> { /// raw contents of the public certificate chain (eg: .crt or .pem file) pub certificate_chain: &'a str, /// contents of the private key (eg .key file) pub private_key: &'a str, /// allow Heroku to modify an uploaded public certificate chain if deemed advantageous by adding missing intermediaries, stripping unnecessary ones, etc. /// default: true pub preprocess: Option<bool>, } impl<'a> HerokuEndpoint<SSL, (), SSLCreateParams<'a>> for SSLCreate<'a> { fn method(&self) -> Method { Method::Post } fn path(&self) -> String { format!("apps/{}/ssl-endpoints", self.app_id) } fn body(&self) -> Option<SSLCreateParams<'a>> { Some(self.params.clone()) } }