veracode-platform 0.1.1

A comprehensive Rust client library for the Veracode platform (Applications, Identity, Pipeline Scan, Sandbox)
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
# Veracode Platform Client Library

[![Rust](https://img.shields.io/badge/rust-1.70%2B-brightgreen.svg)](https://www.rust-lang.org)
[![Crates.io](https://img.shields.io/crates/v/veracode-platform.svg)](https://crates.io/crates/veracode-platform)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](#license)
[![Documentation](https://docs.rs/veracode-platform/badge.svg)](https://docs.rs/veracode-platform)

A comprehensive Rust client library for the Veracode security platform, providing type-safe and ergonomic access to Applications, Identity, Pipeline Scan, Sandbox, Policy, and Build APIs.

## โœจ Features

- ๐Ÿ” **HMAC Authentication** - Built-in Veracode API credential support with automatic signature generation
- ๐Ÿ›ก๏ธ **Secure Credential Handling** - All API credentials are securely wrapped to prevent accidental exposure in logs
- ๐ŸŒ **Multi-Regional Support** - Automatic endpoint routing for Commercial, European, and Federal regions
- ๐Ÿ”„ **Smart API Routing** - Automatically uses REST or XML APIs based on operation requirements
- ๐Ÿ“ฑ **Applications API** - Complete application lifecycle management via REST API
- ๐Ÿ‘ฅ **Identity API** - User and team management via REST API
- ๐Ÿ” **Pipeline Scan API** - CI/CD security scanning via REST API
- ๐Ÿงช **Sandbox API** - Development sandbox management via REST API
- ๐Ÿ”จ **Build API** - Build management and SAST operations via XML API
- ๐Ÿ“Š **Scan API** - File upload and scan operations via XML API
- ๐Ÿ“‹ **Policy API** - Security policy management and compliance evaluation via REST API
- ๐Ÿš€ **Async/Await** - Built on tokio for high-performance concurrent operations
- โšก **Type-Safe** - Full Rust type safety with comprehensive serde serialization
- ๐Ÿ“Š **Rich Data Types** - Comprehensive data structures for all API responses
- ๐Ÿ”ง **Workflow Helpers** - High-level operations combining multiple API calls
- ๐Ÿ”’ **Debug Safety** - All sensitive credentials show `[REDACTED]` in debug output
- ๐Ÿงช **Comprehensive Testing** - Extensive test coverage including security measures

## ๐Ÿš€ Quick Start

Add to your `Cargo.toml`:

```toml
[dependencies]
veracode-platform = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
```

### Basic Usage

```rust
use veracode_platform::{VeracodeConfig, VeracodeClient, VeracodeRegion};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Configure client for your region
    let config = VeracodeConfig::new(
        std::env::var("VERACODE_API_ID")?,
        std::env::var("VERACODE_API_KEY")?,
    ).with_region(VeracodeRegion::Commercial); // Commercial (default), European, or Federal
    
    // Create client
    let client = VeracodeClient::new(config)?;
    
    // Use Applications API (REST)
    let apps = client.get_all_applications().await?;
    println!("Found {} applications", apps.len());
    
    // Use Pipeline Scan API (REST)
    let pipeline = client.pipeline_api();
    // ... pipeline operations
    
    // Use Scan API for file uploads (XML)
    let scan_api = client.scan_api();
    // ... scan operations
    
    Ok(())
}
```

## ๐ŸŒ Regional Support

The library automatically handles regional endpoints for both REST and XML APIs:

```rust
use veracode_platform::{VeracodeConfig, VeracodeRegion};

// Commercial region (default)
let config = VeracodeConfig::new("api_id".to_string(), "api_key".to_string())
    .with_region(VeracodeRegion::Commercial);
// REST: api.veracode.com | XML: analysiscenter.veracode.com

// European region
let config = VeracodeConfig::new("api_id".to_string(), "api_key".to_string())
    .with_region(VeracodeRegion::European);
// REST: api.veracode.eu | XML: analysiscenter.veracode.eu

// US Federal region
let config = VeracodeConfig::new("api_id".to_string(), "api_key".to_string())
    .with_region(VeracodeRegion::Federal);
// REST: api.veracode.us | XML: analysiscenter.veracode.us
```

## ๐Ÿ“š API Modules

### Applications API (REST)
Complete application lifecycle management:

```rust
// List all applications
let apps = client.get_all_applications().await?;

// Get specific application
let app_query = ApplicationQuery {
    name: Some("MyApp".to_string()),
    ..Default::default()
};
let app = client.get_application(app_query).await?;

// Create new application
let create_request = CreateApplicationRequest {
    name: "New App".to_string(),
    description: Some("My new application".to_string()),
    business_unit_id: Some(12345),
    teams: vec![],
    tags: vec![],
};
let new_app = client.create_application(create_request).await?;
```

### Pipeline Scan API (REST)
CI/CD security scanning:

```rust
use veracode_platform::pipeline::{CreateScanRequest, DevStage};

let pipeline = client.pipeline_api();

// Create a pipeline scan
let scan_request = CreateScanRequest {
    binary_name: "my-app.jar".to_string(),
    binary_size: file_data.len() as u64,
    binary_hash: calculate_sha256(&file_data),
    project_name: "My Project".to_string(),
    project_uri: Some("https://github.com/user/repo".to_string()),
    dev_stage: DevStage::Development,
    app_id: None,
    project_ref: Some("main".to_string()),
    scan_timeout: Some(30),
    plugin_version: None,
    emit_stack_dump: None,
    include_modules: None,
};

let scan_result = pipeline.create_scan(scan_request).await?;
println!("Created scan: {}", scan_result.scan_id);

// Monitor scan status
let scan_info = pipeline.get_scan(&scan_result.scan_id).await?;
println!("Scan status: {:?}", scan_info.status);

// Get findings when complete
if scan_info.status == ScanStatus::Complete {
    let findings = pipeline.get_findings(&scan_result.scan_id).await?;
    println!("Found {} security issues", findings.len());
}
```

### Identity API (REST)
User and team management:

```rust
let identity = client.identity_api();

// List users
let users = identity.get_users(None).await?;

// Create new user
let create_user = CreateUserRequest {
    email: "user@example.com".to_string(),
    first_name: "John".to_string(),
    last_name: "Doe".to_string(),
    user_type: UserType::User,
    roles: vec![],
    teams: vec![],
};
let new_user = identity.create_user(create_user).await?;

// Manage teams
let teams = identity.get_teams().await?;
```

### Sandbox API (REST)
Development sandbox management:

```rust
let sandbox_api = client.sandbox_api();

// List sandboxes for an application
let sandboxes = sandbox_api.get_sandboxes("app-guid").await?;

// Create new sandbox
let create_request = CreateSandboxRequest {
    name: "Development Sandbox".to_string(),
    auto_recreate: Some(false),
    custom_fields: vec![],
};
let sandbox = sandbox_api.create_sandbox("app-guid", create_request).await?;
```

### Scan API (XML)
File upload and scan operations:

```rust
let scan_api = client.scan_api();

// Upload file for scanning
let upload_request = UploadFileRequest {
    app_id: "12345".to_string(),
    file_path: "/path/to/file.jar".to_string(),
    sandbox_id: Some("sandbox-guid".to_string()),
};

let uploaded_file = scan_api.upload_file(upload_request).await?;
println!("Uploaded: {}", uploaded_file.file_name);

// Start pre-scan
let pre_scan = scan_api.begin_pre_scan(BeginPreScanRequest {
    app_id: "12345".to_string(),
    sandbox_id: Some("sandbox-guid".to_string()),
    scan_all_nonfatal_top_level_modules: Some(true),
    auto_scan: Some(true),
});
```

### Policy API (REST)
Security policy and compliance management:

```rust
let policy_api = client.policy_api();

// Get organizational policies
let policies = policy_api.get_policies().await?;

// Evaluate policy compliance
let compliance = policy_api.evaluate_policy_compliance(
    &app_guid, 
    &policy_guid, 
    None
).await?;
println!("Compliance status: {:?}", compliance.status);
println!("Score: {}/100", compliance.score.unwrap_or(0));

// Initiate policy-based scan
let scan_request = PolicyScanRequest {
    application_guid: app_guid.to_string(),
    policy_guid: policy_guid.to_string(),
    scan_type: ScanType::Static,
    sandbox_guid: None,
    config: None,
};
let scan_result = policy_api.initiate_policy_scan(scan_request).await?;
```

### Build API (XML)
Build management and SAST operations:

```rust
let build_api = client.build_api();

// Get build list for application
let builds = build_api.get_build_list(GetBuildListRequest {
    app_id: "12345".to_string(),
    sandbox_id: None,
}).await?;

// Create new build
let create_build = CreateBuildRequest {
    app_id: "12345".to_string(),
    version: "1.0.0".to_string(),
    sandbox_id: None,
    lifecycle_stage: None,
    launch_date: None,
};
let build = build_api.create_build(create_build).await?;
```

### Workflow Helpers
High-level operations combining multiple API calls:

```rust
let workflow = client.workflow();

// Complete application workflow
let workflow_config = WorkflowConfig {
    app_name: "My Application".to_string(),
    build_version: "1.0.0".to_string(),
    file_paths: vec!["/path/to/app.jar".to_string()],
    scan_timeout: Some(45),
    delete_incomplete_scans: true,
};

let result = workflow.run_complete_workflow(workflow_config).await?;
println!("Workflow completed: {:?}", result);
```

## ๐Ÿ” Authentication

### Environment Variables
Set your Veracode API credentials:

```bash
export VERACODE_API_ID="your-api-id"
export VERACODE_API_KEY="your-api-key"
```

### Direct Configuration
Or pass credentials directly:

```rust
let config = VeracodeConfig::new(
    "your-api-id".to_string(),
    "your-api-key".to_string()
);
```

### Development Mode
Disable certificate validation for development environments:

```bash
export VERASCAN_DISABLE_CERT_VALIDATION="true"
```

Or in code:
```rust
let config = VeracodeConfig::new("api_id".to_string(), "api_key".to_string())
    .with_certificate_validation_disabled(); // Only for development!
```

## ๐ŸŽ›๏ธ Feature Flags

Enable only the APIs you need to reduce compile time and binary size:

```toml
[dependencies]
veracode-platform = { version = "0.1.0", features = ["pipeline", "applications"] }
```

Available features:
- `applications` - Applications API support
- `identity` - Identity API support
- `pipeline` - Pipeline Scan API support
- `sandbox` - Sandbox API support
- `policy` - Policy API support
- `default` - All APIs enabled

## ๐Ÿงช Examples

The library includes comprehensive examples for each API:

```bash
# Set up credentials first
export VERACODE_API_ID="your-api-id"
export VERACODE_API_KEY="your-api-key"

# Applications API example
cargo run --example application_lifecycle

# Identity API example
cargo run --example identity_lifecycle

# Pipeline Scan API example
cargo run --example pipeline_scan_lifecycle

# Sandbox API example
cargo run --example sandbox_lifecycle

# Policy API example
cargo run --example policy_lifecycle

# Basic usage example
cargo run --example basic_usage

# Build lifecycle example
cargo run --example build_lifecycle_example

# Large file upload example
cargo run --example large_file_upload_example

# XML API workflow validation
cargo run --example xml_api_workflow_validation
```

## ๐Ÿ—๏ธ Architecture

### API Type Routing
The library automatically routes operations to the correct API type:

- **REST API (`api.veracode.*`)**: Applications, Identity, Pipeline, Policy, Sandbox management
- **XML API (`analysiscenter.veracode.*`)**: Build management, Scan operations, Legacy workflows

### Smart Client Management
The client automatically creates specialized instances for different API types:

```rust
let client = VeracodeClient::new(config)?;

// REST API modules use the main client
let apps = client.get_all_applications().await?;  // Uses REST
let pipeline = client.pipeline_api();             // Uses REST
let identity = client.identity_api();             // Uses REST

// XML API modules use a specialized XML client internally
let scan_api = client.scan_api();                 // Uses XML
let build_api = client.build_api();               // Uses XML
```

### Regional Endpoint Management
All regional variants are supported with automatic endpoint resolution:

| Region | REST Endpoint | XML Endpoint |
|--------|---------------|--------------|
| Commercial | `api.veracode.com` | `analysiscenter.veracode.com` |
| European | `api.veracode.eu` | `analysiscenter.veracode.eu` |
| Federal | `api.veracode.us` | `analysiscenter.veracode.us` |

## ๐Ÿ” Security Features

### Secure Credential Handling

All API credentials are automatically secured to prevent accidental exposure:

```rust
use veracode_platform::{VeracodeConfig, VeracodeClient};

// Credentials are automatically wrapped in secure containers
let config = VeracodeConfig::new(
    std::env::var("VERACODE_API_ID")?,
    std::env::var("VERACODE_API_KEY")?,
);

// Debug output shows [REDACTED] instead of actual credentials
println!("{:?}", config);
// Output: VeracodeConfig { api_id: [REDACTED], api_key: [REDACTED], ... }
```

### Debug Safety

All sensitive information is automatically redacted in debug output:

- **API Credentials**: `VERACODE_API_ID` and `VERACODE_API_KEY` show as `[REDACTED]`
- **Configuration Structures**: `VeracodeConfig` safely displays structure without exposing credentials
- **Identity API**: `ApiCredential` structures redact sensitive `api_key` fields
- **Comprehensive Coverage**: All credential-containing structures are protected

### Backward Compatibility

Security improvements are transparent to existing code:

- All existing examples continue to work unchanged
- No breaking changes to public APIs
- Secure wrappers are internal implementation details
- Access to credentials through standard methods (`as_str()`, `into_string()`)

## ๐Ÿ”ง Error Handling

The library provides comprehensive error types for robust error handling:

```rust
use veracode_platform::{VeracodeError, pipeline::PipelineError, sandbox::SandboxError};

// Pipeline API error handling
match pipeline.get_findings(&scan_id).await {
    Ok(findings) => println!("Found {} issues", findings.len()),
    Err(PipelineError::FindingsNotReady) => {
        println!("Scan still processing, try again later");
    },
    Err(PipelineError::ApiError(VeracodeError::Unauthorized)) => {
        println!("Check your API credentials");
    },
    Err(PipelineError::ApiError(VeracodeError::NotFound(msg))) => {
        println!("Scan not found: {}", msg);
    },
    Err(e) => println!("Error: {}", e),
}

// Sandbox API error handling
match sandbox_api.get_sandboxes("app-guid").await {
    Ok(sandboxes) => println!("Found {} sandboxes", sandboxes.len()),
    Err(SandboxError::InvalidApplicationGuid(guid)) => {
        println!("Invalid application GUID: {}", guid);
    },
    Err(SandboxError::ApiError(VeracodeError::Authentication(msg))) => {
        println!("Authentication failed: {}", msg);
    },
    Err(e) => println!("Error: {}", e),
}
```

### Common Error Types

| Error Type | Description |
|------------|-------------|
| `VeracodeError::Authentication` | Invalid API credentials or signature issues |
| `VeracodeError::NotFound` | Requested resource doesn't exist |
| `VeracodeError::InvalidResponse` | API returned unexpected response format |
| `VeracodeError::Http` | Network or HTTP-level errors |
| `VeracodeError::Serialization` | JSON parsing or serialization errors |

## ๐Ÿ“Š Data Types

### Core Types
```rust
// Application management
pub struct Application {
    pub guid: String,
    pub name: String,
    pub description: Option<String>,
    // ... more fields
}

// Pipeline scanning
pub struct Finding {
    pub issue_id: u32,
    pub issue_type: String,
    pub issue_type_id: String,
    pub cwe_id: String,
    pub severity: Severity,
    // ... more fields
}

// Identity management
pub struct User {
    pub user_id: String,
    pub email: String,
    pub first_name: String,
    pub last_name: String,
    pub user_type: UserType,
    // ... more fields
}
```

### Enums and Status Types
```rust
// Scan status tracking
#[derive(Debug, Clone, PartialEq)]
pub enum ScanStatus {
    Pending,
    Running,
    Complete,
    Failed,
    Cancelled,
}

// Security severity levels
#[derive(Debug, Clone, PartialEq)]
pub enum Severity {
    VeryHigh,
    High,
    Medium,
    Low,
    VeryLow,
    Informational,
}

// Development stages
#[derive(Debug, Clone, PartialEq)]
pub enum DevStage {
    Development,
    Testing,
    Release,
}
```

## ๐Ÿ”ฌ Testing

Run the test suite:

```bash
# Run all tests
cargo test

# Run tests with output
cargo test -- --nocapture

# Run specific test module
cargo test --test applications_api
```

Note: Integration tests require valid Veracode API credentials and may create/modify resources in your Veracode account.

## ๐Ÿ“– Documentation

Generate and view the documentation:

```bash
# Build and open documentation
cargo doc --open

# Build documentation for all features
cargo doc --all-features --open
```

## ๐Ÿท๏ธ Versioning

This library follows [Semantic Versioning](https://semver.org/):

- **Major version** changes indicate breaking API changes
- **Minor version** changes add functionality in a backward-compatible manner
- **Patch version** changes include backward-compatible bug fixes

## ๐Ÿค Contributing

Contributions are welcome! Please read our contributing guidelines:

1. **Fork** the repository
2. **Create** a feature branch (`git checkout -b feature/amazing-feature`)
3. **Commit** your changes (`git commit -m 'Add amazing feature'`)
4. **Push** to the branch (`git push origin feature/amazing-feature`)
5. **Open** a Pull Request

### Development Setup

```bash
# Clone the repository
git clone <repository-url>
cd veracode-workspace/veracode-api

# Run tests
cargo test

# Check formatting
cargo fmt -- --check

# Run lints
cargo clippy -- -D warnings

# Build documentation
cargo doc --all-features
```

## ๐Ÿ“œ License

This project is licensed under the Apache License, Version 2.0 - see the [LICENSE](LICENSE) file for details.

```
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

## ๐Ÿ†˜ Support

- ๐Ÿ“š **Documentation**: [docs.rs/veracode-platform]https://docs.rs/veracode-platform
- ๐Ÿ› **Issues**: [GitHub Issues]https://github.com/yourusername/veracode-platform/issues
- ๐Ÿ’ฌ **Discussions**: [GitHub Discussions]https://github.com/yourusername/veracode-platform/discussions
- ๐Ÿ“ **Changelog**: [CHANGELOG.md]CHANGELOG.md

---

*Built with โค๏ธ in Rust for the security community*