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
use super::{
ModelSecurityCustomRulesClient, ModelSecurityGroupsClient, ModelSecurityModelsClient,
ModelSecurityRulesClient, ModelSecurityScansClient, models::PyPIAuthResponse, oauth,
};
use crate::{Client, Endpoint, RawRequest, RequestOptions, Result};
/// All planes share one OAuth provider, session, limiter, transport and destination policy.
#[derive(Clone, Debug)]
pub struct ModelSecurityClient {
data: Client,
management: Client,
}
impl ModelSecurityClient {
/// Scope one OAuth client to explicitly admitted data and management endpoints.
///
/// Enable `model-security`. Both endpoints must already be allowed by the
/// client's destination policy; transport, session and OAuth provider are shared.
///
/// ```no_run
/// use scm_sdk::{Client, Endpoint, Result,
/// airs::model_security::{ModelSecurityClient, ModelSecurityScanListOptions}};
/// async fn scan_page(oauth: Client, data: Endpoint, management: Endpoint) -> Result<()> {
/// let security = ModelSecurityClient::new(oauth, data, management)?;
/// let query = ModelSecurityScanListOptions::default();
/// let _page = security.scans().list(&query, None).await?;
/// Ok(())
/// }
/// ```
pub fn new(client: Client, data: Endpoint, management: Endpoint) -> Result<Self> {
let client = oauth(client)?;
Ok(Self {
data: client.with_endpoint(data)?,
management: client.with_endpoint(management)?,
})
}
/// Borrow the client scoped to model scan and inventory reads.
pub fn data_client(&self) -> &Client {
&self.data
}
/// Borrow the client scoped to rules and security group management.
pub fn management_client(&self) -> &Client {
&self.management
}
/// Access model scans and bounded result pagination.
pub fn scans(&self) -> ModelSecurityScansClient {
ModelSecurityScansClient {
client: self.data.clone(),
}
}
/// Access scanned models, versions and file inventory.
pub fn models(&self) -> ModelSecurityModelsClient {
ModelSecurityModelsClient {
client: self.data.clone(),
}
}
/// Access security groups and their rule instances.
pub fn security_groups(&self) -> ModelSecurityGroupsClient {
ModelSecurityGroupsClient {
client: self.management.clone(),
}
}
/// Access security rule definitions and versions.
pub fn security_rules(&self) -> ModelSecurityRulesClient {
ModelSecurityRulesClient {
client: self.management.clone(),
}
}
/// Access custom rules and their version lifecycle.
pub fn custom_rules(&self) -> ModelSecurityCustomRulesClient {
ModelSecurityCustomRulesClient {
client: self.management.clone(),
}
}
/// Return explicit PyPI credentials without following the credential-bearing URL.
pub async fn get_pypi_auth(
&self,
options: Option<&RequestOptions>,
) -> Result<PyPIAuthResponse> {
self.management
.send_contract(
RawRequest::read("/v1/pypi/authenticate")
.named("airs.model_security.get_pypi_auth"),
"PyPIAuthResponseSchema",
options,
)
.await
}
}