fastly_api/apis/
iam_roles_api.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14/// struct for passing parameters to the method [`iam_v1_roles_get`]
15#[derive(Clone, Debug, Default)]
16pub struct IamV1RolesGetParams {
17    /// Alphanumeric string identifying the role.
18    pub role_id: String,
19    /// Include related data (i.e., permissions).
20    pub include: Option<String>
21}
22
23/// struct for passing parameters to the method [`iam_v1_roles_list`]
24#[derive(Clone, Debug, Default)]
25pub struct IamV1RolesListParams {
26    /// Number of results per page. The maximum is 1000.
27    pub limit: Option<i32>,
28    /// Cursor value from the `next_cursor` field of a previous response, used to retrieve the next page. To request the first page, this should be empty.
29    pub cursor: Option<String>
30}
31
32
33/// struct for typed errors of method [`iam_v1_roles_get`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum IamV1RolesGetError {
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`iam_v1_roles_list`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum IamV1RolesListError {
44    UnknownValue(serde_json::Value),
45}
46
47
48/// Retrieve a single IAM role by its unique identifier. 
49pub async fn iam_v1_roles_get(configuration: &mut configuration::Configuration, params: IamV1RolesGetParams) -> Result<crate::models::IamV1RoleResponse, Error<IamV1RolesGetError>> {
50    let local_var_configuration = configuration;
51
52    // unbox the parameters
53    let role_id = params.role_id;
54    let include = params.include;
55
56
57    let local_var_client = &local_var_configuration.client;
58
59    let local_var_uri_str = format!("{}/iam/v1/roles/{role_id}", local_var_configuration.base_path, role_id=crate::apis::urlencode(role_id));
60    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
61
62    if let Some(ref local_var_str) = include {
63        local_var_req_builder = local_var_req_builder.query(&[("include", &local_var_str.to_string())]);
64    }
65    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
66        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
67    }
68    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
69        let local_var_key = local_var_apikey.key.clone();
70        let local_var_value = match local_var_apikey.prefix {
71            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
72            None => local_var_key,
73        };
74        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
75    };
76
77    let local_var_req = local_var_req_builder.build()?;
78    let local_var_resp = local_var_client.execute(local_var_req).await?;
79
80    if "GET" != "GET" && "GET" != "HEAD" {
81      let headers = local_var_resp.headers();
82      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
83          Some(v) => v.to_str().unwrap().parse().unwrap(),
84          None => configuration::DEFAULT_RATELIMIT,
85      };
86      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
87          Some(v) => v.to_str().unwrap().parse().unwrap(),
88          None => 0,
89      };
90    }
91
92    let local_var_status = local_var_resp.status();
93    let local_var_content = local_var_resp.text().await?;
94
95    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
96        serde_json::from_str(&local_var_content).map_err(Error::from)
97    } else {
98        let local_var_entity: Option<IamV1RolesGetError> = serde_json::from_str(&local_var_content).ok();
99        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
100        Err(Error::ResponseError(local_var_error))
101    }
102}
103
104/// Retrieve a paginated list of IAM roles available in the account. 
105pub async fn iam_v1_roles_list(configuration: &mut configuration::Configuration, params: IamV1RolesListParams) -> Result<crate::models::IamV1RoleListResponse, Error<IamV1RolesListError>> {
106    let local_var_configuration = configuration;
107
108    // unbox the parameters
109    let limit = params.limit;
110    let cursor = params.cursor;
111
112
113    let local_var_client = &local_var_configuration.client;
114
115    let local_var_uri_str = format!("{}/iam/v1/roles", local_var_configuration.base_path);
116    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
117
118    if let Some(ref local_var_str) = limit {
119        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
120    }
121    if let Some(ref local_var_str) = cursor {
122        local_var_req_builder = local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
123    }
124    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
125        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
126    }
127    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
128        let local_var_key = local_var_apikey.key.clone();
129        let local_var_value = match local_var_apikey.prefix {
130            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
131            None => local_var_key,
132        };
133        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
134    };
135
136    let local_var_req = local_var_req_builder.build()?;
137    let local_var_resp = local_var_client.execute(local_var_req).await?;
138
139    if "GET" != "GET" && "GET" != "HEAD" {
140      let headers = local_var_resp.headers();
141      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
142          Some(v) => v.to_str().unwrap().parse().unwrap(),
143          None => configuration::DEFAULT_RATELIMIT,
144      };
145      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
146          Some(v) => v.to_str().unwrap().parse().unwrap(),
147          None => 0,
148      };
149    }
150
151    let local_var_status = local_var_resp.status();
152    let local_var_content = local_var_resp.text().await?;
153
154    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
155        serde_json::from_str(&local_var_content).map_err(Error::from)
156    } else {
157        let local_var_entity: Option<IamV1RolesListError> = serde_json::from_str(&local_var_content).ok();
158        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
159        Err(Error::ResponseError(local_var_error))
160    }
161}
162