alien-aws-clients 3.3.2

Deploy software into your customers' cloud accounts and keep it fully managed
Documentation
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
use crate::aws::aws_request_utils::{AwsRequestBuilderExt, AwsSignConfig};
use crate::aws::credential_provider::AwsCredentialProvider;
use alien_client_core::{ErrorData, Result};
use alien_error::{Context, ContextError, IntoAlienError};
use bon::Builder;
#[cfg(feature = "test-utils")]
use mockall::automock;
use reqwest::{Client, StatusCode};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};

#[cfg_attr(feature = "test-utils", automock)]
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
pub trait CodeBuildApi: Send + Sync + std::fmt::Debug {
    async fn create_project(&self, request: CreateProjectRequest) -> Result<CreateProjectResponse>;
    async fn delete_project(&self, request: DeleteProjectRequest) -> Result<DeleteProjectResponse>;
    async fn update_project(&self, request: UpdateProjectRequest) -> Result<UpdateProjectResponse>;
    async fn batch_get_projects(
        &self,
        request: BatchGetProjectsRequest,
    ) -> Result<BatchGetProjectsResponse>;
    async fn start_build(&self, request: StartBuildRequest) -> Result<StartBuildResponse>;
    async fn stop_build(&self, request: StopBuildRequest) -> Result<StopBuildResponse>;
    async fn batch_get_builds(
        &self,
        request: BatchGetBuildsRequest,
    ) -> Result<BatchGetBuildsResponse>;
    async fn batch_delete_builds(
        &self,
        request: BatchDeleteBuildsRequest,
    ) -> Result<BatchDeleteBuildsResponse>;
    async fn retry_build(&self, request: RetryBuildRequest) -> Result<RetryBuildResponse>;
}

// ---------------------------------------------------------------------------
// CodeBuild client
// ---------------------------------------------------------------------------
#[derive(Debug, Clone)]
pub struct CodeBuildClient {
    client: Client,
    credentials: AwsCredentialProvider,
}

impl CodeBuildClient {
    pub fn new(client: Client, credentials: AwsCredentialProvider) -> Self {
        Self {
            client,
            credentials,
        }
    }

    /// Get the region for this CodeBuild client
    pub fn region(&self) -> &str {
        self.credentials.region()
    }

    fn sign_config(&self) -> AwsSignConfig {
        AwsSignConfig {
            service_name: "codebuild".into(),
            region: self.credentials.region().to_string(),
            credentials: self.credentials.get_credentials(),
            signing_region: None,
        }
    }

    fn get_base_url(&self) -> String {
        if let Some(override_url) = self.credentials.get_service_endpoint_option("codebuild") {
            override_url.to_string()
        } else {
            format!(
                "https://codebuild.{}.amazonaws.com",
                self.credentials.region()
            )
        }
    }

    // ------------------------- internal helpers -------------------------

    async fn post_json<T: DeserializeOwned + Send + 'static>(
        &self,
        action: &str,
        body: String,
        resource: &str,
    ) -> Result<T> {
        self.credentials.ensure_fresh().await?;
        let base_url = self.get_base_url();
        let url = format!("{}/", base_url.trim_end_matches('/'));

        let builder = self
            .client
            .post(&url)
            .host(&format!(
                "codebuild.{}.amazonaws.com",
                self.credentials.region()
            ))
            .header("X-Amz-Target", format!("CodeBuild_20161006.{}", action))
            .header("Content-Type", "application/x-amz-json-1.1")
            .body(body.clone());

        let result =
            crate::aws::aws_request_utils::sign_send_json(builder, &self.sign_config()).await;

        Self::map_result(result, action, resource, Some(&body))
    }

    async fn post_empty_response(&self, action: &str, body: String, resource: &str) -> Result<()> {
        self.credentials.ensure_fresh().await?;
        let base_url = self.get_base_url();
        let url = format!("{}/", base_url.trim_end_matches('/'));

        let builder = self
            .client
            .post(&url)
            .host(&format!(
                "codebuild.{}.amazonaws.com",
                self.credentials.region()
            ))
            .header("X-Amz-Target", format!("CodeBuild_20161006.{}", action))
            .header("Content-Type", "application/x-amz-json-1.1")
            .body(body.clone());

        let result =
            crate::aws::aws_request_utils::sign_send_no_response(builder, &self.sign_config())
                .await;

        Self::map_result(result, action, resource, Some(&body))
    }

    fn map_result<T>(
        result: Result<T>,
        operation: &str,
        resource: &str,
        request_body: Option<&str>,
    ) -> Result<T> {
        match result {
            Ok(v) => Ok(v),
            Err(e) => {
                if let Some(ErrorData::HttpResponseError {
                    http_status,
                    http_response_text: Some(ref text),
                    ..
                }) = &e.error
                {
                    let status = StatusCode::from_u16(*http_status)
                        .unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
                    if let Some(mapped) =
                        Self::map_codebuild_error(status, text, operation, resource, request_body)
                    {
                        Err(e.context(mapped))
                    } else {
                        // Couldn't parse CodeBuild error, use original error
                        Err(e)
                    }
                } else {
                    Err(e)
                }
            }
        }
    }

    fn map_codebuild_error(
        status: StatusCode,
        body: &str,
        _operation: &str,
        resource: &str,
        request_body: Option<&str>,
    ) -> Option<ErrorData> {
        let parsed: std::result::Result<CodeBuildErrorResponse, _> = serde_json::from_str(body);
        let (code, message) = match parsed {
            Ok(e) => {
                let c = e.type_field.unwrap_or_else(|| "UnknownErrorCode".into());
                let m = e.message.unwrap_or_else(|| "Unknown error".into());
                (c, m)
            }
            Err(_) => {
                // If we can't parse the response, return None to use original error
                return None;
            }
        };

        Some(match code.as_str() {
            "AccessDeniedException" => ErrorData::RemoteAccessDenied {
                resource_type: "Project".into(),
                resource_name: resource.into(),
            },
            "AccountLimitExceededException" => ErrorData::QuotaExceeded { message },
            "ThrottlingException" | "TooManyRequestsException" => {
                ErrorData::RateLimitExceeded { message }
            }
            "ServiceUnavailable" | "InternalFailure" | "ServiceException" => {
                ErrorData::RemoteServiceUnavailable { message }
            }
            "RequestTimeoutException" => ErrorData::Timeout { message },
            "ResourceNotFoundException" => ErrorData::RemoteResourceNotFound {
                resource_type: "Project".into(),
                resource_name: resource.into(),
            },
            "ResourceAlreadyExistsException" => ErrorData::RemoteResourceConflict {
                message,
                resource_type: "Project".into(),
                resource_name: resource.into(),
            },
            "InvalidInputException" | "NotAuthorized" | "ValidationError" => {
                // IAM eventual consistency: CodeBuild may return InvalidInputException
                // when it cannot yet assume a just-created service role. Treat these as
                // transient so the executor retries with backoff.
                if message.contains("sts:AssumeRole") || message.contains("not authorized") {
                    ErrorData::RemoteServiceUnavailable { message }
                } else {
                    ErrorData::InvalidInput {
                        message,
                        field_name: None,
                    }
                }
            }
            _ => match status {
                StatusCode::NOT_FOUND => ErrorData::RemoteResourceNotFound {
                    resource_type: "Project".into(),
                    resource_name: resource.into(),
                },
                StatusCode::CONFLICT => ErrorData::RemoteResourceConflict {
                    message,
                    resource_type: "Project".into(),
                    resource_name: resource.into(),
                },
                StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED => ErrorData::RemoteAccessDenied {
                    resource_type: "Project".into(),
                    resource_name: resource.into(),
                },
                StatusCode::TOO_MANY_REQUESTS => ErrorData::RateLimitExceeded { message },
                StatusCode::SERVICE_UNAVAILABLE
                | StatusCode::BAD_GATEWAY
                | StatusCode::GATEWAY_TIMEOUT => ErrorData::RemoteServiceUnavailable { message },
                _ => ErrorData::HttpResponseError {
                    message: format!("CodeBuild operation failed: {}", message),
                    url: format!("codebuild.amazonaws.com"),
                    http_status: status.as_u16(),
                    http_response_text: Some(body.into()),
                    http_request_text: request_body.map(|s| s.to_string()),
                },
            },
        })
    }
}

#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
impl CodeBuildApi for CodeBuildClient {
    async fn create_project(&self, request: CreateProjectRequest) -> Result<CreateProjectResponse> {
        let body = serde_json::to_string(&request).into_alien_error().context(
            ErrorData::SerializationError {
                message: format!(
                    "Failed to serialize CreateProjectRequest for project '{}'",
                    request.name
                ),
            },
        )?;
        self.post_json("CreateProject", body, &request.name).await
    }

    async fn delete_project(&self, request: DeleteProjectRequest) -> Result<DeleteProjectResponse> {
        let body = serde_json::to_string(&request).into_alien_error().context(
            ErrorData::SerializationError {
                message: format!(
                    "Failed to serialize DeleteProjectRequest for project '{}'",
                    request.name
                ),
            },
        )?;
        self.post_empty_response("DeleteProject", body, &request.name)
            .await?;
        Ok(DeleteProjectResponse {})
    }

    async fn update_project(&self, request: UpdateProjectRequest) -> Result<UpdateProjectResponse> {
        let body = serde_json::to_string(&request).into_alien_error().context(
            ErrorData::SerializationError {
                message: format!(
                    "Failed to serialize UpdateProjectRequest for project '{}'",
                    request.name
                ),
            },
        )?;
        self.post_json("UpdateProject", body, &request.name).await
    }

    async fn batch_get_projects(
        &self,
        request: BatchGetProjectsRequest,
    ) -> Result<BatchGetProjectsResponse> {
        let body = serde_json::to_string(&request).into_alien_error().context(
            ErrorData::SerializationError {
                message: format!("Failed to serialize BatchGetProjectsRequest"),
            },
        )?;
        self.post_json("BatchGetProjects", body, "").await
    }

    async fn start_build(&self, request: StartBuildRequest) -> Result<StartBuildResponse> {
        let body = serde_json::to_string(&request).into_alien_error().context(
            ErrorData::SerializationError {
                message: format!(
                    "Failed to serialize StartBuildRequest for project '{}'",
                    request.project_name
                ),
            },
        )?;
        self.post_json("StartBuild", body, &request.project_name)
            .await
    }

    async fn stop_build(&self, request: StopBuildRequest) -> Result<StopBuildResponse> {
        let body = serde_json::to_string(&request).into_alien_error().context(
            ErrorData::SerializationError {
                message: format!(
                    "Failed to serialize StopBuildRequest for build '{}'",
                    request.id
                ),
            },
        )?;
        self.post_json("StopBuild", body, &request.id).await
    }

    async fn batch_get_builds(
        &self,
        request: BatchGetBuildsRequest,
    ) -> Result<BatchGetBuildsResponse> {
        let body = serde_json::to_string(&request).into_alien_error().context(
            ErrorData::SerializationError {
                message: format!("Failed to serialize BatchGetBuildsRequest"),
            },
        )?;
        self.post_json("BatchGetBuilds", body, "").await
    }

    async fn batch_delete_builds(
        &self,
        request: BatchDeleteBuildsRequest,
    ) -> Result<BatchDeleteBuildsResponse> {
        let body = serde_json::to_string(&request).into_alien_error().context(
            ErrorData::SerializationError {
                message: format!("Failed to serialize BatchDeleteBuildsRequest"),
            },
        )?;
        self.post_json("BatchDeleteBuilds", body, "").await
    }

    async fn retry_build(&self, request: RetryBuildRequest) -> Result<RetryBuildResponse> {
        let body = serde_json::to_string(&request).into_alien_error().context(
            ErrorData::SerializationError {
                message: format!("Failed to serialize RetryBuildRequest"),
            },
        )?;
        self.post_json("RetryBuild", body, &request.id.unwrap_or_default())
            .await
    }
}

// ---------------------------------------------------------------------------
// Request / response payloads
// ---------------------------------------------------------------------------

#[derive(Debug, Deserialize)]
struct CodeBuildErrorResponse {
    #[serde(rename = "__type")]
    type_field: Option<String>,
    #[serde(rename = "message")]
    message: Option<String>,
}

#[derive(Debug, Clone, Serialize, Builder)]
#[serde(rename_all = "camelCase")]
pub struct CreateProjectRequest {
    pub name: String,
    pub source: ProjectSource,
    pub artifacts: ProjectArtifacts,
    pub environment: ProjectEnvironment,
    pub service_role: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub logs_config: Option<LogsConfig>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<Vec<Tag>>,
}

#[derive(Debug, Clone, Serialize, Builder, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProjectSource {
    pub r#type: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub location: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub buildspec: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub git_clone_depth: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub insecure_ssl: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Builder, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProjectArtifacts {
    pub r#type: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub location: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub path: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub namespace_type: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub packaging: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub encryption_disabled: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub artifact_identifier: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bucket_owner_access: Option<String>,
}

#[derive(Debug, Clone, Serialize, Builder, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProjectEnvironment {
    pub r#type: String,
    pub image: String,
    pub compute_type: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub environment_variables: Option<Vec<EnvironmentVariable>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub privileged_mode: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub image_pull_credentials_type: Option<String>,
}

#[derive(Debug, Clone, Serialize, Builder, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EnvironmentVariable {
    pub name: String,
    pub value: String,
    pub r#type: Option<String>,
}

#[derive(Debug, Clone, Serialize, Builder, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Tag {
    pub key: String,
    pub value: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateProjectResponse {
    pub project: Project,
}

#[derive(Debug, Deserialize, Clone, bon::Builder)]
#[serde(rename_all = "camelCase")]
pub struct Project {
    pub name: Option<String>,
    pub arn: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source: Option<ProjectSource>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub artifacts: Option<ProjectArtifacts>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub environment: Option<ProjectEnvironment>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub service_role: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<Vec<Tag>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vpc_config: Option<VpcConfig>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub webhook: Option<Webhook>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub logs_config: Option<LogsConfig>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cache: Option<ProjectCache>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub timeout_in_minutes: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub queued_timeout_in_minutes: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub encryption_key: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub secondary_sources: Option<Vec<ProjectSource>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub secondary_artifacts: Option<Vec<ProjectArtifacts>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_modified: Option<f64>,
}

#[derive(Debug, Clone, Serialize, Builder)]
#[serde(rename_all = "camelCase")]
pub struct DeleteProjectRequest {
    pub name: String,
}

#[derive(Debug, Deserialize)]
pub struct DeleteProjectResponse {}

#[derive(Debug, Clone, Serialize, Builder)]
#[serde(rename_all = "camelCase")]
pub struct UpdateProjectRequest {
    pub name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source: Option<ProjectSource>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub artifacts: Option<ProjectArtifacts>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub environment: Option<ProjectEnvironment>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub service_role: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<Vec<Tag>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vpc_config: Option<VpcConfig>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub webhook: Option<Webhook>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub logs_config: Option<LogsConfig>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cache: Option<ProjectCache>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub timeout_in_minutes: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub queued_timeout_in_minutes: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub encryption_key: Option<String>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateProjectResponse {
    pub project: Project,
}

#[derive(Debug, Clone, Serialize, Builder)]
#[serde(rename_all = "camelCase")]
pub struct StartBuildRequest {
    pub project_name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source_version: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub buildspec_override: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub environment_variables_override: Option<Vec<EnvironmentVariable>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub compute_type_override: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub environment_type_override: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub image_override: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub timeout_in_minutes_override: Option<i32>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StartBuildResponse {
    pub build: Build,
}

#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Build {
    pub id: Option<String>,
    pub arn: Option<String>,
    pub build_number: Option<i64>,
    pub build_status: Option<String>,
    pub start_time: Option<f64>,
    pub end_time: Option<f64>,
    pub current_phase: Option<String>,
    pub build_complete: bool,
    pub initiator: Option<String>,
    pub source_version: Option<String>,
    pub project_name: Option<String>,
    pub phases: Option<Vec<BuildPhase>>,
    pub source: Option<ProjectSource>,
    pub secondary_sources: Option<Vec<ProjectSource>>,
    pub secondary_artifacts: Option<Vec<BuildArtifacts>>,
    pub artifacts: Option<BuildArtifacts>,
    pub logs: Option<LogsLocation>,
    pub vpc_config: Option<VpcConfig>,
    pub environment: Option<ProjectEnvironment>,
}

#[derive(Debug, Clone, Serialize, Builder)]
#[serde(rename_all = "camelCase")]
pub struct StopBuildRequest {
    pub id: String,
}

#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct StopBuildResponse {
    pub build: Build,
}

#[derive(Debug, Clone, Serialize, Builder)]
#[serde(rename_all = "camelCase")]
pub struct BatchGetBuildsRequest {
    pub ids: Vec<String>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BatchGetBuildsResponse {
    pub builds: Option<Vec<Build>>,
    pub builds_not_found: Option<Vec<String>>,
}

#[derive(Debug, Clone, Serialize, Builder)]
#[serde(rename_all = "camelCase")]
pub struct BatchDeleteBuildsRequest {
    pub ids: Vec<String>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BatchDeleteBuildsResponse {
    pub builds_deleted: Option<Vec<String>>,
    pub builds_not_deleted: Option<Vec<BuildNotDeleted>>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BuildNotDeleted {
    pub id: Option<String>,
    pub status_code: Option<String>,
}

#[derive(Debug, Clone, Serialize, Builder)]
#[serde(rename_all = "camelCase")]
pub struct RetryBuildRequest {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub idempotency_token: Option<String>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RetryBuildResponse {
    pub build: Build,
}

#[derive(Debug, Clone, Serialize, Builder, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VpcConfig {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vpc_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subnets: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub security_group_ids: Option<Vec<String>>,
}

#[derive(Debug, Clone, Serialize, Builder, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Webhook {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub payload_url: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub secret: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub branch_filter: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filter_groups: Option<Vec<Vec<WebhookFilter>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub build_type: Option<String>,
}

#[derive(Debug, Clone, Serialize, Builder, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WebhookFilter {
    pub r#type: String,
    pub pattern: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub exclude_matched_pattern: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Builder, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LogsConfig {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cloud_watch_logs: Option<CloudWatchLogsConfig>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub s3_logs: Option<S3LogsConfig>,
}

#[derive(Debug, Clone, Serialize, Builder, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CloudWatchLogsConfig {
    pub status: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub group_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stream_name: Option<String>,
}

#[derive(Debug, Clone, Serialize, Builder, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct S3LogsConfig {
    pub status: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub location: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub encryption_disabled: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bucket_owner_access: Option<String>,
}

#[derive(Debug, Clone, Serialize, Builder, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProjectCache {
    pub r#type: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub location: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub modes: Option<Vec<String>>,
}

#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BuildPhase {
    pub phase_type: Option<String>,
    pub phase_status: Option<String>,
    pub start_time: Option<f64>,
    pub end_time: Option<f64>,
    pub duration_in_seconds: Option<i64>,
}

#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BuildArtifacts {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub location: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sha256sum: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub md5sum: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub override_artifact_name: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub encryption_disabled: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub artifact_identifier: Option<String>,
}

#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LogsLocation {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub group_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stream_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub deep_link: Option<String>,
}

#[derive(Debug, Clone, Serialize, Builder)]
#[serde(rename_all = "camelCase")]
pub struct BatchGetProjectsRequest {
    pub names: Vec<String>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BatchGetProjectsResponse {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub projects: Option<Vec<Project>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub projects_not_found: Option<Vec<String>>,
}